Skip to content

Commit 6a5b5b5

Browse files
authored
Add WiFi scan to settings V2 (#596)
* revised pr #553
1 parent d81942a commit 6a5b5b5

22 files changed

Lines changed: 327 additions & 2 deletions

main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ SRCS
4949
"./http_server/handler_otp.cpp"
5050
"./http_server/handler_restart.cpp"
5151
"./http_server/handler_shutdown.cpp"
52+
"./http_server/handler_wifi_scan.cpp"
5253
"./http_server/handler_file.cpp"
5354
"./http_server/handler_ota_factory.cpp"
5455
"./http_server/v2/handler_v2_dashboard.cpp"

main/http_server/axe-os/src/app/models/IIdentifyV2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export interface IIdentifyV2 {
22
deviceModel: string;
33
defaultTheme: string;
44
otp: boolean;
5+
apActive: boolean;
56
can: { enabled: boolean; };
67
}

main/http_server/axe-os/src/app/models/ISettingsV2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface ISettingsV2 {
3535
deviceModel: string;
3636
version: string;
3737
otp: boolean;
38+
apActive: boolean;
3839

3940
// CAN
4041
can: { hasExtension: boolean; enabled: boolean; };

main/http_server/axe-os/src/app/pages/edit/edit.component.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ <h4>{{ 'COMMON.LOADING' | translate }}</h4>
1818
</div>
1919
<div class="form-row">
2020
<label for="ssid" class="form-label">{{ 'SETTINGS.WIFI_SSID' | translate }}:</label>
21-
<div class="form-control-wrapper">
21+
<div class="input-with-icon">
2222
<input nbInput id="ssid" type="text" formControlName="ssid" />
23+
<button *ngIf="apActive" nbButton ghost size="small" (click)="scanWifi(wifiScanDialog)" type="button"
24+
class="icon-button" [disabled]="wifiScanning"
25+
[nbTooltip]="'SETTINGS.WIFI_SCAN' | translate">
26+
<nb-icon [icon]="wifiScanning ? 'loader-outline' : 'search-outline'" pack="eva"></nb-icon>
27+
</button>
2328
</div>
2429
</div>
2530
<div class="form-row">
@@ -651,6 +656,26 @@ <h6 class="fan-column__title">{{ 'FAN.SECONDARY_CONTROLLER' | translate }}</h6>
651656
</nb-card>
652657
</ng-template>
653658

659+
<ng-template #wifiScanDialog>
660+
<nb-card style="width: 420px; max-height: 70vh;">
661+
<nb-card-header>{{ 'SETTINGS.WIFI_SCAN_SELECT' | translate }}</nb-card-header>
662+
<nb-card-body style="overflow-y: auto;">
663+
<div *ngIf="wifiScanResults.length === 0" class="text-hint">
664+
{{ 'SETTINGS.WIFI_SCAN_NONE' | translate }}
665+
</div>
666+
<button *ngFor="let n of wifiScanResults" nbButton ghost fullWidth
667+
class="wifi-scan-entry"
668+
(click)="selectWifiNetwork(n.ssid)">
669+
<span class="wifi-scan-entry__ssid">{{ n.ssid }}</span>
670+
<span class="wifi-scan-entry__rssi wifi-scan-entry__rssi--{{ wifiSignalStrength(n.rssi) }}">
671+
<nb-icon icon="wifi-outline" pack="eva"></nb-icon>
672+
{{ n.rssi }} dBm
673+
</span>
674+
</button>
675+
</nb-card-body>
676+
</nb-card>
677+
</ng-template>
678+
654679

655680

656681

main/http_server/axe-os/src/app/pages/edit/edit.component.scss

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,40 @@
336336
}
337337
}
338338

