eclipse-paho / eclipse-paho/paho.mqtt.python
Disconnection with error code 16
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 742
- Avg merge
- 12d 48m
- Merged PRs (30d)
- 1
Description
Dear all, I encountered an issue on my client. Specifically, the client is connected to a MQTT broker v3.1.1 with username, password and certs. The client is able to correctly connect and receive messages for some time but then the client enters in this loop:
`
INFO:root:Device disconnected with result code: 16`
`
INFO:root:Device connected with result code: 0
`
`
INFO:root:Device disconnected with result code: 16`
`
INFO:root:Device connected with result code: 0
`
In this way, I can't parse the data. How can i manage this? What means the error code 16? This is my code:
import json
import logging
from paho.mqtt import client as mqtt
import ssl
import os
import copy
logging.getLogger().setLevel(logging.INFO)
USERNAME_BROKER = os.getenv('USERNAME_BROKER')
PWD_BROKER = os.getenv('PWD_BROKER')
BROKER_URL = os.getenv('BROKER_URL')
TOPIC = 'sub/Test/#'
QOS = 0
def on_connect(client, userdata, flags, rc):
logging.info("Device connected with result code: " + str(rc))
def on_disconnect(client, userdata, rc):
logging.info("Device disconnected with result code: " + str(rc))
def on_publish(client, userdata, mid):
logging.info("Device sent message")
def on_message(client, userdata, message):
data = json.loads(message.payload.decode("utf-8"))
print(data)
client = mqtt.Client(client_id=USERNAME_BROKER, protocol=mqtt.MQTTv311)
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_publish = on_publish
client.on_message = on_message
client.username_pw_set(username=USERNAME_BROKER, password=PWD_BROKER)
client.tls_set(ca_certs="./certs/cert1.pem", certfile="./certs/cert2.pem", keyfile="./certs/key.pem",
cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
client.tls_insecure_set(False)
client.connect(BROKER_URL, port=8883, keepalive=30)
client.subscribe(TOPIC, QOS)
client.loop_forever()
Thanks in advance.
Contributor guide
Assessment
This issue has not been assessed yet.