-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
31 lines (22 loc) · 865 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from datetime import datetime
from signal import pause
from gpiozero import DigitalInputDevice
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
def write_consumption():
client = InfluxDBClient(url="http://influxdb:8086", org="sch8fa", token="influx-auth-token")
write_api = client.write_api(write_options=SYNCHRONOUS)
p = Point("gas").field("consumption", 0.01)
write_api.write(bucket="sensors", record=p)
client.close()
# noinspection PyUnusedLocal
def next_consumption(pin):
print("Consumption at {0}".format(datetime.now()))
write_consumption()
def listen_to_input_events():
sensor = DigitalInputDevice("GPIO4", pull_up=True)
sensor.when_activated = next_consumption
if __name__ == '__main__':
listen_to_input_events()
print("Waiting...")
pause()