|
38 | 38 | #include "fabgl.h"
|
39 | 39 | #include "fabui.h"
|
40 | 40 | #include "devdrivers/MCP23S17.h"
|
41 |
| - |
42 |
| -#include <WiFi.h> |
43 |
| -#include "esp_wifi.h" |
44 |
| -#include "esp_event.h" |
| 41 | +#include "network/netutils.h" |
45 | 42 |
|
46 | 43 |
|
47 | 44 |
|
@@ -409,41 +406,19 @@ struct TestApp : public uiApp {
|
409 | 406 | }
|
410 | 407 |
|
411 | 408 | 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 { |
437 | 419 | wifiResultLabel->labelStyle().textColor = Color::BrightRed;
|
438 | 420 | 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); |
445 | 421 | }
|
446 |
| - |
447 | 422 | }
|
448 | 423 |
|
449 | 424 | } app;
|
|
0 commit comments