udpate
This commit is contained in:
@@ -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