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_subscribe.py 592B

123456789101112131415161718192021
  1. import paho.mqtt.client as mqtt
  2. def on_message_temp(client, userdata, message):
  3. print("Received temp message: ", str(message.payload.decode("utf-8")))
  4. def on_message_hum(client, userdata, message):
  5. print("Received hum message: ", str(message.payload.decode("utf-8")))
  6. mqttBroker = "mqtt.eclipseprojects.io"
  7. client = mqtt.Client("Smartphone_temp")
  8. client.message_callback_add("TEMPERATURE", on_message_temp)
  9. client.message_callback_add("HUMIDITY", on_message_hum)
  10. client.connect(mqttBroker)
  11. client.subscribe("TEMPERATURE")
  12. client.subscribe("HUMIDITY")
  13. client.loop_forever()