Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- const char* ssid = "YourWiFiSSID";
- const char* password = "YourWiFiPassword";
- void setup() {
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- WiFi.disconnect();
- delay(100);
- Serial.println("Scanning available WiFi networks...");
- int n = WiFi.scanNetworks();
- if (n == 0) {
- Serial.println("No networks found");
- } else {
- Serial.println("Found networks:");
- 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) == ENC_TYPE_NONE) ? " " : "*");
- delay(10);
- }
- }
- // Connect to an open WiFi network
- for (int i = 0; i < n; ++i) {
- if (WiFi.encryptionType(i) == ENC_TYPE_NONE) {
- Serial.println("Connecting to open network...");
- WiFi.begin(WiFi.SSID(i), "");
- break;
- }
- }
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void loop() {
- // Do nothing
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement