repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mainProg.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import paho.mqtt.client as mqtt
  2. import json
  3. from raspySensors import RaspySensors
  4. #region global Varaibles
  5. sensors = RaspySensors()
  6. #endregion
  7. #region
  8. def measureSendData():
  9. '''Measure Data via sensor class and send via MQTT'''
  10. sensorData = sensors.readSensors()
  11. client.publish("Robot/Data", json.dumps(sensorData, indent=4))
  12. #endregion
  13. #region MQTT callbacks
  14. def send_data_json(client, userdata, message):
  15. strIn = str(message.payload.decode("UTF-8"))
  16. dataDict = json.loads(strIn)
  17. print("Received data: ", json.dumps(dataDict))
  18. #Function for all Plants or one which changes according to request
  19. def drive_plant_1(clients, userdata, message):
  20. #TODO Start drive forward
  21. print("Driving to plant 1")
  22. measureSendData()
  23. #TODO Start Drive Back Function
  24. print("Driving back to start position")
  25. #endregion
  26. mqttBroker = "mqtt.eclipseprojects.io"
  27. client = mqtt.Client("Smartphone_temp")
  28. dataDict = {}
  29. client.message_callback_add("Robot/Data", send_data_json)
  30. client.message_callback_add("Robot/Plant/1", drive_plant_1)
  31. client.connect(mqttBroker)
  32. client.subscribe("Robot/Data")
  33. client.subscribe("Robot/Plant/1")
  34. client.loop_forever()