init.lua 1.5 KB

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