Skip to content

Commit 1ad2713

Browse files
committed
updated HardwareTest example to use new network classes
1 parent fffc285 commit 1ad2713

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

examples/VGA/HardwareTest/HardwareTest.ino

+11-36
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
#include "fabgl.h"
3939
#include "fabui.h"
4040
#include "devdrivers/MCP23S17.h"
41-
42-
#include <WiFi.h>
43-
#include "esp_wifi.h"
44-
#include "esp_event.h"
41+
#include "network/netutils.h"
4542

4643

4744

@@ -409,41 +406,19 @@ struct TestApp : public uiApp {
409406
}
410407

411408
void testWifi() {
412-
// use API directly to be able to call esp_wifi_deinit() and free necessary memory to mount sd card
413-
414-
esp_event_loop_create_default();
415-
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
416-
417-
// reduce wifi memory footprint
418-
cfg.static_rx_buf_num = 2;
419-
cfg.static_tx_buf_num = 1;
420-
cfg.ampdu_rx_enable = cfg.ampdu_tx_enable = cfg.amsdu_tx_enable = 0;
421-
422-
esp_wifi_init(&cfg);
423-
uint16_t number = 8;
424-
wifi_ap_record_t ap_info[number];
425-
uint16_t ap_count = 0;
426-
memset(ap_info, 0, sizeof(ap_info));
427-
esp_wifi_set_mode(WIFI_MODE_STA);
428-
esp_wifi_start();
429-
auto r = esp_wifi_scan_start(NULL, true);
430-
esp_wifi_scan_get_ap_records(&number, ap_info);
431-
esp_wifi_scan_get_ap_num(&ap_count);
432-
esp_wifi_stop();
433-
esp_wifi_deinit();
434-
esp_event_loop_delete_default();
435-
436-
if (r != ESP_OK) {
409+
fabgl::WiFiScanner scanner;
410+
if (scanner.scan(0, true)) {
411+
if (scanner.count() == 0) {
412+
wifiResultLabel->labelStyle().textColor = Color::Yellow;
413+
wifiResultLabel->setText("Ok, No Network Found!");
414+
} else {
415+
wifiResultLabel->labelStyle().textColor = Color::Green;
416+
wifiResultLabel->setTextFmt("Ok, Found %d Networks", scanner.count());
417+
}
418+
} else {
437419
wifiResultLabel->labelStyle().textColor = Color::BrightRed;
438420
wifiResultLabel->setText("Wifi Scan Failed!");
439-
} else if (ap_count == 0) {
440-
wifiResultLabel->labelStyle().textColor = Color::Yellow;
441-
wifiResultLabel->setText("Ok, No Network Found!");
442-
} else {
443-
wifiResultLabel->labelStyle().textColor = Color::Green;
444-
wifiResultLabel->setTextFmt("Ok, Found %d Networks", ap_count);
445421
}
446-
447422
}
448423

449424
} app;

0 commit comments

Comments
 (0)