diff --git a/html/admin.html b/html/admin.html index ccece87..eeec61f 100755 --- a/html/admin.html +++ b/html/admin.html @@ -79,49 +79,49 @@
- +
- +
- +
@@ -506,62 +506,6 @@ function update_config_sqlite(param, value){ }); } -function update_config_scripts_sqlite(param, value) { - console.log("Updating scripts sqlite ", param, " : ", value); - const toastLiveExample = document.getElementById('liveToast') - const toastBody = toastLiveExample.querySelector('.toast-body'); - - $.ajax({ - url: 'launcher.php?type=update_config_scripts_sqlite¶m=' + param + '&value=' + value, - dataType: 'json', - method: 'GET', - cache: false, - success: function(response) { - console.log(response); - // Format the response nicely - let formattedMessage = ''; - - if (response.success) { - // Success message - toastLiveExample.classList.remove('text-bg-danger'); - toastLiveExample.classList.add('text-bg-success'); - - formattedMessage = ` - Success!
- Parameter: ${response.script_path || param}
- Value: ${response.enabled !== undefined ? response.enabled : value}
- ${response.message || ''} - `; - - if (response.script_path == "envea/read_value_v2.py") { - console.log("envea sondes activated"); - add_sondeEnveaContainer(); - - } - } else { - // Error message - toastLiveExample.classList.remove('text-bg-success'); - toastLiveExample.classList.add('text-bg-danger'); - - formattedMessage = ` - Error!
- ${response.error || 'Unknown error'}
- Parameter: ${response.script_path || param} - `; - } - - // Update the toast body with formatted content - toastBody.innerHTML = formattedMessage; - // Show the toast - const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample) - toastBootstrap.show() - }, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); - } - }); -} - function update_config(param, value){ console.log("Updating ",param," : ", value); diff --git a/html/launcher.php b/html/launcher.php index 8f21845..615c565 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -218,52 +218,6 @@ if ($type == "update_config_sqlite") { } } -//UPDATING the config_scripts table from SQLite DB -if ($type == "update_config_scripts_sqlite") { - $script_path = $_GET['param'] ?? null; - $enabled = $_GET['value'] ?? null; - - if ($script_path === null || $enabled === null) { - echo json_encode(["error" => "Missing parameter or value"]); - exit; - } - - try { - $db = new PDO("sqlite:$database_path"); - $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - // First, check if parameter exists and get its type - $checkStmt = $db->prepare("SELECT enabled FROM config_scripts_table WHERE script_path = :script_path"); - $checkStmt->bindParam(':script_path', $script_path); - $checkStmt->execute(); - $result = $checkStmt->fetch(PDO::FETCH_ASSOC); - - if ($result) { - // Convert enabled value to 0 or 1 - $enabledValue = (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) ? 1 : 0; - - // Update the enabled status - $updateStmt = $db->prepare("UPDATE config_scripts_table SET enabled = :enabled WHERE script_path = :script_path"); - $updateStmt->bindParam(':enabled', $enabledValue, PDO::PARAM_INT); - $updateStmt->bindParam(':script_path', $script_path); - $updateStmt->execute(); - - echo json_encode([ - "success" => true, - "message" => "Script configuration updated successfully", - "script_path" => $script_path, - "enabled" => (bool)$enabledValue - ], JSON_UNESCAPED_SLASHES); // Prevent escaping forward slashes - } else { - echo json_encode([ - "error" => "Script path not found in configuration", - "script_path" => $script_path - ], JSON_UNESCAPED_SLASHES); // Prevent escaping forward slashes - } - } catch (PDOException $e) { - echo json_encode(["error" => $e->getMessage()]); - } -} //UPDATING the envea_sondes_table table from SQLite DB if ($type == "update_sonde") { diff --git a/html/logs.html b/html/logs.html index 3f2ad22..4412773 100755 --- a/html/logs.html +++ b/html/logs.html @@ -56,7 +56,7 @@
- Master logs + Sara logs diff --git a/loop/SARA_send_data_v2.py b/loop/SARA_send_data_v2.py index 09c1c9e..d1916ad 100755 --- a/loop/SARA_send_data_v2.py +++ b/loop/SARA_send_data_v2.py @@ -200,30 +200,6 @@ def load_config_sqlite(): print(f"Error loading config from SQLite: {e}") return {} -def load_config_scripts_sqlite(): - """ - Load script configuration data from SQLite config_scripts_table - - Returns: - dict: Script paths as keys and enabled status as boolean values - """ - try: - # Query the config_scripts_table - cursor.execute("SELECT script_path, enabled FROM config_scripts_table") - rows = cursor.fetchall() - - # Create config dictionary with script paths as keys and enabled status as boolean values - scripts_config = {} - for script_path, enabled in rows: - # Convert integer enabled value (0/1) to boolean - scripts_config[script_path] = bool(enabled) - - return scripts_config - - except Exception as e: - print(f"Error loading scripts config from SQLite: {e}") - return {} - #Load config config = load_config_sqlite() #config @@ -234,16 +210,13 @@ device_latitude_raw = config.get('latitude_raw', 0) device_longitude_raw = config.get('longitude_raw', 0) modem_version=config.get('modem_version', "") Sara_baudrate = config.get('SaraR4_baudrate', 115200) -npm_5channel = config.get('npm_5channel', False) #5 canaux du NPM selected_networkID = int(config.get('SARA_R4_neworkID', 0)) send_uSpot = config.get('send_uSpot', False) #envoi sur MicroSpot () +npm_5channel = config.get('npm_5channel', False) #5 canaux du NPM +envea_cairsens= config.get('envea', False) wind_meter= config.get('windMeter', False) - -#config_scripts -config_scripts = load_config_scripts_sqlite() -bme_280_config = config_scripts.get('BME280/get_data_v2.py', False) -envea_cairsens= config_scripts.get('envea/read_value_v2.py', False) -mppt_charger= config_scripts.get('MPPT/read.py', False) +bme_280_config = config.get('BME280', False) +mppt_charger= config.get('MPPT', False) #update device id in the payload json payload_json["nebuleairid"] = device_id diff --git a/master.py b/old/master.py similarity index 100% rename from master.py rename to old/master.py diff --git a/sqlite/create_db.py b/sqlite/create_db.py index 0b430ec..b10e2ac 100755 --- a/sqlite/create_db.py +++ b/sqlite/create_db.py @@ -27,14 +27,6 @@ CREATE TABLE IF NOT EXISTS config_table ( ) """) -#creates a config_scripts table -cursor.execute(''' -CREATE TABLE IF NOT EXISTS config_scripts_table ( - script_path TEXT PRIMARY KEY, - enabled INTEGER NOT NULL -) -''') - #creates a config table for envea sondes cursor.execute(""" CREATE TABLE IF NOT EXISTS envea_sondes_table ( @@ -46,7 +38,6 @@ CREATE TABLE IF NOT EXISTS envea_sondes_table ( ) """) - # Create a table timer cursor.execute(""" CREATE TABLE IF NOT EXISTS timestamp_table ( diff --git a/sqlite/set_config.py b/sqlite/set_config.py index 68fb4c9..de6f940 100644 --- a/sqlite/set_config.py +++ b/sqlite/set_config.py @@ -22,35 +22,14 @@ print(f"Connected to database") # Clear existing data (if any) cursor.execute("DELETE FROM config_table") -cursor.execute("DELETE FROM config_scripts_table") cursor.execute("DELETE FROM envea_sondes_table") print("Existing data cleared") -#add values - -# Insert script configurations -script_configs = [ - ("NPM/get_data_modbus_v3.py", True), - ("loop/SARA_send_data_v2.py", True), - ("RTC/save_to_db.py", True), - ("BME280/get_data_v2.py", True), - ("envea/read_value_v2.py", False), - ("MPPT/read.py", False), - ("windMeter/read.py", False), - ("sqlite/flush_old_data.py", True) -] - -for script_path, enabled in script_configs: - cursor.execute( - "INSERT INTO config_scripts_table (script_path, enabled) VALUES (?, ?)", - (script_path, 1 if enabled else 0) - ) # Insert general configurations config_entries = [ ("modem_config_mode", "0", "bool"), ("deviceID", "XXXX", "str"), - ("npm_5channel", "0", "bool"), ("latitude_raw", "0", "int"), ("longitude_raw", "0", "int"), ("latitude_precision", "0", "int"), @@ -65,7 +44,11 @@ config_entries = [ ("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") ]