diff --git a/iam-lib/airsensor/airsensor.c b/iam-lib/airsensor/airsensor.c index 1d3c8b4d124529112ded789ac251f92369c4cf2a..637845cbc119475da0cd31994ffa2904f19ea48d 100755 --- a/iam-lib/airsensor/airsensor.c +++ b/iam-lib/airsensor/airsensor.c @@ -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); } diff --git a/temp.py b/temp.py index 19208442b236251e7090d78162177b2baeba9118..0a255f65813bb3e5ee6c84cd26e5ced6f6c5681b 100755 --- a/temp.py +++ b/temp.py @@ -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)