Computer NetworksNETWORKS

MQTT envoyer un message de Raspberry Pi à Amazon AWS

Python code:

import paho.mqtt.client as mqtt
import time

def on_message(client, userdata, message):
print(“message received ” ,str(message.payload.decode(“utf-8”)))
print(“message topic=”,message.topic)
print(“message qos=”,message.qos)
print(“message retain flag=”,message.retain)

broker_address=”[IPv4]”
print(“creating new instance”)
client = mqtt.Client(“P1”)
client.on_message=on_message
print(“connecting to broker”)
client.connect(broker_address)
client.loop_start()
print(“Subscribing to topic”,”Test”)
print(“Publishing message to topic”,”Test”)
client.publish(“Test”,”[Message]”)
time.sleep(10)
client.loop_stop()

source

ipv4

Alice AUSTIN

Alice AUSTIN is studying Cisco Systems Engineering. He has passion with both hardware and software and writes articles and reviews for many IT websites.

Leave a Reply

Your email address will not be published. Required fields are marked *