Raspy MQTT Tests added
This commit is contained in:
parent
fc545d59a1
commit
e39b2a2753
13
software/roboter/raspy/mqtt_publish1.py
Normal file
13
software/roboter/raspy/mqtt_publish1.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
mqttBroker = "mqtt.eclipseprojects.io"
|
||||||
|
client = mqtt.Client("Temperature")
|
||||||
|
client.connect(mqttBroker)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
randNumber = random.randint(0, 20)
|
||||||
|
client.publish("TEMPERATURE", randNumber)
|
||||||
|
print("Published " + str(randNumber) + " to topic TEMPERATURE")
|
||||||
|
time.sleep(2)
|
21
software/roboter/raspy/mqtt_subscribe.py
Normal file
21
software/roboter/raspy/mqtt_subscribe.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
|
||||||
|
def on_message_temp(client, userdata, message):
|
||||||
|
print("Received temp message: ", str(message.payload.decode("utf-8")))
|
||||||
|
|
||||||
|
def on_message_hum(client, userdata, message):
|
||||||
|
print("Received hum message: ", str(message.payload.decode("utf-8")))
|
||||||
|
|
||||||
|
|
||||||
|
mqttBroker = "mqtt.eclipseprojects.io"
|
||||||
|
client = mqtt.Client("Smartphone_temp")
|
||||||
|
|
||||||
|
client.message_callback_add("TEMPERATURE", on_message_temp)
|
||||||
|
client.message_callback_add("HUMIDITY", on_message_hum)
|
||||||
|
|
||||||
|
client.connect(mqttBroker)
|
||||||
|
client.subscribe("TEMPERATURE")
|
||||||
|
client.subscribe("HUMIDITY")
|
||||||
|
|
||||||
|
client.loop_forever()
|
Loading…
x
Reference in New Issue
Block a user