コード例 #1
0
def publish(client: mqtt, msg):
    status, _ = client.publish(topic, msg)

    if status == 0:
        print(f"Sending: {msg}")
    else:
        print("Error in sending a message")
コード例 #2
0
def publish(client: mqtt_client):
    msg_count = 0
    while True:
        time.sleep(1)
        msg = f"messages: {msg_count}"
        result = client.publish(topic, msg)
        # result: [0, 1]
        status = result[0]
        if status == 0:
            print(f"====>Send `{msg}` to topic `{topic}`")
        else:
            print(f"Failed to send message to topic {topic}")
        msg_count += 1
コード例 #3
0
def publish(client: mqtt_client):
    msg_count = 0
    while True:
        time.sleep(1)
        msg = f"messages: {msg_count}"
        result = client.publish(topic_incoming, msg)
        status = result[0]
        if status == 0:
            print(f"Sent {msg} to topic {topic_incoming}")
        else:
            print(f"Failed to send message to topic {topic_incoming}")

        msg_count += 1