Refactor MQTT function names
This commit is contained in:
parent
d1b5e67ce6
commit
fb2556c62c
11
mqtt.lua
11
mqtt.lua
@ -1,9 +1,9 @@
|
|||||||
-- Global variable
|
-- Global variable
|
||||||
t=nil
|
m=nil
|
||||||
mqttConnected = false
|
mqttConnected = false
|
||||||
|
|
||||||
-- MQTT extension
|
-- MQTT extension
|
||||||
function startMqtt()
|
function registerMqtt()
|
||||||
m = mqtt.Client("wordclock", 120)
|
m = mqtt.Client("wordclock", 120)
|
||||||
-- on publish message receive event
|
-- on publish message receive event
|
||||||
m:on("message", function(client, topic, data)
|
m:on("message", function(client, topic, data)
|
||||||
@ -30,17 +30,20 @@ function startMqtt()
|
|||||||
mqttConnected = true
|
mqttConnected = true
|
||||||
-- subscribe topic with qos = 0
|
-- subscribe topic with qos = 0
|
||||||
client:subscribe(mqttPrefix .. "/command", 0)
|
client:subscribe(mqttPrefix .. "/command", 0)
|
||||||
|
tmr.alarm(3, 500, 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)
|
||||||
|
end)
|
||||||
end,
|
end,
|
||||||
function(client, reason)
|
function(client, reason)
|
||||||
print("failed reason: " .. reason)
|
print("failed reason: " .. reason)
|
||||||
|
m=nil
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function startMqttClient()
|
function registerMqttClient()
|
||||||
if (mqttServer ~= nil and mqttPrefix ~= nil) then
|
if (mqttServer ~= nil and mqttPrefix ~= nil) then
|
||||||
startMqtt()
|
registerMqtt()
|
||||||
print "Started MQTT client"
|
print "Started MQTT client"
|
||||||
oldBrightness=0
|
oldBrightness=0
|
||||||
oldTemp=0
|
oldTemp=0
|
||||||
|
Loading…
Reference in New Issue
Block a user