Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esp32cam UPnP and EasyDDNS to No-Ip no connection #76

Open
fredythegreat opened this issue Jan 17, 2024 · 1 comment
Open

Esp32cam UPnP and EasyDDNS to No-Ip no connection #76

fredythegreat opened this issue Jan 17, 2024 · 1 comment

Comments

@fredythegreat
Copy link

fredythegreat commented Jan 17, 2024

So, i am trying to get a esp32cam module to run a web server via a LTE Router with UPnP. I have created a No-Ip Account and a hostname without ddns key for my project. The router has a working sim-card with internet flatrate. The problem is i am not getting a connection to no-ip and i have no idea, why. The code looks like this (UPnP Example):

/*
Note: This example includes the library EasyDDNS. You'll have to add this package using your Arduino Library Manager.
The purpose of this package is to publish your dynamic IP to a DDNS service that will allocate a human readable
address to your current IP. If you do not need that, you can remove this dependency.
*/

#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <TinyUPnP.h>
#include <EasyDDNS.h> // see note above

const char* ssid = "";
const char* password = "";
#define LISTEN_PORT 2222 // http://:<LISTEN_PORT>/?name=
#define LEASE_DURATION 36000 // seconds
#define FRIENDLY_NAME "" // this name will appear in your router port forwarding section
#define DDNS_USERNAME ""
#define DDNS_PASSWORD ""
#define DDNS_DOMAIN ""

TinyUPnP tinyUPnP(20000); // -1 means blocking, preferably, use a timeout value (ms)
WebServer server(LISTEN_PORT);

const int led = 13;

void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp32!");
digitalWrite(led, 0);
}

void handleNotFound() {
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}

void setup(void) {
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

boolean portMappingAdded = false;
tinyUPnP.addPortMappingConfig(WiFi.localIP(), LISTEN_PORT, RULE_PROTOCOL_TCP, LEASE_DURATION, FRIENDLY_NAME);
while (!portMappingAdded) {
portMappingAdded = tinyUPnP.commitPortMappings();
Serial.println("");

if (!portMappingAdded) {
  // for debugging, you can see this in your router too under forwarding or UPnP
  tinyUPnP.printAllPortMappings();
  Serial.println(F("This was printed because adding the required port mapping failed"));
  delay(30000);  // 30 seconds before trying again
}

}

Serial.println("UPnP done");

if (MDNS.begin("esp32")) {
Serial.println("MDNS responder started");
}

server.on("/", handleRoot);

server.on("/inline", {
server.send(200, "text/plain", "this works as well");
});

server.onNotFound(handleNotFound);

server.begin();
Serial.println("HTTP server started");

}

void loop(void) {

EasyDDNS.update(300000);

tinyUPnP.updatePortMappings(600000); // 10 minutes

server.handleClient();

delay(5);
}

I was not sure which port to use so i chose 2222 not sure if thats the way to go. As all the DDNS Definitions are not used in the code i copied the code from the EasyDDNS page into my code:

EasyDDNS.service("noip");
EasyDDNS.client("DDNS_DOMAIN", "DDNS_USERNAME", "DDNS_PASSWORD");

The esp boots normally and in the serial monitor the last three lines say "UPnP done, MDNS responder started, HTTP Server started". The UPnP stuff seems to work and i am not really sure what i am doing wrong. Can anyone point me in the right direction? Thanks

@ofekp
Copy link
Owner

ofekp commented Jan 21, 2024

I will be available next week, if I haven't answered, please ping me here. Thanks.
Meanwhile, please attempt to use the latest commit from master branch, as it contains some fixes which are not included in the version that is installed by default using the IDE. Let me know if the problem persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants