Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --uart config--
- BAUD = 115200
- DATABITS = 8
- PARITY = uart.PARITY_NONE
- STOPBITS = uart.STOPBITS_1
- --wifi config--
- WIFI_SSID = "SSID"
- WIFI_PASSWORD = "PASSWORD"
- WIFI_SIGNAL_MODE = wifi.PHYMODE_G
- --ip config--
- IP = "10.10.10.250"
- NETMASK = "255.255.255.0"
- GATEWAY = "10.10.10.1"
- --setup uart--
- uart.setup(0, BAUD, DATABITS, PARITY, STOPBITS, 0)
- --connect to wifi--
- wifi.setmode(wifi.STATION)
- wifi.setphymode(WIFI_SIGNAL_MODE)
- wifi.sta.config(WIFI_SSID, WIFI_PASSWORD)
- wifi.sta.connect()
- if ip ~= "" then
- wifi.sta.setip({ip=IP, netmask=NETMASK, gateway=GATEWAY})
- end
- function startup()
- if file.open("init.lua") == nil then
- print("init.lua deleted or renamed")
- else
- print("Running")
- file.close("init.lua")
- -- the actual application is stored in 'application.lua'
- require "server"
- end
- end
- -- Start server after 2.5 sec.
- tmr.alarm(0, 2500, tmr.ALARM_SINGLE, function()
- uart.on("data") -- stop listening UART.
- print "starting server..."
- tmr.unregister(0)
- tmr.alarm(1, 3000, tmr.ALARM_SINGLE, startup)
- end)
- -- Listen to UART data and stop the above timer in case of "qw" string was received.
- uart.on("data", "w", function(d)
- if d == "qw" then
- tmr.stop(0) -- Stop timer. Server won't start.
- tmr.stop(1)
- uart.on("data")
- print "cancelled."
- elseif data == "287797648" then
- tmr.stop(0) -- Stop timer. Server won't start.
- tmr.stop(1)
- uart.on("data")
- print "cancelled."
- end
- end, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement