Saataa andagii !
This commit is contained in:
parent
934e97a709
commit
7a9860a3bb
2 changed files with 44 additions and 3 deletions
38
mqtt.lua
38
mqtt.lua
|
@ -1,4 +1,4 @@
|
|||
client = mqtt.client("ESP32", "192.168.1.76", 1883, false)
|
||||
client = mqtt.client("ESP32", "192.168.0.11", 1883, false)
|
||||
client:connect("","")
|
||||
|
||||
function printMaster(length, msg)
|
||||
|
@ -9,8 +9,40 @@ function printAlt(length, msg)
|
|||
console("[ALT]"..msg)
|
||||
end
|
||||
|
||||
max_temp = 0
|
||||
min_temp = 100
|
||||
max_place = ""
|
||||
min_place = ""
|
||||
|
||||
function printBuildingTemp(length, msg)
|
||||
local temp_str, place = pack.unpack(msg)
|
||||
local temp = tonumber(temp_str)
|
||||
if temp > max_temp then
|
||||
max_temp = temp
|
||||
max_place = place
|
||||
end
|
||||
if temp < min_temp then
|
||||
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)
|
||||
tmr.delayms(5000)
|
||||
end
|
||||
end
|
||||
|
||||
client:subscribe("MASTER", mqtt.QOS0, printMaster)
|
||||
client:subscribe("ALT", mqtt.QOS0, printAlt)
|
||||
client:publish("MASTER", "Hello, world!", mqtt.QOS0)
|
||||
client:publish("ALT", "Hello, world!", mqtt.QOS0)
|
||||
-- client:publish("MASTER", "Hello, world!", mqtt.QOS0)
|
||||
-- client:publish("ALT", "Hello, world!", mqtt.QOS0)
|
||||
|
||||
temp_sender = thread.start(sendTemp)
|
||||
client:subscribe("Building/temp", mqtt.QOS0, printBuildingTemp)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue