deverick / Arduino-Upnp-PortMapping

UPNP based portmapping function for the Arduino
29 stars 9 forks source link

Hang on finding External IP #1

Open dave92082 opened 11 years ago

dave92082 commented 11 years ago

I am trying to use this library on both a Duemilanove and a Mega 1280 however on both boards when the example gets to printing the External IP, the sketch hangs. The External IP is: line prints and nothing further occurs no matter how much time passes by.

I am using Arduino IDE 1.0.5 with a Seeed Studio Ethernet shield and Netgear WNDR3700 router with uPNP enabled. I have verified that other devices on the network can create port maps using uPNP.

Output I recieve is: Initializing... Configured Ethernet using DHCP device IP is: 192.168.0.25 gateway IP is: 192.168.0.1 subnet mask is: 255.255.255.0 DNS is: 192.168.0.1 External IP is:

dave92082 commented 11 years ago

I've added some debugging Serial.prinln()'s to the library and it appears that it is not getting past this section:

if (_apmClient.connect(igdIp(), igdPort())) {

I changed it to the following:

Serial.println("Entered getExternalIpRequest()"); if (_apmClient.connect(igdIp(), igdPort())) { Serial.println("Entered IF statement"); ... ... } else {

Serial.println("no connection to server"); // if you didn't get a connection to the server: _apmClient.stop(); return 0; }

It never gets further than the first line. Output from the serial monitor is as follows: Initializing... Configured Ethernet using DHCP device IP is: 192.168.0.25 gateway IP is: 192.168.0.1 subnet mask is: 255.255.255.0 DNS is: 192.168.0.1 External IP is: Entered getExternalIpRequest()

I'll post more as I learn.

dave92082 commented 11 years ago

After a lot of debugging, I found where the code hit a never ending while loop. In the parseXmlResponse method, it is getting stuck looking for LINE_FEED which never comes. Instead it appears that my router is stopping the packet data without a line feed so the wile loop goes on forever due to _igdClient.read() returning a -1. I am able to resolve it wrapping that line as follows:

if (_igdClient.available()) c = _igdClient.read(); else break;

It looks like I still may be failing to map a port though. To be continued...

dave92082 commented 11 years ago

I still wasn't able to get a port forwarded since it wasn't able to parse the response from my Netgear WNDR3700. I made a modification to the parseXmlResponse method to grab the first instance of and now it is working. I am going to make the same change to the other parse method in an attempt to free up some more resources. As it is, my implementation is only using around 800 bytes of RAM to parse out the controlURL.

If I can figure out how to submit a patch on here I will, if not I'll fork it. Great library by the way!!!

thefantas commented 8 years ago

I have a similar error, but only when the power is off (obviously not give external IP) should exit the process but not to stay frozen on line 42 portMapping.cpp "If (_apmClient.connect (igdIp (), igdPort ()))".

pino-dev-br commented 6 years ago

I'm needing a upnp port forwarding from Arduino. Does anybody solve?