prusa3d / Prusa-Firmware-ESP32-Cam

Firmware for ESP32 Cam modules to be used in Prusa Connect
GNU General Public License v3.0
97 stars 10 forks source link

Add Gestion of Multiple SSID #35

Open BugsBunny1403 opened 1 month ago

BugsBunny1403 commented 1 month ago

Hello, if it possible to add an option for specify multiple SSID. It's an example i use with the old version of your work before join prusa team.

WiFiMulti wifiMulti;

void setup() {

  // Add list of wifi networks
  wifiMulti.addAP("SSID1", "password1");
  wifiMulti.addAP("SSID2", "SSID2");

  // 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);
    }
  }

  // Connect to Wi-Fi using wifiMulti (connects to the SSID with strongest connection)
  Serial.println("Connecting Wifi...");
  if(wifiMulti.run() == WL_CONNECTED) {
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  }

  Serial.println("");
  Serial.print("Signal Strength (RSSI): ");
  Serial.print(WiFi.RSSI());
  Serial.println(" dBm");
}

void loop() {
  Serial.println("----------------------------------------------------------------");
  /* check wifi reconnecting */
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Reconnecting to WiFi...");
  //if the connection to the stongest hotstop is lost, it will connect to the next network on the list
    if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED) {}

  } else if (WiFi.status() == WL_CONNECTED) {
    char cstr[150];
    sprintf(cstr, "Wifi connected. SSID: %s, RSSI: %d dBm, IP: %s \n", WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.localIP().toString().c_str());
    Serial.printf(cstr);
  }

}
johnyHV commented 1 month ago

Hello. I will look at the implementation and configuration of this option