update
This commit is contained in:
8
.claude/settings.local.json
Normal file
8
.claude/settings.local.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(python3:*)"
|
||||
],
|
||||
"deny": []
|
||||
}
|
||||
}
|
||||
@@ -1198,3 +1198,96 @@ if ($type == "toggle_systemd_service") {
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
_____ ____ _ _ _
|
||||
| ____|_ ____ _____ __ _ | _ \ ___| |_ ___ ___| |_(_) ___ _ __
|
||||
| _| | '_ \ \ / / _ \/ _` | | | | |/ _ \ __/ _ \/ __| __| |/ _ \| '_ \
|
||||
| |___| | | \ V / __/ (_| | | |_| | __/ || __/ (__| |_| | (_) | | | |
|
||||
|_____|_| |_|\_/ \___|\__,_| |____/ \___|\__\___|\___|\__|_|\___/|_| |_|
|
||||
|
||||
*/
|
||||
|
||||
// Detect Envea devices on specified port
|
||||
if ($type == "detect_envea_device") {
|
||||
$port = $_GET['port'] ?? null;
|
||||
|
||||
if (empty($port)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'No port specified'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate port name (security check)
|
||||
$allowedPorts = ['ttyAMA2', 'ttyAMA3', 'ttyAMA4', 'ttyAMA5'];
|
||||
|
||||
if (!in_array($port, $allowedPorts)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Invalid port name'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Execute the envea detection script
|
||||
$command = "sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/envea/read_ref.py " . escapeshellarg($port) . " 2>&1";
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Check if we got any meaningful output
|
||||
$detected = false;
|
||||
$device_info = '';
|
||||
$raw_data = $output;
|
||||
|
||||
if (!empty($output)) {
|
||||
// Look for indicators that a device is connected
|
||||
if (strpos($output, 'Connexion ouverte') !== false) {
|
||||
// Connection was successful
|
||||
if (strpos($output, 'Données reçues brutes') !== false &&
|
||||
strpos($output, 'b\'\'') === false) {
|
||||
// We received actual data (not empty)
|
||||
$detected = true;
|
||||
$device_info = 'Envea CAIRSENS Device';
|
||||
|
||||
// Try to extract device type from ASCII data if available
|
||||
if (preg_match('/Valeurs converties en ASCII : (.+)/', $output, $matches)) {
|
||||
$ascii_data = trim($matches[1]);
|
||||
if (!empty($ascii_data) && $ascii_data !== '........') {
|
||||
$device_info = "Envea Device: " . $ascii_data;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Connection successful but no data
|
||||
$device_info = 'Port accessible but no Envea device detected';
|
||||
}
|
||||
} else if (strpos($output, 'Erreur de connexion série') !== false) {
|
||||
// Serial connection error
|
||||
$device_info = 'Serial connection error - port may be busy or not available';
|
||||
} else {
|
||||
// Other output
|
||||
$device_info = 'Unexpected response from port';
|
||||
}
|
||||
} else {
|
||||
// No output at all
|
||||
$device_info = 'No response from port';
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'port' => $port,
|
||||
'detected' => $detected,
|
||||
'device_info' => $device_info,
|
||||
'data' => $raw_data,
|
||||
'timestamp' => date('Y-m-d H:i:s')
|
||||
], JSON_PRETTY_PRINT);
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Script execution failed: ' . $e->getMessage(),
|
||||
'port' => $port
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user