Hi Joacim,
unfortunately, we haven't heard from the author of the Lua client
for a while. It could be a problem in the client code. I'll take
a look if I get the chance. If anyone out there is interested in
looking at the Lua client, we'd like to hear from you.
Ian
On 09/11/13 08:00, Joacim wrote:
Hi,
Trying to get MQTT
Lua client running on Micasaverde Vera 3 (home automation
controller) but get problems.
I am new to Lua so
maybe beginner's problem?!
Do you see anything
strange?
Error:
01 11/09/13 0:00:36.101 luup_log:62: SensorMqtt plugin: Enter sendToMqtt <0x2d773680>
01 11/09/13 0:00:36.101 luup_log:62: SensorMqtt plugin: Create MQTT Client <0x2d773680>
01 11/09/13 0:00:36.102 luup_log:62: SensorMqtt plugin: Connect to 192.168.1.21 and port 1883 <0x2d773680>
01 11/09/13 0:00:36.102 LuaInterface::CallFunction_Timer-5 function sendToMqtt failed [string "module("L_SensorMqtt", package.seeall)..."]:47: attempt to index field 'client' (a nil value) <0x2d773680>
The code:
module("L_SensorMqtt", package.seeall)
-- Service ID strings used by this device.
SERVICE_ID = "urn:upnp-sensor-mqtt-se:serviceId:SensorMqtt1"
local mqttServerIp = nil
local mqttServerPort = 0
local MQTT = require("mqtt_library")
local SENSOR_MQTT_LOG_NAME = "SensorMqtt plugin: "
local function log(text, level)
luup.log("SensorMqtt plugin: " .. text, (level or 50))
end
function startup(lul_device)
_G["sendToMqtt"] = sendToMqtt
-- Help prevent race condition ???
-- luup.io.intercept()
SENSOR_MQTT_DEVICE = lul_device
log("Initialising SensorMqtt", 1)
--Reading variables
mqttServerIp = luup.variable_get(SERVICE_ID, "mqttServerIp", SENSOR_MQTT_DEVICE)
if(mqttServerIp == nil) then
mqttServerIp = "0.0.0.0"
luup.variable_set(SERVICE_ID, "mqttServerIp", mqttServerIp, SENSOR_MQTT_DEVICE)
end
mqttServerPort = luup.variable_get(SERVICE_ID, "mqttServerPort", SENSOR_MQTT_DEVICE)
if(mqttServerPort == nil) then
mqttServerPort = "0"
luup.variable_set(SERVICE_ID, "mqttServerPort", mqttServerPort, SENSOR_MQTT_DEVICE)
end
log("Start - Preparing worker thread", 1)
-- Prepare the worker "thread"
luup.call_delay("sendToMqtt", 20, "")
log("Done - Preparing worker thread", 1)
end
function sendToMqtt(luup_data)
luup.log(SENSOR_MQTT_LOG_NAME .. "Enter sendToMqtt", 1)
luup.log(SENSOR_MQTT_LOG_NAME .. "Create MQTT Client", 1)
luup.log(SENSOR_MQTT_LOG_NAME .. "Connect to " .. mqttServerIp .. " and port " .. mqttServerPort, 1)
mqttServerPort = tonumber(mqttServerPort)
local mqtt_client = MQTT.client.create(mqttServerIp, mqttServerPort)
luup.log(SENSOR_MQTT_LOG_NAME .. "Connect MQTT Client", 1)
mqtt_client:connect("Vera")
luup.log(SENSOR_MQTT_LOG_NAME .. "Publish MQTT message", 1)
mqtt_client:publish("Vera/Test", "*** Vera test start ***")
--mqtt_client:subscribe({ args.topic_s })
luup.log(SENSOR_MQTT_LOG_NAME .. "Destroy MQTT Client", 1)
mqtt_client:destroy()
luup.log(SENSOR_MQTT_LOG_NAME .. "Done with MQTT", 1)
luup.call_delay("sendToMqtt", 10, "")
luup.log(SENSOR_MQTT_LOG_NAME .. "Leaving sendToMqtt", 1)
end
I would be happy for some ideas on what’s wrong
Regards
Joacim
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev
|