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?
netmodule instead of thehttpmodule: nodemcu.readthedocs.io/en/latest/en/modules/net/#netsocketon - Marcel Stör