Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <Ethernet.h>
  2. #include <SPI.h>
  3. ////////////////////////////////////////////////////////////////////
  4.  
  5. //Delay between updates in minutes.
  6. int Delay =  30;
  7.  
  8. char DNS_Server[] = "dynamicdns.park-your-domain.com";
  9. int DNS_Port = 80;
  10.  
  11. byte mac_address[] = {0x91,0xA2,0xDB,0x02,0x05,0x17};
  12.  
  13. /////////////////////////////////////////////////////////////////////
  14. char oldIP[16];
  15. char newIP[16];
  16.  
  17. void setup(){
  18.   Serial.begin(9600);
  19.   Serial.println("\nStarted...");
  20.   Serial.println("Ethernet Configuration (please wait)");
  21.   while(Ethernet.begin(mac_address) == 0){
  22.     Serial.println("failure.  Retrying in 5 seconds.");
  23.     delay(5000);
  24.   }
  25.   Serial.println("Successful.  Allow 5 seconds to fully initialize.");
  26.   delay(10000);  
  27. }
  28.  
  29.  
  30. void loop() {
  31.   Serial.println("Loop");
  32.   if(GetIPFromServer(newIP)){
  33.     Serial.println(newIP);
  34.   }
  35.   else {
  36.     Serial.println("Didn't get any data?");
  37.   }
  38.   delay(Delay*1000);
  39. }
  40.  
  41.  
  42.  
  43. byte GetIpFromServer(char buffer[]){
  44.   EthernetClient client;
  45.   if (client.connect("biranchi.com/",80)){
  46.     client.println("GET /ip.php HTTP/1.0");
  47.     client.println("");
  48.    
  49.     while (!client.available()){}
  50.    
  51.     int i = 0;
  52.     char ch = client.available();
  53.     while (ch != '\n'){
  54.       if (client.available()){
  55.         buffer[i] = client.read();
  56.         i++;
  57.     }
  58.     client.stop();
  59.     return 1;
  60.   }
  61.   return 0;
  62. }
Add Comment
Please, Sign In to add comment