Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Lua Client - attempt to index field 'client' (a nil value)
Lua Client - attempt to index field 'client' (a nil value) [message #1177326] Fri, 08 November 2013 23:04 Go to next message
Joacim Järkeborn is currently offline Joacim JärkebornFriend
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 Go to previous messageGo to next message
Andy Piper is currently offline Andy PiperFriend
Messages: 17
Registered: November 2011
Location: Kingston upon Thames, UK
Junior Member

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
Re: Lua Client - attempt to index field 'client' (a nil value) [message #1177866 is a reply to message #1177366] Sat, 09 November 2013 07:50 Go to previous message
Joacim Järkeborn is currently offline Joacim JärkebornFriend
Messages: 4
Registered: November 2013
Junior Member
Hi Andy,

Thanks for you reply, I have started with the mailing list.

Guess you don't remember but we met couple a years ago Smile We (Volvo) visited IBM Hursley and had some sessions where MQTT was one + dinner.

Cheers!
Previous Topic:Trouble compiling Paho java plugin
Next Topic:Sent time
Goto Forum:
  


Current Time: Tue Mar 19 10:00:03 GMT 2024

Powered by FUDForum. Page generated in 0.02378 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top