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 777B

1234567891011121314151617181920212223242526272829303132333435
  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 MQTT callbacks
  8. def send_data_json(client, userdata, message):
  9. strIn = str(message.payload.decode("UTF-8"))
  10. dataDict = json.loads(strIn)
  11. print("Received data: ", json.dumps(dataDict))
  12. def drive_plant_1(clients, userdata, message):
  13. print("Driving to plant 1")
  14. #endregion
  15. mqttBroker = "mqtt.eclipseprojects.io"
  16. client = mqtt.Client("Smartphone_temp")
  17. dataDict = {}
  18. client.message_callback_add("Robot/Data", send_data_json)
  19. client.message_callback_add("Robot/Plant/1", drive_plant_1)
  20. client.connect(mqttBroker)
  21. client.subscribe("Robot/Data")
  22. client.subscribe("Robot/Plant/1")
  23. client.loop_forever()