diff --git a/lua_modules/ds18b20/ds18b20-example.lua b/lua_modules/ds18b20/ds18b20-example.lua new file mode 100644 index 00000000..fca1accc --- /dev/null +++ b/lua_modules/ds18b20/ds18b20-example.lua @@ -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 diff --git a/lua_modules/ds18b20/ds18b20-web.lua b/lua_modules/ds18b20/ds18b20-web.lua new file mode 100644 index 00000000..7ff81979 --- /dev/null +++ b/lua_modules/ds18b20/ds18b20-web.lua @@ -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" .. + "" .. + "
" .. + "ESP8266" .. + "Temperature : " .. ds18b20.read() .. "