1
votes

My setup is like this : Nodemcu and raspberry pi are connected to a WiFi router. My lua code in Nodemcu needs to call a REST API hosted in the raspberry pi over the WLAN.

But I could see that the connection is failing:

http.get("http://192.168.43.100:8080/api/logdevice", nil, function (code, resp) print(code, resp) end)
> --http.get("http://example.com", nil, function (code, resp) print(code, resp) end)HTTP client: Disconnected with error: -11
HTTP client: Connection timeout
HTTP client: Connection timeout

When I give an internet address (http://example.com), the request is succeeding.

I am able to access the REST API from another laptop in the same WiFi network.

I have verified that the WiFi settings are correct by using the lua code:

ip, netmask, gateway = wifi.sta.getip()

Is there any limitation in nodemcu while accessing private IP addresses?

UPDATE 1 : I made nodemcu the Access Point and connected the API server machine to it. Now nodemcu is able to access the API. But this is not the WiFi setup I need. I need nodemcu to be the WiFi Station. So I am thinking this might be an issue in the routing table. Is there any extra route config I should do after connecting nodemcu to an external AP?

1
Does it work if you use the low-level net module instead of the http module: nodemcu.readthedocs.io/en/latest/en/modules/net/#netsocketon - Marcel Stör
@MarcelStör That also failed - Kiran
So, you can access the internet from NodeMCU but not resources in your private network? There are no known issues or limitations that I'm aware of in this area. The fact neither HTTP nor net operations succeed for private resources IMHO suggest a "blocking" network component on your end. - Marcel Stör
@MarcelStör This sounds like my issue : github.com/nodemcu/nodemcu-firmware/issues/1089 Also another laptop on the same network can access this. - Kiran
I doubt it. That issue basically said that when 192.168.43.100/foo wouldn't work then 192.168.43.100:80/foo would. So, it seemed to be related to default ports 80/443 but that's just my personal conclusion. Also, in that issue it was established that calling the same resource with the net module works. - Marcel Stör

1 Answers

0
votes

If I am understanding this correctly you appear to have addressed connectivity between the nodemcu device and the internet (beyond your router) by calling an external site. You have also checked that you can locally call the REST api within your network by using another device suggesting the issue appears to be with communication specifically between the nodemcu and rpi on the wireless network.

I would check the DHCP screen on your router to verify the IP addresses of the nodemcu and rpi. Try to ping the nodemcu from the rpi or laptop. Turn on whatever logging is available on the rpi webserver to check for an inbound request (from laptop and then nodemcu) and also verify the netmask setting for the nodemcu is the same as the rpi (as the webserver response could be routed out of the gateway if they differ).

You could also try connecting to the rpi using a simple telnet client from the nodemcu if you want to try a "simpler" more direct test.

It would be helpful to have the actual values for IP address, netmask and gateway for the nodemcu, rpi and laptop to pursue this further.