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.

temp_sensor.py 714B

123456789101112131415161718192021222324252627
  1. import time
  2. import paho.mqtt.publish as publish
  3. from w1thermsensor import W1ThermSensor
  4. sensors = {
  5. '0517021db9ff': 'rack_ceiling',
  6. '0517022f8eff': 'rack_back',
  7. '0416a02b0eff': 'rack_front',
  8. '051702869eff': 'rack_floor'
  9. }
  10. msgs = []
  11. while True:
  12. for sensor in W1ThermSensor.get_available_sensors():
  13. msg = {
  14. 'topic': 'sensor/office/temp/{}'.format(sensors[sensor.id]),
  15. 'payload': "{:.2f}".format(sensor.get_temperature()),
  16. 'qos': 0,
  17. 'retain': False
  18. }
  19. msgs.append(msg)
  20. print("Sensor {} has temperature {:.2f}".format(sensors[sensor.id], sensor.get_temperature()))
  21. publish.multiple(msgs, hostname="192.168.1.119", client_id="rack_temp")
  22. time.sleep(15)