Lua Client - attempt to index field 'client' (a nil value) [message #1177326] |
Fri, 08 November 2013 23:04 |
Joacim Järkeborn Messages: 4 Registered: November 2013 |
Junior Member |
|
|
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
|
|
|
Re: Lua Client - attempt to index field 'client' (a nil value) [message #1177366 is a reply to message #1177326] |
Fri, 08 November 2013 23:39 |
|
Hi Joacim
Unfortunately the Lua client hasn't had a lot of love so I'm not sure if this is a Lua issue or a client issue! You'll generally get more focus by asking such questions on the mailing list https://dev.eclipse.org/mailman/listinfo/paho-dev rather than the web-based forums, and I would also encourage you to use Bugzilla to ask specific questions.
I'm going to point the original author of the Lua client, Andy Gelme, at this thread to see if he can add any insight. I'd love to see some progress on improving the code.
Developer Advocate | Eclipse Paho project | mqtt.org | andypiper.me
|
|
|
|
Powered by
FUDForum. Page generated in 0.02378 seconds