Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- //Delay between Dynamic IP updates, in minutes...
- int UpDelay = 1;
- //DNS Server to update
- char DNS_Server[] = "dynamicdns.park-your-domain.com";
- //MAC address
- byte mac[] = { 0x90, 0xA1, 0xDB, 0x02, 0x05, 0x17 };
- //Public IP server
- char IPServer[] = "checkip.dyndns.com";
- //checkip.dyndns.org
- //Ignore these
- String IPA, OldIPA;
- EthernetClient client;
- void setup() {
- Serial.begin(19200);
- Serial.println("Started...");
- //Turn LED
- Configure:
- Serial.print("(please wait)\nEthernet ");
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Configuration failed. Retrying in 2 minutes.");
- delay(60*1000*2);
- goto Configure;
- }
- Serial.println("Configured...");
- //Turn LED 2 on
- delay(5000);
- }
- void loop() {
- Serial.println("Running Update");
- Serial.println("Attempting Connect.");
- if(client.connect(IPServer, 80)){
- Serial.println("Connected to IP Server\n\n");
- client.println("GET HTTP/1.0");
- client.println();
- //Wait for response
- delay(2000);
- String BufLine;
- while(client.available() > 0){
- BufLine += client.read();
- if(BufLine.endsWith("\n")){
- if(BufLine.indexOf("Current IP Address: ") > -1){
- IPA = BufLine.substring(76,BufLine.length()-16);
- Serial.println(IPA);
- client.stop();
- if(IPA != "0"){
- delay(2000);
- //UPDATE DNS HERE
- Serial.println("Time to.");
- EthernetClient client;
- delay(2000);
- if(client.connect(DNS_Server, 80)){
- Serial.println("Updating DNS");
- long time = (millis()/1000);
- String sendstring = "GET /update?host=www&domain=cluelessperson.com%20&password=2e7958b8d7304f978b7cc01ef18925c3&Timer=" + String(time) + " HTTP/1.0";
- client.println(sendstring);
- client.println("");
- for(int x = 0;x < 10;x++){
- while(client.available() > 0){
- Serial.print(client.read());
- }
- delay(1000);
- }
- client.stop();
- }else{
- Serial.println("Failed to connect to dns server");
- }
- }
- OldIPA = IPA;
- }
- BufLine = "";
- }
- }
- Serial.print("\n\n");
- }else{
- Serial.println("Connection failed...");
- //Turn Update Light Off
- }
- for(int i = (30*UpDelay);i > -1 ;i--){
- delay(1000);
- Serial.println(i);
- }
- }
Add Comment
Please, Sign In to add comment