Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Lua Client - attempt to index field 'client' (a nil value)

Hi Ian,

I got it working but it was a bit of trial and error :-) because I am not experienced in Lua as such and how things are organized/working. But it seems to me that Micasaverde Vera3 is using the old style module structure and MQTT Client the new module.
I "downgraded" the MQTT Lua client and then everything started to work.
I posted some more information in the thread @,17432.msg135624.html#msg135624

I think MQTT Lua client should be improved both from functionality implementation perspective but also to generalize it as an API. Today have implementations like "isPsp(...)" to check weather the device is a Sony Playstation Portable or not; I think such should be kept as specializations API.

For now I will continue to implement the Vera3 plugin to fetch sensor data and to integrate Emoncms. Will see how much I get into MQTT Lua client and if I can contribute something :-)



On Mon, Nov 11, 2013 at 1:31 PM, Ian Craggs <icraggs@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
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.


On 09/11/13 08:00, Joacim wrote:

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?

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 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))

function startup(lul_device)
	_G["sendToMqtt"] = sendToMqtt
	-- Help prevent race condition ???

	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 = ""
		luup.variable_set(SERVICE_ID, "mqttServerIp", mqttServerIp, SENSOR_MQTT_DEVICE)
	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)
	log("Start - Preparing worker thread", 1)
	-- Prepare the worker "thread"
	luup.call_delay("sendToMqtt", 20, "")
	log("Done - Preparing worker thread", 1)

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)
	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)
	luup.log(SENSOR_MQTT_LOG_NAME .. "Done with MQTT", 1)
	luup.call_delay("sendToMqtt", 10, "")
	luup.log(SENSOR_MQTT_LOG_NAME .. "Leaving sendToMqtt", 1)
I would be happy for some ideas on what’s wrong

paho-dev mailing list

Back to the top