Fix WiFi setup flow and improve hotspot management

- Fix deviceID overwrite bug: preserve manual configuration across reboots
- Use deviceName as hotspot SSID for better device identification
- Implement live WiFi scanning instead of reading stale CSV data
- Improve hotspot management with dynamic connection detection
- Add database status updates on WiFi connection success/failure
- Hide password in logs for better security

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
PaulVua
2026-01-05 17:27:37 +01:00
parent a38ce79555
commit 1f4d38257e
3 changed files with 69 additions and 33 deletions

View File

@@ -792,33 +792,39 @@ if ($type == "wifi_connect") {
if ($type == "wifi_scan") {
// Set the path to your CSV file
$csvFile = '/var/www/nebuleair_pro_4g/wifi_list.csv';
// Perform live WiFi scan instead of reading stale CSV file
$output = shell_exec('nmcli -f SSID,SIGNAL,SECURITY device wifi list ifname wlan0 2>/dev/null');
// Initialize an array to hold the JSON data
$jsonData = [];
// Open the CSV file for reading
if (($handle = fopen($csvFile, 'r')) !== false) {
// Get the headers from the first row
$headers = fgetcsv($handle);
// Loop through the rest of the rows
while (($row = fgetcsv($handle)) !== false) {
// Combine headers with row data to create an associative array
$jsonData[] = array_combine($headers, $row);
if ($output) {
// Split the output into lines
$lines = explode("\n", trim($output));
// Skip the header line and process each network
for ($i = 1; $i < count($lines); $i++) {
$line = trim($lines[$i]);
if (empty($line)) continue;
// Split by multiple spaces (nmcli uses column formatting)
$parts = preg_split('/\s{2,}/', $line, 3);
if (count($parts) >= 2) {
$jsonData[] = [
'SSID' => trim($parts[0]),
'SIGNAL' => trim($parts[1]),
'SECURITY' => isset($parts[2]) ? trim($parts[2]) : '--'
];
}
}
// Close the file handle
fclose($handle);
}
// Set the content type to JSON
header('Content-Type: application/json');
// Convert the array to JSON format and output it
echo json_encode($jsonData, JSON_PRETTY_PRINT);
}