init.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. -- Tel--l the chip to connect to the access point
  2. --wifi.setmode(wifi.STATIONAP)
  3. wifi.setmode(wifi.STATION)
  4. print('set (mode='..wifi.getmode()..')')
  5. print('MAC: ',wifi.sta.getmac())
  6. print('chip: ',node.chipid())
  7. print('heap: ',node.heap())
  8. <<<<<<< HEAD
  9. local joincounter = 0
  10. cfg={}
  11. cfg.ssid="ESP-"..node.chipid()
  12. cfg.pwd="ESP-"..node.chipid()
  13. wifi.ap.config(cfg)
  14. cfg = nil
  15. =======
  16. wifi.sta.config("Kirsch Extreme","1151511515")
  17. >>>>>>> parent of 4989410... Update init.lua
  18. -- Compile server code and remove original .lua files.
  19. -- This only happens the first time afer the .lua files are uploaded.
  20. local compileAndRemoveIfNeeded = function(f)
  21. if file.open(f) then
  22. file.close()
  23. node.compile(f)
  24. file.remove(f)
  25. end
  26. end
  27. local serverFiles = {'httpserver.lua', 'httpserver-request.lua', 'httpserver-static.lua', 'httpserver-error.lua','http/ual.lua'}
  28. for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end
  29. compileAndRemoveIfNeeded = nil
  30. serverFiles = nil
  31. -- Connect to the WiFi access point. Once the device is connected,
  32. -- you may start the HTTP server.
  33. tmr.alarm(0, 3000, 1, function()
  34. if wifi.sta.getip() == nil and joincounter < 5 then
  35. print("Connecting to AP...")
  36. joincounter = joincounter +1
  37. else
  38. tmr.stop(0)
  39. -- print('IP: ',wifi.sta.getip())
  40. -- Uncomment to automatically start the server in port 80
  41. joincounter = nil
  42. collectgarbage()
  43. dofile("httpserver.lc")(80)
  44. end
  45. end)