thingsboard / thingsboard-python-client-sdk

ThingsBoard client Python SDK
https://thingsboard.io
Other
111 stars 64 forks source link

MQTT client was disconnected with reason code 7 #72

Open AndreSensaway opened 2 weeks ago

AndreSensaway commented 2 weeks ago

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.
Leo-Hassan commented 5 days ago

I also met once on docker thingsbroad-gateway 3.5.1