-- Author: moononournation -- Notes by Marcos: This example could be improved quite a bit. -- We should provide a way to return available access points as JSON, then populated -- a drop down list using JavaScript every 5-10 seconds. I'm not sure it's worth it, -- however. return function (connection, req, args) dofile('httpserver-header.lc')(connection, 200, 'html') connection:send('Connect AP

Connect AP

') if req.method == 'GET' then local ip = wifi.sta.getip() if not (ip == nil) then connection:send('

IP: ' .. ip .. '

') end connection:send('
SSID:

PWD:

') elseif req.method == 'POST' then local rd = req.getRequestData() collectgarbage() wifi.sta.config(rd['ssid'], rd['pwd']) wifi.sta.connect() local joinCounter = 0 local joinMaxAttempts = 15 tmr.alarm(0, 1000, 1, function() local ip = wifi.sta.getip() if ip == nil and joinCounter < joinMaxAttempts then joinCounter = joinCounter + 1 else if joinCounter >= joinMaxAttempts then connection:send('

Failed to connect to WiFi Access Point.

') else connection:send('

IP: ' .. ip .. '

') end tmr.stop(0) joinCounter = nil joinMaxAttempts = nil collectgarbage() end end) end connection:send('') end