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_publisher.py 760B

123456789101112131415161718192021222324252627282930313233343536
  1. import paho.mqtt.client as mqtt
  2. from software.defines import MQTT_BROKER_LOCAL
  3. from random import randrange, uniform
  4. import time
  5. import json
  6. from software.defines import Topics, PLANTDATA
  7. mqttBroker = "192.168.178.182"
  8. def on_connect(client, userdata, flags, rc):
  9. if rc == 0:
  10. print("Connected")
  11. else:
  12. print("Connection failed")
  13. client = mqtt.Client()
  14. client.on_connect = on_connect
  15. client.connect(mqttBroker)
  16. plantdata = {
  17. "AirTemperature": 20.4,
  18. "AirHumidity": 7.0,
  19. "SoilMoisture": 5.0,
  20. "Brightness": 39,
  21. "PlantID": 2,
  22. "Timestamp": "hallo",
  23. "MeasurementID": 187
  24. }
  25. print(type(PLANTDATA))
  26. while True:
  27. client.publish("TEST", json.dumps(plantdata))
  28. print(json.dumps(plantdata))
  29. time.sleep(2)