|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import paho.mqtt.client as mqtt
- import json
- from raspySensors import RaspySensors
-
- #region global Varaibles
- sensors = RaspySensors()
-
-
- #endregion
-
- #region
-
- def measureSendData():
- '''Measure Data via sensor class and send via MQTT'''
- sensorData = sensors.readSensors()
- client.publish("Robot/Data", json.dumps(sensorData, indent=4))
-
- #endregion
-
- #region MQTT callbacks
- def send_data_json(client, userdata, message):
- strIn = str(message.payload.decode("UTF-8"))
- dataDict = json.loads(strIn)
- print("Received data: ", json.dumps(dataDict))
-
- #Function for all Plants or one which changes according to request
- def drive_plant_1(clients, userdata, message):
- #TODO Start drive forward
- print("Driving to plant 1")
- measureSendData()
- #TODO Start Drive Back Function
- print("Driving back to start position")
-
-
-
- #endregion
-
-
- mqttBroker = "mqtt.eclipseprojects.io"
- client = mqtt.Client("Smartphone_temp")
-
- dataDict = {}
-
- client.message_callback_add("Robot/Data", send_data_json)
- client.message_callback_add("Robot/Plant/1", drive_plant_1)
-
- client.connect(mqttBroker)
- client.subscribe("Robot/Data")
- client.subscribe("Robot/Plant/1")
-
- client.loop_forever()
|