Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rtctime.set(1)
- client = nil
- function wifiClose()
- client = nil
- wifi.sta.eventMonStop()
- wifi.sta.disconnect()
- print( "Wifi closed, mem: "..node.heap().."\n\r" )
- tmr.alarm(0, 3000, tmr.ALARM_SINGLE, function()
- local sec = 1000000
- local interval = 20
- local tm = interval * sec - tmr.now()
- if tm < sec then tm = interval * sec end
- rtctime.dsleep( tm )
- end)
- end
- function createClient()
- client = net.createConnection( net.TCP, 0 )
- client:on( "connection", function( socket, data )
- local sec,usec = rtctime.get()
- print( "Connected to server\n\r" )
- socket:send( sec..","..tmr.time() )
- end)
- client:on( "receive", function( socket, data )
- print( "Received from server: "..data.."\n\r" )
- socket:close()
- wifiClose()
- end)
- client:connect( 10000, "10.1.1.1" )
- end
- function wifiClient()
- print( "-------------------------------------------------\n\r" )
- print( "Wifi on\n\r" )
- local ip = {}
- ip.ip = "10.1.1.10"
- ip.netmask = "255.255.255.0"
- ip.gateway = "10.1.1.1"
- wifi.sleeptype( wifi.NONE_SLEEP )
- wifi.setphymode( wifi.PHYMODE_B )
- wifi.setmode( wifi.STATION )
- wifi.sta.config( "blah", "blah" )
- wifi.sta.setip( ip )
- wifi.sta.eventMonReg( wifi.STA_GOTIP, function()
- print( "GOT IP in "..tmr.time().." sec\n\r" )
- tmr.alarm( 0, 1000, tmr.ALARM_SINGLE, function()
- createClient()
- end)
- end)
- wifi.sta.eventMonStart()
- wifi.sta.connect()
- end
- wifiClient()
Advertisement
Add Comment
Please, Sign In to add comment