Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
netadmin:protocoles:mqtt:mqttv5_user_properties [2022/12/20 23:51] – yoann | netadmin:protocoles:mqtt:mqttv5_user_properties [2022/12/25 16:32] (Version actuelle) – yoann | ||
---|---|---|---|
Ligne 25: | Ligne 25: | ||
===== User properties à publier ===== | ===== User properties à publier ===== | ||
- | + | Le client du module Python Paho depuis sa version 1.5.1 supporte MQTTv5 | |
+ | |||
+ | ==== Client Python Paho ==== | ||
+ | |||
+ | Pour utiliser le protocole MQTTv5, il faut bien spécifier la version du protocole à utiliser lors de l' | ||
+ | |||
+ | <code python> | ||
+ | from paho.mqtt.client import Client as MqttClient | ||
+ | from paho.mqtt.client import MQTTv5 as MQTTv5 | ||
+ | |||
+ | aClient = MqttClient(" | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | from paho.mqtt.properties import Properties | ||
+ | from paho.mqtt.packettypes import PacketTypes | ||
+ | |||
+ | properties=Properties(PacketTypes.CONNECT) | ||
+ | properties.MaximumPacketSize=20 | ||
+ | |||
+ | aClient.connect(host, | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | from paho.mqtt.properties import Properties | ||
+ | from paho.mqtt.packettypes import PacketTypes | ||
+ | |||
+ | aProp = Properties(PacketTypes.PUBLISH) | ||
+ | |||
+ | from datetime import datetime | ||
+ | |||
+ | aDateString = " | ||
+ | aDateTime = datetime.strptime(aDateString, | ||
+ | ts = int(aDateTime.timestamp()) | ||
+ | |||
+ | aProp.UserProperty = [(" | ||
+ | |||
+ | # vérifier les user properties sont des paires clés/ | ||
+ | aProp.json() | ||
+ | {' | ||
+ | |||
+ | |||
+ | aClient.connect(" | ||
+ | aClient.publish(topic=" | ||
+ | |||
+ | </ | ||
===== Références ===== | ===== Références ===== | ||
* http:// | * http:// | ||
+ | * http:// | ||
+ | * http:// | ||
* https:// | * https:// |