Advertisement
xorkrus

Untitled

May 5th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. gpio.mode(5, gpio.INPUT)
  2. srv=net.createServer(net.TCP)
  3. srv:listen(80,function(conn)
  4. print(payload)
  5.   conn:on("receive",function(conn,payload)
  6.     print(payload)
  7.     if ( gpio.read(5) == 0 ) then
  8.         reply = "GPIO14 (5) is 0"
  9.     elseif ( gpio.read(5) == 1 ) then
  10.         reply = "GPIO14 (5) is 1"
  11.     else
  12.         reply = "GPIO14 (5) is ERR"
  13.     end
  14.         payloadLen = string.len(reply)
  15.         print(payloadLen)
  16.         conn:send("HTTP/1.1 200 OK\r\n")
  17.         conn:send("Content-Length:" .. tostring(payloadLen) .. "\r\n")
  18.         conn:send("Connection:close\r\n\r\n")
  19.         conn:send(reply)
  20.   end)
  21.   conn:on("sent",function(conn)
  22.     conn:close()
  23.   end)
  24. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement