Advertisement
doublemintben

init.lua

Mar 16th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. --uart config--
  2. BAUD = 115200
  3. DATABITS = 8
  4. PARITY = uart.PARITY_NONE
  5. STOPBITS = uart.STOPBITS_1
  6.  
  7.  
  8. --wifi config--
  9. WIFI_SSID = "SSID"
  10. WIFI_PASSWORD = "PASSWORD"
  11. WIFI_SIGNAL_MODE = wifi.PHYMODE_G
  12.  
  13. --ip config--
  14. IP = "10.10.10.250"
  15. NETMASK = "255.255.255.0"
  16. GATEWAY = "10.10.10.1"
  17.  
  18. --setup uart--
  19. uart.setup(0, BAUD, DATABITS, PARITY, STOPBITS, 0)
  20.  
  21. --connect to wifi--
  22. wifi.setmode(wifi.STATION)
  23. wifi.setphymode(WIFI_SIGNAL_MODE)
  24. wifi.sta.config(WIFI_SSID, WIFI_PASSWORD)
  25. wifi.sta.connect()
  26.  
  27. if ip ~= "" then
  28.     wifi.sta.setip({ip=IP, netmask=NETMASK, gateway=GATEWAY})
  29. end
  30.  
  31. function startup()
  32.     if file.open("init.lua") == nil then
  33.         print("init.lua deleted or renamed")
  34.     else
  35.         print("Running")
  36.         file.close("init.lua")
  37.         -- the actual application is stored in 'application.lua'
  38.         require "server"
  39.     end
  40. end
  41.  
  42. -- Start server after 2.5 sec.
  43. tmr.alarm(0, 2500, tmr.ALARM_SINGLE, function()
  44.     uart.on("data") -- stop listening UART.
  45.     print "starting server..."
  46.     tmr.unregister(0)
  47.     tmr.alarm(1, 3000, tmr.ALARM_SINGLE, startup)
  48. end)
  49.  
  50. -- Listen to UART data and stop the above timer in case of "qw" string was received.
  51. uart.on("data", "w", function(d)
  52.     if d == "qw" then
  53.         tmr.stop(0) -- Stop timer. Server won't start.
  54.         tmr.stop(1)
  55.         uart.on("data")
  56.         print "cancelled."
  57.     elseif data == "287797648" then
  58.         tmr.stop(0) -- Stop timer. Server won't start.
  59.         tmr.stop(1)
  60.         uart.on("data")
  61.         print "cancelled."
  62.     end
  63. end, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement