Merge pull request #88 from baracudaz/master

DS18B20 module examples
This commit is contained in:
zeroday 2015-01-11 00:36:04 +08:00
commit 56daed7b70
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,19 @@
t = require("ds18b20")
-- ESP-01 GPIO Mapping
gpio0 = 3
gpio2 = 4
t.setup(gpio0)
addrs = t.addrs()
if (addrs ~= nil) then
print("Total DS18B20 sensors: "..table.getn(addrs))
end
-- Just read temperature
print("Temperature: "..t.read().."'C")
-- Don't forget to release it after use
t = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil

View File

@ -0,0 +1,27 @@
require('ds18b20')
port = 80
-- ESP-01 GPIO Mapping
gpio0, gpio2 = 3, 4
ds18b20.setup(gpio0)
srv=net.createServer(net.TCP)
srv:listen(port,
function(conn)
conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
"<!DOCTYPE HTML>" ..
"<html><body>" ..
"<b>ESP8266</b></br>" ..
"Temperature : " .. ds18b20.read() .. "<br>" ..
"Node ChipID : " .. node.chipid() .. "<br>" ..
"Node MAC : " .. wifi.sta.getmac() .. "<br>" ..
"Node Heap : " .. node.heap() .. "<br>" ..
"Timer Ticks : " .. tmr.now() .. "<br>" ..
"</html></body>")
conn:on("sent",function(conn) conn:close() end)
end
)