You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: You may remove this section prior to submitting your question.
A small team of volunteers monitors issues; this is the same team that develops the library. Whilst we are keen to help,
there are often better places to ask questions, including:
Stack Overflow - well written questions are generally answered
within a day. Please use the tags MQTT, Python and Paho.
Reddit - great for questions requiring discussion.
MQTT Google Group - fairly quiet but questions about the protocol are generally answered quickly.
def on_connect(client, userdata, flags, reason_code, properties):
if reason_code.is_failure:
print(f"Failed to connect: {reason_code}. loop_forever() will retry connection")
else:
# we should always subscribe from on_connect callback to be sure
# our subscribed is persisted across reconnections.
#client.subscribe("$SYS/#")
client.subscribe(MQTT_TOPIC)
Prerequisites
Note: You may remove this section prior to submitting your question.
A small team of volunteers monitors issues; this is the same team that develops the library. Whilst we are keen to help,
there are often better places to ask questions, including:
within a day. Please use the tags MQTT, Python and Paho.
Prior to asking a question here, please:
"Known limitations" section) and look at the examples.
to test your assumptions.
Question
(1) make account file
cd /etc/mosquitto
mosquitto_passwd -c .account userid
Password: passwd
Reenter password: passwd
(2) /etc/mosquitto/mosquitto.conf
.....
password_file /etc/mosquitto/.account
.....
(3) source code
import time
import paho.mqtt.client as mqtt
MQTT_SERVER = "127.0.0.1"
MQTT_PORT = 1883
MQTT_TOPIC = "wind"
def on_connect(client, userdata, flags, reason_code, properties):
if reason_code.is_failure:
print(f"Failed to connect: {reason_code}. loop_forever() will retry connection")
else:
# we should always subscribe from on_connect callback to be sure
# our subscribed is persisted across reconnections.
#client.subscribe("$SYS/#")
client.subscribe(MQTT_TOPIC)
.......
client_userdata = 1
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
......
mqttc.on_connect = on_connect
......
username = "userid"
password = "passwd"
mqttc.username_pw_set(username, password)
mqttc.user_data_set([])
mqttc.connect(MQTT_SERVER, MQTT_PORT)
.....
mqttc.loop_forever()
Result
Failed to connect: Not authorized. loop_forever() will retry connection
Environment
It's often helpful for us to know how you are using the library so please provide:
The text was updated successfully, but these errors were encountered: