updates
This commit is contained in:
@@ -79,49 +79,49 @@
|
|||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_NPM" onchange="update_config_scripts_sqlite('NPM/get_data_modbus_v3.py', this.checked)">
|
<input class="form-check-input" type="checkbox" value="" id="check_NPM" onchange="update_config_scripts_sqlite('NPM/get_data_modbus_v3.py', this.checked)">
|
||||||
<label class="form-check-label" for="check_NPM">
|
<label class="form-check-label" for="check_NPM">
|
||||||
Next PM
|
Send Next PM data
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_NPM_5channels" onchange="update_config_sqlite('npm_5channel', this.checked)">
|
<input class="form-check-input" type="checkbox" value="" id="check_NPM_5channels" onchange="update_config_sqlite('npm_5channel', this.checked)">
|
||||||
<label class="form-check-label" for="check_NPM_5channels">
|
<label class="form-check-label" for="check_NPM_5channels">
|
||||||
Next PM send 5 channels (no script)
|
Send Next PM 5 channels data
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_bme280" onchange="update_config_scripts_sqlite('BME280/get_data_v2.py', this.checked)">
|
<input class="form-check-input" type="checkbox" value="" id="check_bme280" onchange="update_config_sqlite('BME280', this.checked)">
|
||||||
<label class="form-check-label" for="check_bme280">
|
<label class="form-check-label" for="check_bme280">
|
||||||
Sonde temp/hum (BME280)
|
Send temp/hum data (BME280)
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_envea" onchange="update_config_scripts_sqlite('envea/read_value_v2.py', this.checked)">
|
<input class="form-check-input" type="checkbox" value="" id="check_envea" onchange="update_config_sqlite('envea/read_value_v2.py', this.checked)">
|
||||||
<label class="form-check-label" for="check_envea">
|
<label class="form-check-label" for="check_envea">
|
||||||
Sonde Envea
|
Send Envea sensor data
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_solarBattery" onchange="update_config_scripts_sqlite('MPPT/read.py', this.checked)">
|
<input class="form-check-input" type="checkbox" value="" id="check_solarBattery" onchange="update_config_sqlite('MPPT', this.checked)">
|
||||||
<label class="form-check-label" for="check_solarBattery">
|
<label class="form-check-label" for="check_solarBattery">
|
||||||
Solar / Battery MPPT
|
Send Solar / Battery MPPT data
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_WindMeter" onchange="update_config_sqlite('windMeter', this.checked)">
|
<input class="form-check-input" type="checkbox" value="" id="check_WindMeter" onchange="update_config_sqlite('windMeter', this.checked)">
|
||||||
<label class="form-check-label" for="check_WindMeter">
|
<label class="form-check-label" for="check_WindMeter">
|
||||||
Wind Meter (no script -> systemd service)
|
Senb Wind Meter data
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check mb-3">
|
<div class="form-check mb-3">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="check_uSpot" onchange="update_config_sqlite('send_uSpot', this.checked)" disabled>
|
<input class="form-check-input" type="checkbox" value="" id="check_uSpot" onchange="update_config_sqlite('send_uSpot', this.checked)" disabled>
|
||||||
<label class="form-check-label" for="check_uSpot">
|
<label class="form-check-label" for="check_uSpot">
|
||||||
uSpot
|
Send to uSpot
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -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 = `
|
|
||||||
<strong>Success!</strong><br>
|
|
||||||
Parameter: ${response.script_path || param}<br>
|
|
||||||
Value: ${response.enabled !== undefined ? response.enabled : value}<br>
|
|
||||||
${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 = `
|
|
||||||
<strong>Error!</strong><br>
|
|
||||||
${response.error || 'Unknown error'}<br>
|
|
||||||
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){
|
function update_config(param, value){
|
||||||
console.log("Updating ",param," : ", value);
|
console.log("Updating ",param," : ", value);
|
||||||
|
|||||||
@@ -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
|
//UPDATING the envea_sondes_table table from SQLite DB
|
||||||
if ($type == "update_sonde") {
|
if ($type == "update_sonde") {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<div class="col-lg-6 col-12">
|
<div class="col-lg-6 col-12">
|
||||||
<div class="card" style="height: 80vh;">
|
<div class="card" style="height: 80vh;">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
Master logs
|
Sara logs
|
||||||
<button type="submit" class="btn btn-secondary btn-sm" id="refresh-master-log">Refresh</button>
|
<button type="submit" class="btn btn-secondary btn-sm" id="refresh-master-log">Refresh</button>
|
||||||
<button type="submit" class="btn btn-secondary btn-sm" onclick="clear_loopLogs()">Clear</button>
|
<button type="submit" class="btn btn-secondary btn-sm" onclick="clear_loopLogs()">Clear</button>
|
||||||
|
|
||||||
|
|||||||
@@ -200,30 +200,6 @@ def load_config_sqlite():
|
|||||||
print(f"Error loading config from SQLite: {e}")
|
print(f"Error loading config from SQLite: {e}")
|
||||||
return {}
|
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
|
#Load config
|
||||||
config = load_config_sqlite()
|
config = load_config_sqlite()
|
||||||
#config
|
#config
|
||||||
@@ -234,16 +210,13 @@ device_latitude_raw = config.get('latitude_raw', 0)
|
|||||||
device_longitude_raw = config.get('longitude_raw', 0)
|
device_longitude_raw = config.get('longitude_raw', 0)
|
||||||
modem_version=config.get('modem_version', "")
|
modem_version=config.get('modem_version', "")
|
||||||
Sara_baudrate = config.get('SaraR4_baudrate', 115200)
|
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))
|
selected_networkID = int(config.get('SARA_R4_neworkID', 0))
|
||||||
send_uSpot = config.get('send_uSpot', False) #envoi sur MicroSpot ()
|
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)
|
wind_meter= config.get('windMeter', False)
|
||||||
|
bme_280_config = config.get('BME280', False)
|
||||||
#config_scripts
|
mppt_charger= config.get('MPPT', False)
|
||||||
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)
|
|
||||||
|
|
||||||
#update device id in the payload json
|
#update device id in the payload json
|
||||||
payload_json["nebuleairid"] = device_id
|
payload_json["nebuleairid"] = device_id
|
||||||
|
|||||||
@@ -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
|
#creates a config table for envea sondes
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS envea_sondes_table (
|
CREATE TABLE IF NOT EXISTS envea_sondes_table (
|
||||||
@@ -46,7 +38,6 @@ CREATE TABLE IF NOT EXISTS envea_sondes_table (
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
# Create a table timer
|
# Create a table timer
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS timestamp_table (
|
CREATE TABLE IF NOT EXISTS timestamp_table (
|
||||||
|
|||||||
@@ -22,35 +22,14 @@ print(f"Connected to database")
|
|||||||
|
|
||||||
# Clear existing data (if any)
|
# Clear existing data (if any)
|
||||||
cursor.execute("DELETE FROM config_table")
|
cursor.execute("DELETE FROM config_table")
|
||||||
cursor.execute("DELETE FROM config_scripts_table")
|
|
||||||
cursor.execute("DELETE FROM envea_sondes_table")
|
cursor.execute("DELETE FROM envea_sondes_table")
|
||||||
print("Existing data cleared")
|
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
|
# Insert general configurations
|
||||||
config_entries = [
|
config_entries = [
|
||||||
("modem_config_mode", "0", "bool"),
|
("modem_config_mode", "0", "bool"),
|
||||||
("deviceID", "XXXX", "str"),
|
("deviceID", "XXXX", "str"),
|
||||||
("npm_5channel", "0", "bool"),
|
|
||||||
("latitude_raw", "0", "int"),
|
("latitude_raw", "0", "int"),
|
||||||
("longitude_raw", "0", "int"),
|
("longitude_raw", "0", "int"),
|
||||||
("latitude_precision", "0", "int"),
|
("latitude_precision", "0", "int"),
|
||||||
@@ -65,7 +44,11 @@ config_entries = [
|
|||||||
("SARA_R4_neworkID", "20810", "int"),
|
("SARA_R4_neworkID", "20810", "int"),
|
||||||
("WIFI_status", "connected", "str"),
|
("WIFI_status", "connected", "str"),
|
||||||
("send_uSpot", "0", "bool"),
|
("send_uSpot", "0", "bool"),
|
||||||
|
("npm_5channel", "0", "bool"),
|
||||||
|
("envea", "0", "bool"),
|
||||||
("windMeter", "0", "bool"),
|
("windMeter", "0", "bool"),
|
||||||
|
("BME280", "0", "bool"),
|
||||||
|
("MPPT", "0", "bool"),
|
||||||
("modem_version", "XXX", "str")
|
("modem_version", "XXX", "str")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user