Chat freely about anything...

User avatar
By TerryE
#19646 The f specifier does round:
Code: Select all=("%.1f"):format(2/3)
0.7
User avatar
By Ambro
#19676 If I insert the suggested line then there is a problem: it does not work .
> 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
User avatar
By twaymouth
#19698 ds18b20.lc is the compiled code generated when you issue the node.compile command. To update this code you need to remove init.lua, reboot and then remove ds18b29.lc in this order otherwise you will end up with a boot loop. The files can be removed by using the file.remove("") command.

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?
User avatar
By Ambro
#19756 If I load the following file then It does not respond 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
)

>>> 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