2019-07-04 22:15:03 +03:00
|
|
|
/* WiFi scan Example
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
*/
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/task.h>
|
|
|
|
|
#include "sdkconfig.h"
|
2019-07-04 21:10:01 +03:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
|
|
|
|
|
|
void wifiScan() {
|
|
|
|
|
// WiFi.scanNetworks will return the number of networks found
|
|
|
|
|
int n = WiFi.scanNetworks();
|
|
|
|
|
Serial.println("scan done");
|
|
|
|
|
if (n == 0) {
|
|
|
|
|
Serial.println("no networks found");
|
|
|
|
|
} else {
|
|
|
|
|
Serial.print(n);
|
|
|
|
|
Serial.println(" networks found");
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
|
// Print SSID and RSSI for each network found
|
|
|
|
|
Serial.print(i + 1);
|
|
|
|
|
Serial.print(": ");
|
|
|
|
|
Serial.print(WiFi.SSID(i));
|
|
|
|
|
Serial.print(" (");
|
|
|
|
|
Serial.print(WiFi.RSSI(i));
|
|
|
|
|
Serial.print(")");
|
|
|
|
|
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
|
|
|
|
|
delay(10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Serial.println("");
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 22:15:03 +03:00
|
|
|
#if !CONFIG_AUTOSTART_ARDUINO
|
|
|
|
|
void arduinoTask(void *pvParameter) {
|
2019-07-04 21:10:01 +03:00
|
|
|
// Set WiFi to station mode and disconnect from an AP if it was previously connected
|
2019-07-04 22:15:03 +03:00
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
WiFi.disconnect();
|
2019-07-04 21:10:01 +03:00
|
|
|
Serial.begin(115200);
|
2019-07-04 22:15:03 +03:00
|
|
|
delay(100);
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
wifiScan();
|
|
|
|
|
|
|
|
|
|
// Wait a bit before scanning again
|
|
|
|
|
delay(5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 20:04:51 +05:30
|
|
|
extern "C" void app_main()
|
2019-07-04 22:15:03 +03:00
|
|
|
{
|
|
|
|
|
// initialize arduino library before we start the tasks
|
|
|
|
|
initArduino();
|
|
|
|
|
|
|
|
|
|
xTaskCreate(&arduinoTask, "arduino_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
void setup() {
|
|
|
|
|
// Set WiFi to station mode and disconnect from an AP if it was previously connected
|
2019-07-04 21:10:01 +03:00
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
WiFi.disconnect();
|
2019-07-04 22:15:03 +03:00
|
|
|
Serial.begin(115200);
|
2019-07-04 21:10:01 +03:00
|
|
|
delay(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
wifiScan();
|
2019-07-04 22:15:03 +03:00
|
|
|
// Wait a bit before scanning again
|
2019-07-04 21:10:01 +03:00
|
|
|
delay(5000);
|
2019-07-04 22:15:03 +03:00
|
|
|
}
|
|
|
|
|
#endif
|