-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgather.py
More file actions
21 lines (18 loc) · 733 Bytes
/
gather.py
File metadata and controls
21 lines (18 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python
import Adafruit_DHT
import time
import socket
import os
sensor = Adafruit_DHT.DHT22
pin = 4
tid = time.time()
node = socket.getfqdn()
location = "somewhere"
sensorName = "am2302"
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
with open('am2302sensor', 'w+') as f:
f.write('node_sensor_temp{{node="{0}",location="{2}",sensor="{3}"}} {1:0.1f}\n'.format(node, temperature, location, sensorName))
f.write('node_sensor_humidity{{node="{0}",location="{2}",sensor="{3}"}} {1:0.1f}\n'.format(node, humidity, location, sensorName))
f.write('node_sensor_updated_timestamp{{node="{0}"}} {1:.0f}\n'.format(node, tid))
f.close()