Guest User

Untitled

a guest
Apr 29th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. tm = 0
  2.  
  3. function wifiServer()
  4. local ap = {}
  5. ap.ssid = "blah"
  6. ap.pwd = "blah"
  7.  
  8. local ip = {}
  9. ip.ip="10.1.1.1"
  10. ip.netmask="255.255.255.0"
  11. ip.gateway="10.1.1.1"
  12.  
  13. wifi.setmode(wifi.SOFTAP)
  14. wifi.setphymode(wifi.PHYMODE_B)
  15. wifi.sleeptype(wifi.NONE_SLEEP)
  16. wifi.ap.setmac("99-99-99-99-99-99")
  17. wifi.ap.config(ap)
  18. wifi.ap.setip(ip)
  19. wifi.ap.dhcp.stop()
  20. end
  21.  
  22. function netServer()
  23. local server = net.createServer( net.TCP, 10 )
  24. server:listen( 10000, function( conn )
  25. conn:on( "receive", function( socket, data )
  26. print( "DATA: "..data.."\n\r" )
  27. socket:send( "OK C:"..data.." on S:"..tmr.time() )
  28. print( "Drift: --> "..(tmr.time()-tm).." sec\n\r" )
  29. tm = tmr.time()
  30. end)
  31. conn:on( "connection", function()
  32. print( "Client connected\n\r")
  33. end)
  34. conn:on( "disconnection", function()
  35. print( "Client disconnected \n\r")
  36. end)
  37. conn:on( "reconnection", function()
  38. print( "Client re-connected\n\r")
  39. end)
  40. end)
  41. end
  42.  
  43. wifiServer()
  44. netServer()
Advertisement
Add Comment
Please, Sign In to add comment