aboutsummaryrefslogtreecommitdiff
path: root/diller/mq.lua
diff options
context:
space:
mode:
Diffstat (limited to 'diller/mq.lua')
-rw-r--r--diller/mq.lua24
1 files changed, 10 insertions, 14 deletions
diff --git a/diller/mq.lua b/diller/mq.lua
index 66927e2..f3136d6 100644
--- a/diller/mq.lua
+++ b/diller/mq.lua
@@ -2,26 +2,22 @@ local P = {}
local m, topic, cid
local subscriptions = {}
-local function p(msg)
- print("# MQTT: "..msg)
-end
-
local function mq_client_connected(con)
- p("connected")
+ info("mqtt: connected")
end
local function subscribed()
- p("subscribed")
+ info("mqtt: subscribed")
end
local function disconnect()
- p("Lost wifi connection, disconnecting")
+ info("mqtt: Lost wifi connection, disconnecting")
m:close()
m = nil
end
local function on_message(client, topic, message)
- -- p("on_message: topic="..topic..", message="..message)
+ -- p("mqtt: on_message: topic="..topic..", message="..message)
local _, _, new_property_name = string.find(topic, '/property/([%a%d-]+)/name$')
if new_property_name then
@@ -38,13 +34,13 @@ end
function mq_on_timer()
-- This crashes the module:
-- local status = wifi.sta.status()
- -- p("checking status, status="..status)
+ -- p("mqtt: checking status, status="..status)
local status = wifi.sta.getip()
if status and status ~= "0.0.0.0" then
if not m then
- p("connecting")
+ info("mqtt: connecting")
-- client id, keepalive, username, password
m = mqtt.Client(cid, 120)
@@ -73,11 +69,11 @@ end
function P.subscribe(path)
local subscription = subscriptions[path]
if subscription then
- print("subscription on "..path.." already registered, state="..tostring(subscription.state))
+ info("mqtt: subscription on "..path.." already registered, state="..tostring(subscription.state))
return
end
- print("Registering subscription on "..path)
+ info("mqtt: Registering subscription on "..path)
subscriptions[path] = true
@@ -87,12 +83,12 @@ end
function P.publish(path, payload)
if not m then
- print("Not connected, dropping message to "..path)
+ info("mqtt: Not connected, dropping message to "..path)
return false, 'not connected'
end
path = topic.."/"..path
- print("path="..path)
+ info("mqtt: path="..path)
m:publish(path, payload, 0, 0)
return true, 'ok'