MQTT client was disconnected with reason code 7
I'm using tb-mqtt-client version 1.9.9
When connecting to a gateway device, I keep getting the following message:
MQTT client was disconnected with reason code 7 (The connection was lost.)
This happens continuously (around 1 to 2 times per second). I can send telemetry/attributes in the brief periods that the connection holds, but it is not sustainable.
Here is the minimal code that reproduces my error:
from time import sleep
from tb_gateway_mqtt import TBGatewayMqttClient
import logging
logging.basicConfig(level=logging.DEBUG)
gateway = TBGatewayMqttClient('myUrl.com',
port=1883,
username='deviceToken')
gateway.connect()
i=0
while True:
i+=1
print(f'sent: {"hello_"+str(i)}')
sleep(10)
Is there something wrong with the code or is this a problem on the thingsboard mqtt broker side? I've looked at the thingsboard logs and cannot find anything that would indicate that it is refusing the connection for some reason.
Any help on this would be appreciated!
When I set the loggin level to Debug, Here are the logs I get:
INFO:tb_connection:MQTT client <paho.mqtt.client.Client object at 0x0000025390DDD5E0> - Connected!
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes/response - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/rpc - successfully completed.
WARNING:tb_connection:MQTT client was disconnected with reason code 7 (The connection was lost.)
DEBUG:tb_connection:Client: <paho.mqtt.client.Client object at 0x0000025390DDD5E0>, user data: None, result code: 7. Description: The connection was lost.
INFO:tb_connection:MQTT client <paho.mqtt.client.Client object at 0x0000025390DDD5E0> - Connected!
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes/response - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/rpc - successfully completed.
WARNING:tb_connection:MQTT client was disconnected with reason code 7 (The connection was lost.)
DEBUG:tb_connection:Client: <paho.mqtt.client.Client object at 0x0000025390DDD5E0>, user data: None, result code: 7. Description: The connection was lost.
INFO:tb_connection:MQTT client <paho.mqtt.client.Client object at 0x0000025390DDD5E0> - Connected!
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes/response - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/rpc - successfully completed.
WARNING:tb_connection:MQTT client was disconnected with reason code 7 (The connection was lost.)
DEBUG:tb_connection:Client: <paho.mqtt.client.Client object at 0x0000025390DDD5E0>, user data: None, result code: 7. Description: The connection was lost.
INFO:tb_connection:MQTT client <paho.mqtt.client.Client object at 0x0000025390DDD5E0> - Connected!
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes/response - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/rpc - successfully completed.
WARNING:tb_connection:MQTT client was disconnected with reason code 7 (The connection was lost.)
DEBUG:tb_connection:Client: <paho.mqtt.client.Client object at 0x0000025390DDD5E0>, user data: None, result code: 7. Description: The connection was lost.
I also met once on docker thingsbroad-gateway 3.5.1
Hi @AndreSensaway and @Leo-Hassan, thanks for your interest in ThingsBoard Python Client SDK! Try to use the latest release version (currently 1.10.8) and let us know about the result.
Hello, I've updated to version 1.10.8 and tested the same minimal code that I showed in the first post. The problem persists but instead of showing:
WARNING:tb_connection:MQTT client was disconnected with reason code 7 (The connection was lost.)
it shows:
WARNING:tb_connection:MQTT client was disconnected with reason code None (Description not found.)
Here are the logs I get when running the code:
INFO:tb_connection:MQTT client <paho.mqtt.client.Client object at 0x00000274BF18E490> - Connected!
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes/response - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/rpc - successfully completed.
INFO:tb_connection:Service configuration was successfully retrieved and applied.
INFO:tb_connection:Current limits: {'rateLimit': {'messages': None, 'telemetryMessages': None, 'telemetryDataPoints': None}, 'maxPayloadSize': 65536, 'maxInflightMessages': 100}
WARNING:tb_connection:MQTT client was disconnected with reason code None (Description not found.)
DEBUG:tb_connection:Client: <paho.mqtt.client.Client object at 0x00000274BF18E490>, user data: None, result code: None. Description: Description not found.
INFO:tb_connection:MQTT client <paho.mqtt.client.Client object at 0x00000274BF18E490> - Connected!
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/attributes/response - successfully completed.
DEBUG:tb_connection:Service subscription to topic v1/gateway/rpc - successfully completed.
INFO:tb_connection:Service configuration was successfully retrieved and applied.
INFO:tb_connection:Current limits: {'rateLimit': {'messages': None, 'telemetryMessages': None, 'telemetryDataPoints': None}, 'maxPayloadSize': 65536, 'maxInflightMessages': 100}
WARNING:tb_connection:MQTT client was disconnected with reason code None (Description not found.)
DEBUG:tb_connection:Client: <paho.mqtt.client.Client object at 0x00000274BF18E490>, user data: None, result code: None. Description: Description not found.