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()
ipv4