ayushsharma82 / EasyDDNS

Easy to Use ESP8266 & ESP32 DDNS Update Client Library.
MIT License
197 stars 59 forks source link

No-ip not updating whilst using a mobile wifi dongle #37

Open downerhouse opened 2 years ago

downerhouse commented 2 years ago

I am using a ESP32 camera module configured as a security camera. This is intended to be located in my garage, and gains its internet connection via a mobile hotspot.

The code is set up so connect to a variety of wifi SSID's, so the ESP32 will connect at home, or when in the garage.

When the ESP32 boots on my home wifi, it updates no-ip no problem, I can see this on my account, and the text output from the serial port confirms this.

When the ESP32 is connected via the mobile hotspot, it fails to update, nor are any further messages shown.

I am assuming this was in relation to the previous issue logged about IPV4 addresses, but I thought that had been fixed in the 1.8.0 library (which is what I am using).

I have checked, and my mobile provider does not issue IPV6 addresses, and I do not have any other either inbound or outbound connectivity issues through the mobile hotspot firewall.

Please can you advise if there is a workaround, or an update in the pipeline that may fix this?

Many thanks. EasyDDNS Issue.docx

downerhouse commented 2 years ago

Update, so after some digging and debugging, I now know why the update to no-ip does not happen. I assume that all other dynamic DNS services would have the same issue. Although I know why the failure is happening, I do not understand what is causing it.

I'll explain.

In the EasyDDNS.cpp library, the following section is where the request is made for the public IP address:

  WiFiClient client;
  HTTPClient http;
  http.begin(client, "http://ifconfig.me/ip");
  int httpCode = http.GET();
  if (httpCode > 0) {
    if (httpCode == HTTP_CODE_OK) {
      new_ip = http.getString();
  Serial.println(new_ip);
    }

As you can see, I've added a new line to output the result to the serial outut.

When connected to my home network

My code connects to my home Wireless LAN using a dynamic IP address. After connection, the program waits for a number of seconds before checking the public IP. The following output example is given from the above line Serial.println(new_ip);

51.198.63.136

When connected to my mobile dongle

When connecting to the mobile dongle, it connects using a static IP. I have tested both static and dynamic IP's getting the same issue, so the problem is not caused by that. However, with the same line Serial.println(new_ip);, the following is output:

c 92.40.71.203 0

The code is expecting a valid IP address instead of the above additional characters as well. I do not know why these additional characters are being introduced by the http request, or what they mean.

downerhouse commented 2 years ago

A further update.

I made some changes inside EasyDDNS.cpp to try different public IP API's. I tried the following:

  http.begin(client, "http://ifconfig.me/ip");
  http.begin("http://api.ipify.org/");
  http.begin("https://ip4.seeip.org/");

Both ifconfig.me & ipify.org both returned the same spurious characters, where the "c" and "0" were added to the front and end of the returned IP address.

However, seeip.org behaves normally and the no-ip address now correctly gets updated.

This is all very strange behaviour, and I have no clue why those additional characters are added only when I am connected to my mobile dongle.

Grimaction commented 2 years ago

I would suggest to use replace(), remove() and trim() function to cut unnecessary characters from new_ip variable in your own code if you see that behavior.

Side question - why do you want to know mobile (cellular) public IP? I'm afraid you won't be able to reach your ESP32 from such network as mobile networks uses NATs and you cannot open ports.

downerhouse commented 2 years ago

I would suggest to use replace(), remove() and trim() function to cut unnecessary characters from new_ip variable in your own code if you see that behavior.

Side question - why do you want to know mobile (cellular) public IP? I'm afraid you won't be able to reach your ESP32 from such network as mobile networks uses NATs and you cannot open ports.

I've got my code working with the alternative public IP API as described. I did consider using the trim function etc, which may still do, but wanted this page to be aware of some unexplained issues, which as you can see are not bugs in this library code, more a very unusual response in this scenario.

Regarding your question on mobile / public IP.

I use a special APN on my network provider (am not entirely sure they know about it) , which gives me my own public IP and therefore regular port forwarding works just fine. A solution which I've been using for a number of years as I have several remote security cameras.

There are other solutions of course to push the video feed, rather than connect remotely, but until they disable the APN I use (I also have unlimited data plan, and my normal monthly usage on each device is around 500gb), will stuck with current solution ion as it works perfectly.