About WiFi scan sketch

Hi every one.
I tested a WiFi scan sketch got error message of:
'class WiFiClass' has no member named 'mode'
where can find a suitable library for it please?

I have tested few of libraries with its examples, got similar errors.

the reason I do that is my ESP32 can't connect to my WiFi router now, it was connecting well before. do I need change my router's mode?

Thanks
Adam

#include "WiFi.h"

void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // 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("");

  // Wait a bit before scanning again
  delay(5000);
}

ERROR:

Arduino: 1.8.16 (Windows 7), Board: "AI Thinker ESP32-CAM, 160MHz (WiFi/BT), QIO, 40MHz"



C:\Users\HUA.DELLV-PC\Documents\Arduino\WIFI_SCAN\WIFI_SCAN.ino: In function 'void setup()':

WIFI_SCAN:12:8: error: 'class WiFiClass' has no member named 'mode'

   WiFi.mode(WIFI_STA);

        ^~~~

WIFI_SCAN:12:13: error: 'WIFI_STA' was not declared in this scope

   WiFi.mode(WIFI_STA);

             ^~~~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\WIFI_SCAN\WIFI_SCAN.ino: In function 'void loop()':

WIFI_SCAN:38:49: error: 'WIFI_AUTH_OPEN' was not declared in this scope

       Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");

                                                 ^~~~~~~~~~~~~~

exit status 1

'class WiFiClass' has no member named 'mode'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

If I compile your sketch on windows 10 using Arduino IDE 1.8.19
with ESp32 core 1.0.6 and Board type ESP32 Dev module your code compiles

1 Like

Thank you.
yes, I compiling it on my WIN10.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.