Mise à jour avec la nouvelle API (V2) de Paho MQTT
This commit is contained in:
12
snmp2mqtt.py
12
snmp2mqtt.py
@@ -179,12 +179,14 @@ def load_config(config_path):
|
||||
|
||||
|
||||
def connect_mqtt(mqtt_config):
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
print("Connected to MQTT Broker!")
|
||||
def on_connect(client, userdata, connect_flags, reason_code, properties):
|
||||
if reason_code == 0:
|
||||
logging.info("Connected to MQTT Broker!")
|
||||
else:
|
||||
print("Failed to connect, return code {rc}")
|
||||
client = mqtt_client.Client()
|
||||
logging.error(f"Failed to connect to MQTT Broker, reason code: {reason_code}")
|
||||
|
||||
# Use the new callback API version 2
|
||||
client = mqtt_client.Client(callback_api_version=mqtt_client.CallbackAPIVersion.VERSION2)
|
||||
client.username_pw_set(mqtt_config["user"], mqtt_config["password"])
|
||||
client.on_connect = on_connect
|
||||
client.connect(mqtt_config['broker'], mqtt_config['port'])
|
||||
|
Reference in New Issue
Block a user