run telnet, and HTTP. Start up AP mode, and station mode.

This commit is contained in:
Ryan Voots 2016-05-01 15:30:43 -07:00
parent b875d5b80d
commit cdfb1b8071

View file

@ -11,6 +11,7 @@ wifiConfig.accessPointConfig = {}
wifiConfig.accessPointConfig.ssid = "ESP-"..node.chipid() -- Name of the SSID you want to create
wifiConfig.accessPointConfig.pwd = "ESP-"..node.chipid() -- WiFi password - at least 8 characters
-- default connection setup, just in case we don't have one saved.
wifiConfig.stationPointConfig = {}
wifiConfig.stationPointConfig.ssid = "Scalar24" -- Name of the WiFi network you want to join
wifiConfig.stationPointConfig.pwd = "Fb274Gh@12G1" -- Password for the WiFi network
@ -23,11 +24,6 @@ print('MAC: ',wifi.sta.getmac())
print('chip: ',node.chipid())
print('heap: ',node.heap())
wifi.ap.config(wifiConfig.accessPointConfig)
wifi.sta.config(wifiConfig.stationPointConfig.ssid, wifiConfig.stationPointConfig.pwd)
wifiConfig = nil
collectgarbage()
-- End WiFi configuration
-- Compile server code and remove original .lua files.
@ -43,15 +39,29 @@ local compileAndRemoveIfNeeded = function(f)
end
end
local serverFiles = {'telnet.lua'}
local serverFiles = {'telnet.lua', 'httpserver.lua', 'httpserver-basicauth.lua', 'httpserver-conf.lua', 'httpserver-b64decode.lua', 'httpserver-request.lua', 'httpserver-static.lua', 'httpserver-header.lua', 'httpserver-error.lua', 'wificonfig.lua'}
for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end
compileAndRemoveIfNeeded = nil
serverFiles = nil
-- Check for a wifi config file
if file.open("wificonfig.lc") then
file.close()
print('Found config.')
wifiConfig.stationPointConfig = dofile("wificonfig.lc")
end
-- Start the APs once we hit here
wifi.ap.config(wifiConfig.accessPointConfig)
wifi.sta.config(wifiConfig.stationPointConfig.ssid, wifiConfig.stationPointConfig.pwd)
wifiConfig = nil
collectgarbage()
-- Connect to the WiFi access point.
-- Once the device is connected, you may start the HTTP server.
-- We run an AP, and connect to an AP. We need to start the servers early.
dofile("telnet.lc")(23)
dofile("httpserver.lc")(80)
local joinCounter = 0
local joinMaxAttempts = 5
@ -65,9 +75,6 @@ tmr.alarm(0, 3000, 1, function()
print('Failed to connect to WiFi Access Point.')
else
print('IP: ',ip)
-- tmr.delay(1000)
-- Uncomment to automatically start the server in port 80
dofile("telnet.lc")(23)
end
tmr.stop(0)
joinCounter = nil