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.

mqtt_subscriber.py 586B

1234567891011121314151617181920212223242526
  1. import paho.mqtt.client as mqtt
  2. import time
  3. from software.backend.defines import Topics
  4. from software.backend.defines import MQTT_BROKER_GLOBAL
  5. def on_message(client, userdata, message):
  6. print("received message: ", str(message.payload.decode("utf-8")))
  7. def on_connect(client, userdata, flags, rc):
  8. if rc == 0:
  9. print("Connected")
  10. else:
  11. print("Connection failed")
  12. mqttBroker = ""
  13. client = mqtt.Client()
  14. client.connect(MQTT_BROKER_GLOBAL, 1883)
  15. client.on_message = on_message
  16. client.subscribe(Topics['BACKEND_ACTION_GETALLDATA'])
  17. client.loop_forever()