Added cmd MQTT sublevel and refactored function
This commit is contained in:
parent
34e47c9a39
commit
9534368b01
22
mqtt.lua
22
mqtt.lua
@ -2,14 +2,7 @@
|
||||
m=nil
|
||||
mqttConnected = false
|
||||
|
||||
-- MQTT extension
|
||||
function registerMqtt()
|
||||
m = mqtt.Client("wordclock", 120)
|
||||
-- on publish message receive event
|
||||
m:on("message", function(client, topic, data)
|
||||
print(topic .. ":" )
|
||||
if data ~= nil then
|
||||
print(data)
|
||||
function handleSingleCommand(client, topic, data)
|
||||
if (data == "ON") then
|
||||
briPercent=100
|
||||
m:publish(mqttPrefix .. "/clock", "ON", 0, 0)
|
||||
@ -33,6 +26,18 @@ function registerMqtt()
|
||||
print "Unknown MQTT command"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- MQTT extension
|
||||
function registerMqtt()
|
||||
m = mqtt.Client("wordclock", 120)
|
||||
-- on publish message receive event
|
||||
m:on("message", function(client, topic, data)
|
||||
print(topic .. ":" )
|
||||
if data ~= nil then
|
||||
print(data)
|
||||
handleSingleCommand(client, topic, data)
|
||||
end
|
||||
end)
|
||||
|
||||
@ -44,6 +49,7 @@ function registerMqtt()
|
||||
tmr.alarm(3, 500, 0, function()
|
||||
-- publish a message with data = hello, QoS = 0, retain = 0
|
||||
client:publish(mqttPrefix .. "/ip", tostring(wifi.sta.getip()), 0, 0)
|
||||
client:subscribe(mqttPrefix .. "/cmd/#", 0)
|
||||
end)
|
||||
end,
|
||||
function(client, reason)
|
||||
|
Loading…
Reference in New Issue
Block a user