diff options
author | pks <pks@pks.rocks> | 2021-05-11 10:28:37 +0200 |
---|---|---|
committer | pks <pks@pks.rocks> | 2021-05-11 10:28:37 +0200 |
commit | 49b5ca867d4e75d53078d872f2759b3d1beac2a4 (patch) | |
tree | a85509d3e9a5eac457341c923ec35819e363c541 | |
parent | ef85e805eac28c54c5c342b7d7a713500b286c16 (diff) |
fix
-rwxr-xr-x | weather-logger-receiver | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/weather-logger-receiver b/weather-logger-receiver index f0db5a4..38a5c81 100755 --- a/weather-logger-receiver +++ b/weather-logger-receiver @@ -6,6 +6,7 @@ import signal import sqlite3 import sys import time +import traceback import yaml from RFXtrx import PySerialTransport @@ -38,13 +39,12 @@ def setup_serial(device_path): def add_data_to_db(data, handle, db_connection): db_cursor = db_connection.cursor() columns = ["timestamp", "handle", "temperature"] - values = [int(time.time()), handle, data.values['Temperature']] + values = [str(int(time.time())), f"'{handle}'", str(data.values["Temperature"])] if "Humidity" in data.values: columns.append("humidity") - values.append(data.values['Humidity']) - db_cursor.execute(f"INSERT INTO weather \ - ({','.join(columns)}) \ - VALUES ({','.join(values)})") + values.append(str(data.values["Humidity"])) + query = f"INSERT INTO weather ({','.join(columns)}) VALUES ({','.join(values)})" + db_cursor.execute(query) db_connection.commit() @@ -141,5 +141,6 @@ if __name__ == "__main__": loop(known_devices, serial_connection, db_connection, logger) except Exception as e: logger.error(f"Exception: {e}") + traceback.print_exc() finally: shutdown(config, serial_connection, db_connection, logger) |