Skip to content
Snippets Groups Projects
Commit 3490c8d3 authored by Jonathan Weth's avatar Jonathan Weth
Browse files

Include iAM in temp.py and support piconfig.jonathanweth.de

parent 59d2743b
No related branches found
No related tags found
No related merge requests found
......@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
usb_find_busses();
usb_find_devices();
dev = find_device(vendor, product);
sleep(1);
//sleep(1);
if (dev == NULL)
if (debug == 1)
......@@ -269,7 +269,7 @@ int main(int argc, char *argv[])
exit(0);
// Wait for next request for data
sleep(10);
sleep(3);
}
......
......@@ -8,19 +8,28 @@ import requests
from gpiozero import Button
from influxdb import InfluxDBClient
from RPLCD.i2c import CharLCD
from iam import AirSensor
import threading
# Init LCD
lcd = CharLCD('PCF8574', 0x27)
lcd.write_string("Starting ...")
# Init InfluxDB
client = InfluxDBClient('influx.jonathanweth.de', 80, 'root', 'root', 'room_sensors')
client.create_database('room_sensors')
# Set Influx tags
tags = {
"room": "012",
"scenario": "ventilate-20"
}
class iAMThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.running = True
self.value = None
def run(self):
while self.running:
self.value = AirSensor.get_value()
def temp_it():
while True:
......@@ -67,20 +76,31 @@ def temp_it():
if __name__ == "__main__":
# Read config
print("Read config ...")
lcd.clear()
lcd.write_string("Read config ...")
r = requests.get("https://piconfig.jonathanweth.de/config.json", verify=False)
# Set Influx tags
tags = r.json()
print(tags)
windows = [20, 26]
buttons = {}
iam_thread = iAMThread()
iam_thread.start()
for window in windows:
print(f"Window {window}")
buttons[window] = Button(window)
for temps, temp_count in temp_it():
json_body = []
# Clear LCD
lcd.clear()
lcd.cursor_pos = (0, 0)
json_body = []
########
# TEMP #
......@@ -147,6 +167,24 @@ if __name__ == "__main__":
# Log window data
print(str(window_data))
# Air sensor
print("Read iAM ...")
iam_value = iam_thread.value
print(f"iAM: {iam_value}")
if iam_value:
json_body.append({
"measurement": "iam",
"tags": tags,
"fields": {
"value": iam_value
}
})
lcd.write_string(f"{iam_value} ")
print("\n")
# Wait for next data
# time.sleep(7.675)
client.write_points(json_body)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment