add cpu power mode
This commit is contained in:
101
html/admin.html
101
html/admin.html
@@ -128,6 +128,20 @@
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="cpu_power_mode" class="form-label">CPU Power Mode</label>
|
||||
<select class="form-select" id="cpu_power_mode" onchange="set_cpu_power_mode(this.value)">
|
||||
<option value="normal">Normal (600-1500MHz dynamic)</option>
|
||||
<option value="powersave">Power Saving (600MHz fixed)</option>
|
||||
</select>
|
||||
<small class="form-text text-muted d-block">
|
||||
<span id="cpu_mode_status" class="text-success"></span>
|
||||
</small>
|
||||
<small class="form-text text-muted d-block">
|
||||
Power saving mode reduces CPU performance by ~30-40% but saves power.
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span class="fw-bold">Protected Settings</span>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="toggleProtectedSettings()" id="unlockBtn">
|
||||
@@ -423,6 +437,16 @@ window.onload = function() {
|
||||
checkbox_aircarto.checked = response["send_aircarto"];
|
||||
checkbox_miotiq.checked = response["send_miotiq"];
|
||||
|
||||
// Set CPU power mode
|
||||
const cpu_power_mode_select = document.getElementById("cpu_power_mode");
|
||||
if (response["cpu_power_mode"]) {
|
||||
cpu_power_mode_select.value = response["cpu_power_mode"];
|
||||
// Update status display
|
||||
const statusElement = document.getElementById('cpu_mode_status');
|
||||
statusElement.textContent = `Current: ${response["cpu_power_mode"]}`;
|
||||
statusElement.className = 'text-success';
|
||||
}
|
||||
|
||||
// If envea is enabled, show the envea sondes container
|
||||
if (response["envea"]) {
|
||||
add_sondeEnveaContainer();
|
||||
@@ -589,6 +613,83 @@ function update_config_sqlite(param, value){
|
||||
}
|
||||
|
||||
|
||||
function set_cpu_power_mode(mode) {
|
||||
console.log("Setting CPU power mode to:", mode);
|
||||
|
||||
const toastLiveExample = document.getElementById('liveToast');
|
||||
const toastBody = toastLiveExample.querySelector('.toast-body');
|
||||
const statusElement = document.getElementById('cpu_mode_status');
|
||||
|
||||
// Show loading status
|
||||
statusElement.textContent = 'Applying mode...';
|
||||
statusElement.className = 'text-warning';
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=set_cpu_power_mode&mode=' + mode,
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
|
||||
let formattedMessage;
|
||||
|
||||
if (response.success) {
|
||||
// Success message
|
||||
toastLiveExample.classList.remove('text-bg-danger');
|
||||
toastLiveExample.classList.add('text-bg-success');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Success!</strong><br>
|
||||
CPU mode set to: <strong>${mode}</strong><br>
|
||||
${response.description || ''}
|
||||
`;
|
||||
|
||||
// Update status
|
||||
statusElement.textContent = `Current: ${mode}`;
|
||||
statusElement.className = 'text-success';
|
||||
|
||||
} else {
|
||||
// Error message
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Error!</strong><br>
|
||||
${response.error || 'Failed to set CPU power mode'}
|
||||
`;
|
||||
|
||||
// Reset status
|
||||
statusElement.textContent = 'Error setting mode';
|
||||
statusElement.className = 'text-danger';
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Show error in toast
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
toastBody.innerHTML = `<strong>Error!</strong><br>Network error: ${error}`;
|
||||
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
|
||||
// Update status
|
||||
statusElement.textContent = 'Network error';
|
||||
statusElement.className = 'text-danger';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function update_config(param, value){
|
||||
console.log("Updating ",param," : ", value);
|
||||
$.ajax({
|
||||
|
||||
@@ -1423,3 +1423,95 @@ if ($type == "detect_envea_device") {
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
____ ____ _ _ ____ __ __ _
|
||||
/ ___| _ \| | | | | _ \ _____ _____ _ _| \/ | __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_
|
||||
| | | |_) | | | | | |_) / _ \ \ /\ / / _ \ '__| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __|
|
||||
| |___| __/| |_| | | __/ (_) \ V V / __/ | | | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_
|
||||
\____|_| \___/ |_| \___/ \_/\_/ \___|_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__|
|
||||
|___/
|
||||
*/
|
||||
|
||||
// Get current CPU power mode
|
||||
if ($type == "get_cpu_power_mode") {
|
||||
try {
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/power/set_cpu_mode.py get 2>&1';
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Try to parse JSON output
|
||||
$result = json_decode($output, true);
|
||||
|
||||
if ($result && isset($result['success']) && $result['success']) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'mode' => $result['config_mode'] ?? 'unknown',
|
||||
'cpu_state' => $result['cpu_state'] ?? null
|
||||
], JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Failed to get CPU power mode',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Script execution failed: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Set CPU power mode
|
||||
if ($type == "set_cpu_power_mode") {
|
||||
$mode = $_GET['mode'] ?? null;
|
||||
|
||||
if (empty($mode)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'No mode specified'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate mode (whitelist)
|
||||
$allowedModes = ['normal', 'powersave'];
|
||||
|
||||
if (!in_array($mode, $allowedModes)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Invalid mode. Allowed: normal, powersave'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Execute the CPU power mode script
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/power/set_cpu_mode.py ' . escapeshellarg($mode) . ' 2>&1';
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Try to parse JSON output
|
||||
$result = json_decode($output, true);
|
||||
|
||||
if ($result && isset($result['success']) && $result['success']) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'mode' => $mode,
|
||||
'message' => "CPU power mode set to: $mode",
|
||||
'description' => $result['description'] ?? ''
|
||||
], JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => $result['error'] ?? 'Failed to set CPU power mode',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Script execution failed: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user