thingsboard-python-client-sdk icon indicating copy to clipboard operation
thingsboard-python-client-sdk copied to clipboard

Incompatibility with asyncua library

Open ts4iot opened this issue 3 years ago • 0 comments

I try to use the tb_device_mqtt library together with the asyncronous opc-ua library asyncua and asyncio.Queue().

With the standard paho-mqtt library the sending of the data works fine. With tb_device_mqtt library it is not working.

The relevant part of the code looks like this: p_plc is the asyncua client q_queue is an async.Queue

    async with g_plc:
	    await subscribe()
	    while g_running:
		    if(not g_queue.empty()):
			    g_logger.info("Queue size start: %d" % g_queue.qsize())	
			    while(not g_queue.empty()):
				    send_data(await g_queue.get())
		    await g_plc.check_connection()
		    await asyncio.sleep(0.001)
	    await asyncio.sleep(2)

The send_data function sends the data to the thingsboard server.

With paho-mqtt I send the data with:

	ret = g_rcc_mqtt.publish('v1/devices/me/telemetry', data, 1)
	g_logger.info(ret)

With tb_device_mqtt I send the data with:

	result = g_rcc_mqtt.send_telemetry(data)
	success = result.get() == TBPublishInfo.TB_ERR_SUCCESS
	g_logger.info(success)

With tb_device_mqtt I get after some seconds the exception: Message publish failed: The client is not currently connected. Is there an example that shows how to use tb_device_mqtt library inside asyncio code.

ts4iot avatar Mar 20 '23 11:03 ts4iot