Webserver in AP (Acess Point) mode


It is the same as the previous chapter, just instead of connecting to wifi as as station, we set wifi.setmode(wifi.SOFTAP)

-- Configure in AP mode (STATION-client, SOFTAP-access point ou STATIONAP- client and access point)

wifi.setmode(wifi.SOFTAP)

----------------------------------
-- Configure ssid and password - doesn't matter since I want the connection to be open
-- cfg={}
-- cfg.ssid="myssid"
-- cfg.pwd="mypassword"
-- wifi.ap.config(cfg)
----------------------------------

print(wifi.ap.getip())


srv=net.createServer(net.TCP)
    srv:listen(80,function(conn)
        conn:on("receive",function(conn,payload)
            print(payload)
            conn:send("<h1> This is my simple webpage </h1>")
            conn:send('<form action="" method="POST">\n')
            conn:send('<input type="submit" name= "button1" value="Left">')
            conn:send('<input type="submit" name= "button1" value="Right">')
    end)
    conn:on("sent",function(conn) conn:close() end)
end)

In your console you will see the IP you have to connect to:

And there you have it:

results matching ""

    No results matching ""