Browse Source

Send JSON via MQTT added

master
Luis Waldhauser 1 year ago
parent
commit
d27076ba54
1 changed files with 20 additions and 0 deletions
  1. 20
    0
      software/roboter/raspy/send_json.py

+ 20
- 0
software/roboter/raspy/send_json.py View File

@@ -0,0 +1,20 @@
import paho.mqtt.client as mqtt
import random
import time
import json

mqttBroker = "mqtt.eclipseprojects.io"
client1 = mqtt.Client("RobotData")
client1.connect(mqttBroker)

dataDict = {
"Temperature" : 0,
"Humidity" : 0
}

while True:
dataDict["Temperature"] = random.randint(0, 20)
dataDict["Humidity"] = random.randint(0, 100)
client1.publish("Robot/Data", json.dumps(dataDict, indent= 4))
print("Published " + json.dumps(dataDict) + " to topic Robot/Data")
time.sleep(5)

Loading…
Cancel
Save