0

have an esp8266.

i'm trying to create a DDNS updater.

it has to wait 5 min then do a GET request to a URL.

Here's my code:

/* Code For DNS Updater.*/

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define LOOP_TIME 300000

const char* ssid = "SomeSSID";
const char* password = "SomePSWD";

const String address="http://dynamicdns.park-your-domain.com";
const String path="update";
const String pathHost="host";
const String pathPassword="password";
const String pathDomain="domain";


const String dnsName="my-example-host.com";
const String ddnsPassword="my-example-password";
const String updateHosts[]={
    "@",
    "subdomain1",
    "subdomain2",
  };

void setup() {
  Serial.begin(115200);
  connectWiFi();
}

long nextUpdate=0;

void loop() {
  if(nextUpdate<millis()){
    if (WiFi.status() == WL_CONNECTED) {
    updateDNS();
    }else{
      connectWiFi();
    }
    nextUpdate=millis()+LOOP_TIME;
  }
}

void updateDNS(){
  Serial.println("Updating Hosts:");
  for(int host=0;host<(sizeof(updateHosts)/sizeof(String));host++){
    Serial.print(updateHosts[host]+": ");
    String assembledURL=address+"/"+path+"?"+pathHost+"="+updateHosts[host]+"&"+pathDomain+"="+dnsName+"&"+pathPassword+"="+ddnsPassword;
//    Serial.println("Host: "+updateHosts[host]+" URL: "+assembledURL);
    HTTPClient http;
    http.begin(assembledURL);
    http.GET();
    http.end();
    Serial.println("Done");
  }
}

void connectWiFi(){
  WiFi.begin(ssid, password);

  Serial.print("Connecting To ");
  Serial.println(ssid);
  Serial.print("Password: ");
  Serial.println(password);
  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {

    delay(500);
    Serial.print(".");

  }
  Serial.println();
  Serial.print("Connected To ");
  Serial.println(ssid);
}

and it stops after a couple of hours - which isnt good for a DDNS updater.

EDIT: maybe it has something to do with my timer. will try an unsigned long instead.

  • Hi @NadavTasher and welcome to the Arduino Stack Exchange community. Unfortunately your question doesn't meet our quality standards.Your question is rather terse. Please edit and improve it. See How to Ask and How to ask a good question for Arduino Stack Exchange. – sa_leinad Jun 28 '18 at 5:51
  • what version of esp8266 arduino package? – Juraj Jun 28 '18 at 12:38
  • shouldn't if(nextUpdate<millis()){ be if(nextUpdate>millis()){, as in the timeout is past the current time? – dandavis Jun 28 '18 at 20:06
  • no, cause if nextUpdate is for example 5000 and millis is 4000 we dont yet wanna run the update. – Nadav Tasher Jul 1 '18 at 8:31
1

I have had the "stops after a while" too and it turned out to be heap memory consumption and fragmentation that caused not having enough stack and heap space any more.

My solution: check the heap from time to time (in loop) and reboot the node when it comes down to a practical limit.

Alternate: avoid using the String type and other Heap usages.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.