Advertisement
doublemintben

my server.lua

Mar 10th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. -- This module implements a simple web-server to allow configuration changes via Wi-Fi.
  2. -- Please be careful! Since it's just an example of working with ESP module, it has no access control at all (to keep things simple).
  3.  
  4. local atmega = require "atmega"
  5.  
  6. sv = net.createServer(net.TCP, 30)
  7.  
  8. local function close_connection(c)
  9.     c:close()
  10. end
  11.  
  12. function receiver(sck, data)
  13.   print(data)
  14.   sck:close()
  15. end
  16.  
  17.  
  18. if sv then
  19.     sv:listen(5000, function(conn)
  20.         conn:on("receive", receiver)
  21.         local stuff = atmega.getMessage()
  22.         if stuff == nil then
  23.             stuff = "fail"
  24.         end
  25.         local test = "test 1 " .. stuff
  26.         conn:send(test, close_connection)
  27.     end)
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement