Support only one single command
This commit is contained in:
parent
a68313e55f
commit
9eabc733f4
@ -35,7 +35,7 @@ Determine the IP address of your clock and execute the following script:
|
|||||||
* GPIO0 factory reset (long during operation)
|
* GPIO0 factory reset (long during operation)
|
||||||
|
|
||||||
## MQTT Interface
|
## MQTT Interface
|
||||||
* **basetopic**/command
|
* **basetopic**/cmd/single
|
||||||
** ON Set brightness to 100%
|
** ON Set brightness to 100%
|
||||||
** OFF Set brightness to 0%
|
** OFF Set brightness to 0%
|
||||||
** 0-100 Set brightness to given value
|
** 0-100 Set brightness to given value
|
||||||
|
7
mqtt.lua
7
mqtt.lua
@ -41,7 +41,7 @@ function registerMqtt()
|
|||||||
print(topic .. ":" )
|
print(topic .. ":" )
|
||||||
if data ~= nil then
|
if data ~= nil then
|
||||||
print(data)
|
print(data)
|
||||||
if (topic == (mqttPrefix .. "/command")) then
|
if (topic == (mqttPrefix .. "/cmd/single")) then
|
||||||
handleSingleCommand(client, topic, data)
|
handleSingleCommand(client, topic, data)
|
||||||
else
|
else
|
||||||
-- Handle here the /cmd/# sublevel
|
-- Handle here the /cmd/# sublevel
|
||||||
@ -63,11 +63,10 @@ function registerMqtt()
|
|||||||
print("MQTT is connected")
|
print("MQTT is connected")
|
||||||
mqttConnected = true
|
mqttConnected = true
|
||||||
-- subscribe topic with qos = 0
|
-- subscribe topic with qos = 0
|
||||||
client:subscribe(mqttPrefix .. "/command", 0)
|
client:subscribe(mqttPrefix .. "/cmd/#", 0)
|
||||||
tmr.alarm(3, 500, 0, function()
|
tmr.alarm(3, 1000, 0, function()
|
||||||
-- publish a message with data = hello, QoS = 0, retain = 0
|
-- publish a message with data = hello, QoS = 0, retain = 0
|
||||||
client:publish(mqttPrefix .. "/ip", tostring(wifi.sta.getip()), 0, 0)
|
client:publish(mqttPrefix .. "/ip", tostring(wifi.sta.getip()), 0, 0)
|
||||||
client:subscribe(mqttPrefix .. "/cmd/#", 0)
|
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
function(client, reason)
|
function(client, reason)
|
||||||
|
Loading…
Reference in New Issue
Block a user