def publish(self, topic, payload, qos=0, retain=False):
"""Publish a message, with the given parameters.
Substitute in the _msg_seq if the payload contains {seq}."""
if not topic:
print("Topic must be specified")
else:
if not payload:
print("Payload not specified, so a zero-length message will be published.")
payload = None
elif (not isinstance(payload, bytearray)) and ("{seq}" in payload):
payload = payload.format(seq=self._msg_seq)
(result, msg_id) = self._mqttclient.publish(topic=topic, payload=payload, qos=qos, retain=retain)
print("...msg_id={!r}, result={} ({})".format(msg_id, result, mqtt.error_string(result)))
if result == mqtt.MQTT_ERR_SUCCESS:
self._msg_seq += 1
mqtt_client_shell.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录