=("%.1f"):format(2/3)
0.7
> If i do compile node.compile("ds18b20.lua") then I have an additional file called ds18b20.lc ( 1988 ) in the file list.
>> is this correct ?
On my side the system works if the three files are loaded one at the time ( save to ESP ) with no additional action.
I just have to change the format of the temperature xx.yy now
>> Is this program capable of managing negative celsius temperature ?
Thanks,
Ambro
Once the files are removed upload the new ds18b20.lua, compile it, reboot then upload init.lua.
The second way to do this is directly add the rounding command to the ds18b20-web.lua file by replacing the temperature line with the following code:
"Temperature : " .. string.format("%02.1f",ds18b20.read()) .. "<br>" ..
if you want to use the second method, remove init.lua, reboot and then upload the new ds18b20-web.lua file. reboot again and upload init.lua. no changes need to be made to ds18b20.lua with the second method.
And yes, this code should be capable of managing negative temperature however being in Melbourne I may never get to test it, maybe I could put a sensor in the freezer?
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
)
>>> if I load the following file then it responds to the net :
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
)
Ambro