Saataa andagii !
This commit is contained in:
parent
48b0b4047e
commit
ddc46bdd2a
9 changed files with 40 additions and 64 deletions
10
mqtt.lua
10
mqtt.lua
|
@ -1,6 +1,10 @@
|
|||
client = mqtt.client("ESP32", "192.168.0.11", 1883, false)
|
||||
client:connect("","")
|
||||
|
||||
nb = 0
|
||||
net.service.http.start()
|
||||
console(net.stat(true)[0]["ip"])
|
||||
|
||||
function printMaster(length, msg)
|
||||
console("[MASTER]"..msg)
|
||||
end
|
||||
|
@ -15,7 +19,7 @@ max_place = ""
|
|||
min_place = ""
|
||||
|
||||
function printBuildingTemp(length, msg)
|
||||
local temp_str, place = pack.unpack(msg)
|
||||
local temp_str, place = split(msg, ":")
|
||||
local temp = tonumber(temp_str)
|
||||
if temp > max_temp then
|
||||
max_temp = temp
|
||||
|
@ -25,15 +29,13 @@ function printBuildingTemp(length, msg)
|
|||
min_temp = temp
|
||||
min_place = place
|
||||
end
|
||||
console("Max : ["..max_place.."] "..max_temp)
|
||||
console("Min : ["..min_place.."] "..min_temp)
|
||||
end
|
||||
|
||||
function sendTemp()
|
||||
s = sensor.attach("DHT22", pio.GPIO21)
|
||||
tmr.delayms(500)
|
||||
while true do
|
||||
client:publish("Building/temp", pack.pack(s:read("temperature"), "Salon"), mqtt.QOS0)
|
||||
client:publish("Building/temp", s:read("temperature")..":Salon", mqtt.QOS0)
|
||||
tmr.delayms(5000)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue