Skip to content
Snippets Groups Projects
Verified Commit 6fa41429 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch 'master' of edugit.org:hansegucker/sensor-class

parents 77e67cea 3490c8d3
Branches
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,15 +76,28 @@ 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)
......@@ -85,6 +107,7 @@ if __name__ == "__main__":
# Outdoor temp
r = requests.get("http://api.openweathermap.org/data/2.5/weather?q=Luebeck,de&appid=890cda16c75a675e1fce4eed7a8d896f")
data = r.json()
temp_out = data["main"]["temp"] - 273.15
......@@ -162,6 +185,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.
Please register or to comment