nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.64k stars 3.12k forks source link

webap_toggle_pin.lua example is not working #3515

Closed mirmisbahali closed 2 years ago

mirmisbahali commented 2 years ago

I'm trying to create a web server while configuring the esp8266 module in Soft Access Point mode but the webap_toggle_pin.lua example is not working. Also, the tutorials available on the internet are showing how to create a web server while the esp8266 is set up in Station mode but not in Soft Access Point mode.

mirmisbahali commented 2 years ago

Sorry, the webap_toggle_pin.lua example is working fine. It turns out that after connecting the nodemcu wifi I was typing the wrong IP address in the browser URL bar.

We can get the IP address by printing the result of wifi.ap.getip() function.

Here is the code I've written to debug the problem:

wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ ssid = "test",  auth = wifi.OPEN})

srv = net.createServer(net.TCP)

print("Visit http://" .. wifi.ap.getip()) -- Get the IP address

srv:listen(80, function(conn)

    print("connection made")

    conn:on('receive', function(client, request)
    client:send('<h1>hello world</h1>')
    end) 

    conn:on("sent", function(c) c:close() end)
end)