Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client ID is reset to b'' after the instantiation of Mqtt object #87

Open
vsupacha opened this issue Jan 24, 2021 · 1 comment
Open

Comments

@vsupacha
Copy link

Environment
Python 3.7.9 on Windows 10, Jupyter Notebook, Ubuntu 20.04 (WSL)
Tested with my target broker, vanilla mosquitto docker, test.mosquitto.org
Flask 1.1.2
Flask-MQTT 1.1.1
Paho-MQTT 1.5.1

Issue

  1. Internal client ID is reset to b'' even app.config[MQTT_CLIENT_ID] is set.
  2. Try a simple workaround, and it is good even string client ID (UUID style).
app.config['MQTT_CLIENT_ID'] = 'UUID'
mqtt = Mqtt(app)
print(mqtt.client._client_id)
mqtt.client._client_id = app.config['MQTT_CLIENT_ID']

Info
Logger from docker

DEBUG:flask_mqtt:Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
DEBUG:flask_mqtt:Connected client '28ceb5d2-2415-4fe9-b249-d5eeff6d78ce' to broker localhost:1883
b''
b'28ceb5d2-2415-4fe9-b249-d5eeff6d78ce'
16 Received CONNACK (0, 0)
DEBUG:flask_mqtt:Received CONNACK (0, 0)
Connected
 * Serving Flask app "testFlaskMQTT" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
INFO:werkzeug: * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit) 

Log message from the target broker

DEBUG:flask_mqtt:Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
DEBUG:flask_mqtt:Connected client '28ceb5d2-2415-4fe9-b249-d5eeff6d78ce' to broker broker.netpie.io:1883
b''
 * Serving Flask app "testFlaskMQTT" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
INFO:werkzeug: * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)
b'28ceb5d2-2415-4fe9-b249-d5eeff6d78ce'
8 failed to receive on socket: [WinError 10054] An existing connection was forcibly closed by the remote host
ERROR:flask_mqtt:failed to receive on socket: [WinError 10054] An existing connection was forcibly closed by the remote host
b'28ceb5d2-2415-4fe9-b249-d5eeff6d78ce'
16 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'28ceb5d2-2415-4fe9-b249-d5eeff6d78ce'
DEBUG:flask_mqtt:Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'28ceb5d2-2415-4fe9-b249-d5eeff6d78ce'
b'28ceb5d2-2415-4fe9-b249-d5eeff6d78ce'
16 Received CONNACK (0, 0)
DEBUG:flask_mqtt:Received CONNACK (0, 0)
Connected
@KT-network
Copy link

KT-network commented Jul 22, 2023

image
另一种解决办法,将检查MQTT_CLIENT_ID的代码放到检查client_id的对象类型之前。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants