Scan for access points.

mrdebug
Posts: 43
Joined: Sat Jul 27, 2019 8:26 am

Scan for access points.

Postby mrdebug » Mon Aug 05, 2019 7:58 am

Hi, with these lines of code

Code: Select all

tcpip_adapter_init();
	pNetworkService->EspErrorCheck(esp_event_loop_create_default());
	pNetworkService->EspErrorCheck(esp_event_loop_init(nullptr, nullptr));

    wifi_init_config_t Config= WIFI_INIT_CONFIG_DEFAULT();
    pNetworkService->EspErrorCheck(esp_wifi_init(&Config));

    pNetworkService->EspErrorCheck(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifiEventHandle, nullptr));
    pNetworkService->EspErrorCheck(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifiEventHandle, nullptr));
    pNetworkService->EspErrorCheck(esp_wifi_set_storage(WIFI_STORAGE_RAM));
    pNetworkService->EspErrorCheck(esp_wifi_set_mode(WIFI_MODE_STA));

	wifi_scan_config_t WifiConfig;
	WifiConfig.ssid= 0;
	WifiConfig.bssid= 0;
	WifiConfig.channel= 0;
	WifiConfig.show_hidden= true;
	pNetworkService->EspErrorCheck(esp_wifi_scan_start(&WifiConfig, true));

	pNetworkService->EspErrorCheck(esp_wifi_start());
	uint16_t AccessPointMax= 20;
	wifi_ap_record_t AccessPointRecords[20];
	pNetworkService->EspErrorCheck(esp_wifi_scan_get_ap_records(&AccessPointMax, AccessPointRecords));
	pNetworkService->OnLog("WIFIScanTask Access points: "+ std::to_string(AccessPointMax));
	for (int count= 0; count< AccessPointMax; count++) {
		pNetworkService->OnLog("WIFIScanTask SSID: "+ std::string((char*)AccessPointRecords[count].ssid)+ ", rssi: "+ std::to_string(AccessPointRecords[count].rssi));
	}
I can enumerate the active access points. The problem is that this approach works only if I am already connected at an access point. If not the funtion returs immediately without any result.
How can I enumerate the access points without to be cconnected to someone?

Who is online

Users browsing this forum: cdollar and 105 guests