SimplyAutomationized

Lua Ds18b20 example. reading two sensors

May 20th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. t=require('ds18b20')
  2. port = 80
  3. -- ESP-01 GPIO Mapping
  4. gpio0, gpio2 = 3, 4
  5. t.setup(gpio2)
  6. addrs = t.addrs()
  7. srv=net.createServer(net.TCP)
  8. srv:listen(port,
  9.      function(conn)
  10.           addrs = t.addrs()
  11.           temperatures=""
  12.           for key,value in pairs(addrs) do
  13.                 temperatures= temperatures .. t.readNumber(addrs[key],t.F) ..","
  14.           end
  15.           conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
  16.               "<!DOCTYPE HTML>" ..
  17.               "<html><body>" ..
  18.               "<b>ESP8266</b></br>" ..
  19.               "Number of sensors:" .. table.getn(addrs) .. "<br>" ..
  20.               "Temperatures : " .. temperatures .. "<br>" ..
  21.               "Node Heap : " .. node.heap() .. "<br>" ..
  22.               "Timer Ticks : " .. tmr.now() .. "<br>" ..
  23.               "</html></body>")          
  24.           conn:on("sent",function(conn) conn:close() end)
  25.      end
  26. )
Advertisement
Add Comment
Please, Sign In to add comment