udpate
This commit is contained in:
@@ -55,28 +55,20 @@
|
||||
<div class="row mb-3">
|
||||
|
||||
<div class="col-lg-3 col-12">
|
||||
<h3 class="mt-4">Parameters</h3>
|
||||
<h3 class="mt-4">Parameters (config)</h3>
|
||||
|
||||
<form>
|
||||
|
||||
<!--
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop" onchange="update_config('loop_activation',this.checked)">
|
||||
<label class="form-check-label" for="flex_loop">Loop activation</label>
|
||||
<div class="mb-3">
|
||||
<label for="device_name" class="form-label">Device Name</label>
|
||||
<input type="text" class="form-control" id="device_name" onchange="update_config_sqlite('deviceName', this.value)">
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop_log" onchange="update_config('loop_log', this.checked)">
|
||||
<label class="form-check-label" for="flex_loop_log">Loop Logs</label>
|
||||
<div class="mb-3">
|
||||
<label for="device_ID" class="form-label">Device ID</label>
|
||||
<input type="text" class="form-control" id="device_ID" disabled>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_start_log" onchange="update_config('boot_log', this.checked)">
|
||||
<label class="form-check-label" for="flex_start_log">Boot Logs</label>
|
||||
</div>
|
||||
-->
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_NPM_5channels" onchange="update_config('NextPM_5channels', this.checked)">
|
||||
<label class="form-check-label" for="check_NPM_5channels">
|
||||
@@ -98,15 +90,7 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="device_name" class="form-label">Device Name</label>
|
||||
<input type="text" class="form-control" id="device_name" onchange="update_config('deviceName', this.value)">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="device_ID" class="form-label">Device ID</label>
|
||||
<input type="text" class="form-control" id="device_ID" disabled>
|
||||
</div>
|
||||
|
||||
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
|
||||
</form>
|
||||
@@ -117,13 +101,6 @@
|
||||
|
||||
<h3 class="mt-4">Clock</h3>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_RTC" onchange="update_config('i2c_RTC', this.checked)">
|
||||
<label class="form-check-label" for="check_RTC">
|
||||
RTC module (DS3231)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="sys_local_time" class="form-label">System time (local)</label>
|
||||
<input type="text" class="form-control" id="sys_local_time" disabled>
|
||||
@@ -227,11 +204,6 @@ window.onload = function() {
|
||||
const checkbox_envea = document.getElementById("check_envea");
|
||||
checkbox_envea.checked = data["envea/read_value_v2.py"];
|
||||
|
||||
//get RTC check
|
||||
const checkbox_RTC = document.getElementById("check_RTC");
|
||||
checkbox_RTC.checked = data.i2c_RTC;
|
||||
|
||||
|
||||
//device name
|
||||
const device_name = document.getElementById("device_name");
|
||||
device_name.value = data.deviceName;
|
||||
@@ -300,6 +272,22 @@ window.onload = function() {
|
||||
.catch(error => console.error('Error loading config.json:', error));
|
||||
}
|
||||
|
||||
function update_config_sqlite(param, value){
|
||||
console.log("Updating sqlite ",param," : ", value);
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=update_config_sqlite¶m='+param+'&value='+value,
|
||||
dataType: 'text', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
cache: false, // Prevent AJAX from caching
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function update_config(param, value){
|
||||
console.log("Updating ",param," : ", value);
|
||||
|
||||
@@ -25,6 +25,67 @@ if ($type == "get_npm_sqlite_data") {
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == "update_config_sqlite") {
|
||||
echo "updating....";
|
||||
$param = $_GET['param'] ?? null;
|
||||
$value = $_GET['value'] ?? null;
|
||||
|
||||
if ($param === null || $value === null) {
|
||||
echo json_encode(["error" => "Missing parameter or value"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$database_path = "/var/www/nebuleair_pro_4g/sqlite/sensors.db";
|
||||
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 type FROM config_table WHERE key = :param");
|
||||
$checkStmt->bindParam(':param', $param);
|
||||
$checkStmt->execute();
|
||||
$result = $checkStmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result) {
|
||||
// Parameter exists, determine type and update
|
||||
$type = $result['type'];
|
||||
|
||||
// Convert value according to type if needed
|
||||
$convertedValue = $value;
|
||||
if ($type == "bool") {
|
||||
// Convert various boolean representations to 0/1
|
||||
$convertedValue = (filter_var($value, FILTER_VALIDATE_BOOLEAN)) ? "1" : "0";
|
||||
} elseif ($type == "int") {
|
||||
$convertedValue = (string)intval($value);
|
||||
} elseif ($type == "float") {
|
||||
$convertedValue = (string)floatval($value);
|
||||
}
|
||||
|
||||
// Update the value
|
||||
$updateStmt = $db->prepare("UPDATE config_table SET value = :value WHERE key = :param");
|
||||
$updateStmt->bindParam(':value', $convertedValue);
|
||||
$updateStmt->bindParam(':param', $param);
|
||||
$updateStmt->execute();
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Configuration updated successfully",
|
||||
"param" => $param,
|
||||
"value" => $convertedValue,
|
||||
"type" => $type
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
"error" => "Parameter not found in configuration",
|
||||
"param" => $param
|
||||
]);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(["error" => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($type == "update_config") {
|
||||
echo "updating....";
|
||||
$param=$_GET['param'];
|
||||
@@ -269,7 +330,7 @@ if ($type == "sara_connectNetwork") {
|
||||
$timeout=$_GET['timeout'];
|
||||
$networkID=$_GET['networkID'];
|
||||
|
||||
echo "updating SARA_R4_networkID in config file";
|
||||
//echo "updating SARA_R4_networkID in config file";
|
||||
// Convert `networkID` to an integer (or float if needed)
|
||||
$networkID = is_numeric($networkID) ? (strpos($networkID, '.') !== false ? (float)$networkID : (int)$networkID) : 0;
|
||||
#save to config.json
|
||||
@@ -296,10 +357,10 @@ if ($type == "sara_connectNetwork") {
|
||||
die("Error: Could not write to JSON file.");
|
||||
}
|
||||
|
||||
echo "SARA_R4_networkID updated successfully.";
|
||||
//echo "SARA_R4_networkID updated successfully.";
|
||||
|
||||
|
||||
echo "connecting to network... please wait...";
|
||||
//echo "connecting to network... please wait...";
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_connectNetwork.py ' . $port . ' ' . $networkID . ' ' . $timeout;
|
||||
$output = shell_exec($command);
|
||||
echo $output;
|
||||
|
||||
Reference in New Issue
Block a user