339+
.wifi-scan-entry {
340+
display: flex !important;
341+
justify-content: space-between !important;
342+
align-items: center !important;
343+
text-align: left !important;
344+
padding: 6px 10px !important;
345+
margin-bottom: 4px !important;
346+
width: 100%;
347+
text-transform: none !important;
348+
}
349+
350+
.wifi-scan-entry * {
351+
text-transform: none !important;
352+
}
353+
354+
.wifi-scan-entry__ssid {
355+
flex: 1 1 auto;
356+
overflow: hidden;
357+
text-overflow: ellipsis;
358+
white-space: nowrap;
359+
font-weight: 500;
360+
}
361+
362+
.wifi-scan-entry__rssi {
363+
display: inline-flex;
364+
align-items: center;
365+
gap: 4px;
366+
font-size: 0.8rem;
367+
flex-shrink: 0;
368+
opacity: 0.8;
369+
}
370+
371+
.wifi-scan-entry__rssi--excellent { color: #4caf50; }
372+
.wifi-scan-entry__rssi--good { color: #8bc34a; }
373+
.wifi-scan-entry__rssi--fair { color: #ffc107; }
374+
.wifi-scan-entry__rssi--weak { color: #f44336; }
375+

main/http_server/axe-os/src/app/pages/edit/edit.component.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export class EditComponent implements OnInit {
4444
public lastCoinbaseVerifyMode: number = 1;
4545
public lastFallbackCoinbaseVerifyMode: number = 1;
4646

47+
// WiFi scan
48+
public apActive = false;
49+
public wifiScanning = false;
50+
public wifiScanResults: { ssid: string; rssi: number; authmode: number }[] = [];
51+
4752
toggleCoinbaseVerify(enabled: boolean, controlName: string, lastRef: 'lastCoinbaseVerifyMode' | 'lastFallbackCoinbaseVerifyMode') {
4853
const ctrl = this.form.controls[controlName];
4954
if (enabled) {
@@ -105,6 +110,7 @@ export class EditComponent implements OnInit {
105110
this.originalSettings["poolMode"] = info.poolMode ?? 0;
106111

107112
this.otpEnabled = !!info.otp;
113+
this.apActive = !!info.apActive;
108114
this.hasCanExtension = !!info.can.hasExtension;
109115

110116
this.asicModel = info.asicModel;
@@ -666,4 +672,45 @@ export class EditComponent implements OnInit {
666672
}
667673
}
668674

675+
public scanWifi(dialog: TemplateRef<any>): void {
676+
if (this.wifiScanning) return;
677+
this.wifiScanning = true;
678+
this.systemService.scanWifi().subscribe({
679+
next: (response) => {
680+
const byStrength: { [ssid: string]: { ssid: string; rssi: number; authmode: number } } = {};
681+
for (const n of response.networks || []) {
682+
if (!n.ssid) continue;
683+
if (!byStrength[n.ssid] || n.rssi > byStrength[n.ssid].rssi) {
684+
byStrength[n.ssid] = n;
685+
}
686+
}
687+
this.wifiScanResults = Object.values(byStrength).sort((a, b) => b.rssi - a.rssi);
688+
this.wifiScanning = false;
689+
this.dialogRef = this.dialogService.open(dialog, { closeOnBackdropClick: true });
690+
},
691+
error: () => {
692+
this.wifiScanning = false;
693+
this.toastrService.danger(
694+
this.translate.instant('SETTINGS.WIFI_SCAN_FAILED'),
695+
this.translate.instant('COMMON.ERROR')
696+
);
697+
}
698+
});
699+
}
700+
701+
public selectWifiNetwork(ssid: string): void {
702+
this.form.patchValue({ ssid });
703+
this.form.markAsDirty();
704+
if (this.dialogRef) {
705+
this.dialogRef.close();
706+
}
707+
}
708+
709+
public wifiSignalStrength(rssi: number): string {
710+
if (rssi >= -50) return 'excellent';
711+
if (rssi >= -60) return 'good';
712+
if (rssi >= -70) return 'fair';
713+
return 'weak';
714+
}
715+
669716
}

main/http_server/axe-os/src/app/services/system.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ export class SystemService {
226226
return this.httpClient.patch(`${uri}/api/v2/settings`, update, { headers });
227227
}
228228

229+
public scanWifi(): Observable<{ networks: { ssid: string; rssi: number; authmode: number }[] }> {
230+
return this.httpClient.get<{ networks: { ssid: string; rssi: number; authmode: number }[] }>('/api/v2/wifi/scan');
231+
}
232+
229233
public getIdentifyV2(uri: string = ''): Observable<IIdentifyV2> {
230234
return this.httpClient.get<IIdentifyV2>(`${uri}/api/v2/identify`);
231235
}

main/http_server/axe-os/src/assets/i18n/de.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
"WIFI_SSID": "WiFi-Netzwerk (SSID)",
148148
"WIFI_PASSWORD": "WiFi-Passwort",
149149
"WIFI_PASSWORD_PLACEHOLDER": "WiFi-Passwort eingeben",
150+
"WIFI_SCAN": "WiFi suchen",
151+
"WIFI_SCAN_SELECT": "WiFi-Netzwerk auswählen",
152+
"WIFI_SCAN_NONE": "Keine Netzwerke gefunden",
153+
"WIFI_SCAN_FAILED": "WiFi-Suche fehlgeschlagen",
150154
"FREQUENCY": "Frequenz",
151155
"VOLTAGE": "Spannung",
152156
"CORE_VOLTAGE": "Kernspannung",

main/http_server/axe-os/src/assets/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
"WIFI_SSID": "WiFi Network (SSID)",
148148
"WIFI_PASSWORD": "WiFi Password",
149149
"WIFI_PASSWORD_PLACEHOLDER": "Enter WiFi password",
150+
"WIFI_SCAN": "Scan WiFi",
151+
"WIFI_SCAN_SELECT": "Select WiFi Network",
152+
"WIFI_SCAN_NONE": "No networks found",
153+
"WIFI_SCAN_FAILED": "WiFi scan failed",
150154
"FREQUENCY": "Frequency",
151155
"VOLTAGE": "Voltage",
152156
"CORE_VOLTAGE": "Core Voltage",

main/http_server/axe-os/src/assets/i18n/es.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
"WIFI_SSID": "Red WiFi (SSID)",
148148
"WIFI_PASSWORD": "Contraseña WiFi",
149149
"WIFI_PASSWORD_PLACEHOLDER": "Ingrese contraseña WiFi",
150+
"WIFI_SCAN": "Buscar WiFi",
151+
"WIFI_SCAN_SELECT": "Seleccionar red WiFi",
152+
"WIFI_SCAN_NONE": "No se encontraron redes",
153+
"WIFI_SCAN_FAILED": "Búsqueda WiFi fallida",
150154
"FREQUENCY": "Frecuencia",
151155
"VOLTAGE": "Voltaje",
152156
"CORE_VOLTAGE": "Voltaje del Núcleo",

0 commit comments

Comments
 (0)