|
@@ -38,8 +38,7 @@ function calibrate(temp)
|
|
|
return CorrectedValue
|
|
return CorrectedValue
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-local ow_pin = TEMP_PIN
|
|
|
|
|
-ds18b20.setup(ow_pin)
|
|
|
|
|
|
|
+ds_read_counter = 0
|
|
|
|
|
|
|
|
function ds_start_read()
|
|
function ds_start_read()
|
|
|
ds18b20.read(
|
|
ds18b20.read(
|
|
@@ -47,12 +46,13 @@ function ds_start_read()
|
|
|
local mac = string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)"))
|
|
local mac = string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)"))
|
|
|
local temp = calibrate(raw_temp)
|
|
local temp = calibrate(raw_temp)
|
|
|
print(ind,mac,res,temp,raw_temp)
|
|
print(ind,mac,res,temp,raw_temp)
|
|
|
- ok, json = pcall(sjson.encode, {rom=mac, res=res, temp=temp, raw=raw_temp})
|
|
|
|
|
|
|
+ ok, json = pcall(sjson.encode, {rom=mac, res=res, temp=temp, raw=raw_temp, cnt=ds_read_counter})
|
|
|
if ok then
|
|
if ok then
|
|
|
m:publish(MQTT_TOPIC, json, 0, 0, function(client) print("sent "..json.." to "..MQTT_TOPIC) end)
|
|
m:publish(MQTT_TOPIC, json, 0, 0, function(client) print("sent "..json.." to "..MQTT_TOPIC) end)
|
|
|
else
|
|
else
|
|
|
print("failed to encode!")
|
|
print("failed to encode!")
|
|
|
end
|
|
end
|
|
|
|
|
+ ds_read_counter = ds_read_counter + 1
|
|
|
end,{});
|
|
end,{});
|
|
|
end
|
|
end
|
|
|
|
|
|
|
@@ -76,4 +76,5 @@ function do_mqtt_connect()
|
|
|
m:connect(MQTT_SERVER, handle_mqtt_connected, handle_mqtt_error)
|
|
m:connect(MQTT_SERVER, handle_mqtt_connected, handle_mqtt_error)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ds18b20.setup(TEMP_PIN)
|
|
|
do_mqtt_connect()
|
|
do_mqtt_connect()
|