80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
'''
|
|
____ ___ _ _ _
|
|
/ ___| / _ \| | (_) |_ ___
|
|
\___ \| | | | | | | __/ _ \
|
|
___) | |_| | |___| | || __/
|
|
|____/ \__\_\_____|_|\__\___|
|
|
|
|
Script to set the config
|
|
/usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/set_config.py
|
|
|
|
in case of readonly error:
|
|
sudo chmod 777 /var/www/nebuleair_pro_4g/sqlite/sensors.db
|
|
'''
|
|
|
|
import sqlite3
|
|
|
|
# Connect to (or create if not existent) the database
|
|
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
|
|
cursor = conn.cursor()
|
|
|
|
print(f"Connected to database")
|
|
|
|
# Clear existing data (if any)
|
|
cursor.execute("DELETE FROM config_table")
|
|
cursor.execute("DELETE FROM envea_sondes_table")
|
|
print("Existing data cleared")
|
|
|
|
|
|
# Insert general configurations
|
|
config_entries = [
|
|
("modem_config_mode", "0", "bool"),
|
|
("deviceID", "XXXX", "str"),
|
|
("latitude_raw", "0", "int"),
|
|
("longitude_raw", "0", "int"),
|
|
("latitude_precision", "0", "int"),
|
|
("longitude_precision", "0", "int"),
|
|
("deviceName", "NebuleAir-proXXX", "str"),
|
|
("SaraR4_baudrate", "115200", "int"),
|
|
("NPM_solo_port", "/dev/ttyAMA5", "str"),
|
|
("sshTunnel_port", "59228", "int"),
|
|
("SARA_R4_general_status", "connected", "str"),
|
|
("SARA_R4_SIM_status", "connected", "str"),
|
|
("SARA_R4_network_status", "connected", "str"),
|
|
("SARA_R4_neworkID", "20810", "int"),
|
|
("WIFI_status", "connected", "str"),
|
|
("send_uSpot", "0", "bool"),
|
|
("npm_5channel", "0", "bool"),
|
|
("envea", "0", "bool"),
|
|
("windMeter", "0", "bool"),
|
|
("BME280", "0", "bool"),
|
|
("MPPT", "0", "bool"),
|
|
("modem_version", "XXX", "str")
|
|
]
|
|
|
|
for key, value, value_type in config_entries:
|
|
cursor.execute(
|
|
"INSERT INTO config_table (key, value, type) VALUES (?, ?, ?)",
|
|
(key, value, value_type)
|
|
)
|
|
|
|
# Insert envea sondes
|
|
envea_sondes = [
|
|
(False, "ttyAMA4", "h2s", 4),
|
|
(False, "ttyAMA3", "no2", 1),
|
|
(False, "ttyAMA2", "o3", 1)
|
|
]
|
|
|
|
for connected, port, name, coefficient in envea_sondes:
|
|
cursor.execute(
|
|
"INSERT INTO envea_sondes_table (connected, port, name, coefficient) VALUES (?, ?, ?, ?)",
|
|
(1 if connected else 0, port, name, coefficient)
|
|
)
|
|
|
|
|
|
# Commit and close the connection
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
print("Database updated successfully!")
|