update
This commit is contained in:
@@ -60,22 +60,22 @@
|
||||
<form>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop" onchange="update_config(this.checked)">
|
||||
<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>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop_log">
|
||||
<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>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_start_log">
|
||||
<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_bme280s">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_bme280" onchange="update_config('i2c_BME', this.checked)">
|
||||
<label class="form-check-label" for="check_bme280">
|
||||
Sonde temp/hum (BME280)
|
||||
</label>
|
||||
@@ -83,7 +83,7 @@
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="device_name" class="form-label">Device Name</label>
|
||||
<input type="text" class="form-control" id="device_name">
|
||||
<input type="text" class="form-control" id="device_name" onchange="update_config('deviceName', this.value)">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@@ -91,7 +91,7 @@
|
||||
<input type="text" class="form-control" id="device_ID" disabled>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -153,7 +153,7 @@ window.onload = function() {
|
||||
});
|
||||
|
||||
//get BME check
|
||||
const checkbox = document.getElementById("check_bme280s");
|
||||
const checkbox = document.getElementById("check_bme280");
|
||||
checkbox.checked = data.i2c_BME;
|
||||
|
||||
//loop activation
|
||||
@@ -196,10 +196,10 @@ window.onload = function() {
|
||||
}
|
||||
|
||||
|
||||
function update_config(isChecked){
|
||||
console.log("Updated flex_loop:", isChecked);
|
||||
function update_config(param, value){
|
||||
console.log("Updating ",param," : ", value);
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=update_config',
|
||||
url: 'launcher.php?type=update_config¶m='+param+'&value='+value,
|
||||
dataType: 'text', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
|
||||
@@ -3,9 +3,19 @@ $type=$_GET['type'];
|
||||
|
||||
if ($type == "update_config") {
|
||||
echo "updating....";
|
||||
$param=$_GET['param'];
|
||||
$value=$_GET['value'];
|
||||
$configFile = '../config.json';
|
||||
// Convert value to boolean, integer, or string
|
||||
if ($value === "true") {
|
||||
$value = true; // Convert "true" string to boolean true
|
||||
} elseif ($value === "false") {
|
||||
$value = false; // Convert "false" string to boolean false
|
||||
} elseif (is_numeric($value)) {
|
||||
$value = $value + 0; // Convert numeric strings to int or float
|
||||
}
|
||||
$configData = json_decode(file_get_contents($configFile), true);
|
||||
$configData['loop_activation'] = true;
|
||||
$configData[$param] = $value;
|
||||
file_put_contents($configFile, json_encode($configData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
echo "Config updated!";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user