diff options
-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) |