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)

I forwarded the original forum discussion to Andy Gelme, hopefully he's following this list too, I know he has been busy with other projects.

Great to know you have it working. We know about a bunch of the things that need to be improved, but you're right to highlight a few of the specifics which are device-specific - they may not really belong in the Eclipse version of this library. We should take another look at that.

As you use the Lua client, feel free to raise issues or submit patches via our Bugzilla, the more folks who help and collaborate around the code, the better it can become! :-)



On Mon, Nov 11, 2013 at 2:29 PM, 4 Integration <4integration@xxxxxxxxx> wrote:
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 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 :-)

Thanks.

Regards
Joacim




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.

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



_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev




--
Andy Piper | Kingston upon Thames, London (UK)
blog: http://andypiper.co.uk   |   skype: andypiperuk
twitter: @andypiper  |  images: http://www.flickr.com/photos/andypiper

Back to the top