Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include "esp_wifi.h"
- #include "esp_system.h"
- #include "esp_event.h"
- #include "esp_event_loop.h"
- #include "nvs_flash.h"
- #include "console.h"
- #include "socket.h"
- esp_err_t event_handler(void *ctx, system_event_t *event)
- {
- int i;
- if (event->event_id == SYSTEM_EVENT_SCAN_DONE) {
- printf("Number of access points found: %d\n",
- event->event_info.scan_done.number);
- uint16_t apCount = event->event_info.scan_done.number;
- if (apCount == 0) {
- return ESP_OK;
- }
- wifi_ap_record_t *list =
- (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * apCount);
- ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&apCount, list));
- for (i = 0; i < apCount; i++) {
- char authmode[64];
- switch(list[i].authmode) {
- case WIFI_AUTH_OPEN:
- strcpy(authmode, "WIFI_AUTH_OPEN");
- break;
- case WIFI_AUTH_WEP:
- strcpy(authmode, "WIFI_AUTH_WEP");
- break;
- case WIFI_AUTH_WPA_PSK:
- strcpy(authmode, "WIFI_AUTH_WPA_PSK");
- break;
- case WIFI_AUTH_WPA2_PSK:
- strcpy(authmode, "WIFI_AUTH_WPA2_PSK");
- break;
- case WIFI_AUTH_WPA_WPA2_PSK:
- strcpy(authmode, "WIFI_AUTH_WPA_WPA2_PSK");
- break;
- default:
- strcpy(authmode, "Unknown");
- break;
- }
- printf("MAC=");
- for (int j = 0; j < 5; ++j)
- {
- printf("%02x:", list[i].bssid[j]);
- }
- printf("%02x", list[i].bssid[5]);
- printf(", ssid=%s, rssi=%d, ", list[i].ssid, list[i].rssi);
- printf("authmode=%s\n", authmode);
- }
- free(list);
- }
- return ESP_OK;
- }
- extern "C" { // needed for the C functions to call it
- int app_main(void)
- {
- int portNbr = PORT_NBR;
- nvs_flash_init();
- tcpip_adapter_init();
- ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
- wifiInit();
- socketInit(portNbr);
- // Let us test a WiFi scan ...
- // 2018 03 22 mzimmers: convert these initializers for C++.
- // wifi_scan_config_t scanConf = {
- // .ssid = NULL,
- // .bssid = NULL,
- // .channel = 0,
- // .show_hidden = 1
- wifi_scan_config_t scanConf =
- {
- NULL,
- NULL,
- 0,
- 1,
- WIFI_SCAN_TYPE_ACTIVE,
- 0, 1000 // min/max scan times.
- };
- ESP_ERROR_CHECK(esp_wifi_scan_start(&scanConf, 0));
- initialize_console();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement