Browse Source

first commit

Thomas Jensen 9 months ago
commit
14c2858f04
1 changed files with 27 additions and 0 deletions
  1. 27
    0
      temp_sensor.py

+ 27
- 0
temp_sensor.py View File

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

Loading…
Cancel
Save