Saturday, February 4, 2017

Duck DNS ESP8266 mini WiFi client


This is a Duck DNS ESP8266 mini WiFi client.


Duck DNS (https://www.duckdns.org/) is a free Dynamic DNS (DDNS) service.
It as a few client available for many operating system and a few routers.
A friend of mine runs a router that does not support any of the Duck DNS update mode. Instead of loading his operating system with the Duck DNS updater, or installing an openwrt router, I've implemented an ESP8266 client.


It is powered by USB, it can also be powered by the router USB port.
It's built on a pretty old ESP-01 board.
It has two led, one is the ESP-01 WiFi connection status embedded one, the other is connected to the GPIO2 port, and it's used for the DNS update status.


We need just a 3.3 voltage regulator to run this board using any 5V USB power output capable of 200mA.
The code is written using the Arduino IDE + ESP8266 core, to me that's the fastest and simple way to work with ESP8266.

The WiFiManager library (https://github.com/tzapu/WiFiManager) is used to facilitate the WiFi connection of this module.

Also it runs a web server that allow any user to setup the DuckDNS connection parameters.
User can set the DDNS domain name and token, and also the update interval and the module hostname, that way one can just forget the module IP and open the web configuration page by board name. The default board name is espduckdns001, so the web page address is http://espduckdns001


Code

Notes
  • read risk disclaimer
  • excuse my bad english


42 comments:

  1. Dear Good evening I find very interesting the project but faces a small problem with the code when I go to compile my displays any errors with arduino I'm already 1.8.1.

    (Arduino: 1.8.1 (Windows 10), board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 1M (512K SPIFFS), ck")


    ESPDuckDNS: 426: error: 'HTTP_CODE_OK' was not declared in this scope

         (If (httpCode == HTTP_CODE_OK) {)

                          ^

    '' Exit status 1
    'HTTP_CODE_OK' was not declared in this purpose

    If you can please help.

    Sorry for the miserable englise

    Thanks.

    George

    ReplyDelete
    Replies
    1. Hello, thank you. I think your issue is that you do not have the ESp8266HttpClient library installed. I've checked right now, on Arduino 1.8.1, it compiles.

      Delete
  2. Using Arduino 1.8.0, under ubuntu, everything work flawlessy.
    Spectacular ideea and professionally done work, thank you for sharing this enormous amount of knowledge, Davide Gironi.

    ReplyDelete
    Replies
    1. Thank you! I really appreciate it.

      Delete
    2. Dear friend thank you for an immediate answer to the problem solved I did uninstall and Resettlement Programmes thank you very much for your time

      Yours sincerely

      George

      Delete
    3. Salem
      i have the same problem how do you solve it

      Delete
  3. Thank you very much for your design and code. Works great!!

    ReplyDelete
  4. hello, i cant tray do work, the esp-01 ever freez, the led blue is on and no respose serial comunication.
    please could you help me.

    ReplyDelete
    Replies
    1. Hello, you have to debug it using uart as example. Or you can also double check your wiring, or trying other hardware if you have another esp8266.

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Nice work, thanks!

    For those who don't want to mess with flashing an ESP-001, this should work on any ESP8266-based board such as NodeMCU, Weimos D1 mini, Adafruit Huzzah, etc.

    Works great for me on NodeMCU 1.0 with Arduino IDE 1.8.5 and ESP8266 board library 2.3.0. 2.6.3 had some compile errors that I was too lazy to fix.

    ReplyDelete
  7. this will work with CH340 or CP2102 NodeMcu V3¿

    i wanna buy one of them from here:
    www.aliexpress.com/item/32665100123.html?spm=a2g0o.productlist.0.0.57f56d13prDaxp&algo_pvid=acf4cdd0-5683-4600-9bc6-552e9f6c36d7&algo_expid=acf4cdd0-5683-4600-9bc6-552e9f6c36d7-0&btsid=0ab6f83115984213058228520e4d59&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

    ReplyDelete
    Replies
    1. Hello shay, yes, it will work on any ESP8266. But i suggest you the CP2102 version, because the driver works with many OS.

      Delete
    2. i got my order, from where i can start¿

      Delete
    3. Dear shay, You just have to compile and upload the image to the ESP8266. You can find online many tutorial about this task.

      Delete
    4. before i can start complie and upload, i need a few sketch libraries and board manager's, can you please name thus libraries¿

      Delete
    5. Hello shay, if I remeber well It was Just WiFiManager, anyway you can find the list in the .ino project file.

      Delete
    6. this is working PERFECT,

      BIG THANKS for you,

      now i can let go the crappy free no-ip service that annoying me every month to "renew" my free subscription

      Delete
    7. That's great! Thank you for sharing your experience here.

      Delete
    8. Thanks you again for you making this awsome project,

      If you think about the costs, for me its only 10nis (new israeli shekel) and i have a tiny server that will run forever

      Delete
    9. This comment has been removed by the author.

      Delete
    10. hello, this can work with ipv6¿

      Delete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. In function 'int ddnsUpdate()':
    sketch_oct26a:416:15: error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
    416 | http.begin(getrequest);
    | ~~~~~~~~~~^~~~~~~~~~~~
    exit status 1
    call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
    Can't figure out what's the problem. I'm not used to arduino, found this project useful in internet. So, if anyone know how to make this work please help me guys.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. //send the request, retry on error
      int updateretries = 0;
      do {
      HTTPClient http;
      http.begin(getrequest);//////////error/////////////
      int httpCode = http.GET();
      if(httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      if(payload == "OK")
      updated = 1;
      }

      Delete
    3. Hello, you should check that you have installed all the library needed.

      Delete
    4. ESP8266WiFi
      DNSServer
      ESP8266WebServer
      ESP8266mDNS
      ESP8266HTTPClient --> I don't know why this particular include statement is not highlighted for me in orange color in code while all other libraries are highlighted.
      EEPROM
      WiFiManager
      Ticker
      All these libraries are present in sketch>include library>contributed libraries, even ESP8266HTTPClient is also present.

      Delete
    5. You are using newer libraries, 'HTTPClient::begin' is obsolete, you should change a litte the code in order to compile it correctly.

      Delete
    6. what should i change? can you help me?
      or can i change the libraries to an older version?

      Delete
    7. Unluckly I've not much time to code this. Take a look here: https://stackoverflow.com/questions/67702822/error-call-to-httpclientbegin-declared-with-attribute-error-obsolete-api Let me know if it works.

      Delete
    8. As I said I am a beginner to Arduino, I tried but I can't figure it out. But I'm creating a micro version of your project according to my use case. So it would be helpful for me if you could tell how did you manage to find the public ip address in your code. I followed [variable "getrequest" in ddnsUpdate() function] but can't find. HELP ME IF YOU COULD SPARE SOME TIME.

      Delete
    9. This comment has been removed by the author.

      Delete
    10. This comment has been removed by the author.

      Delete
    11. This comment has been removed by the author.

      Delete
    12. This comment has been removed by the author.

      Delete
  10. ESP8266+CP2102, I saw it have 5v pin.
    That's means that I dont have to put the voltage regulator circuit?

    ReplyDelete
    Replies
    1. Hello Unknown user, it depends on the way the CP2102 is wired up.

      Delete