Skip to content

proposal for issue #1845 Scan networks don't work after WPS config failed #2312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2016

Conversation

jbheren
Copy link
Contributor

@jbheren jbheren commented Jul 21, 2016

Thix fixes the issue for me as discussed here :
#1845

It seems like wifi_wps_status_cb gets an undefined status 4, I gave it a name and added the missing call to wifi_wps_disable.

here is a sketch for testing the case.

/*
 *  This sketch demonstrates how to scan WiFi networks. 
 *  The API is almost the same as with the WiFi Shield library, 
 *  the most obvious difference being the different file you need to include:
 */
#include "ESP8266WiFi.h"

void setup() {
  Serial.begin(74880);
  Serial.setDebugOutput(1);
  Serial.setDebugOutput(true);

  // 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() {

  // If not connected, run the WPS procedure.
  if(!connectWPS()) {
    Serial.println("WPS Failed");
  }

  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) == ENC_TYPE_NONE)?" ":"*");
      delay(10);
    }
  }
  Serial.println("");

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

// https://gist.github.com/copa2/fcc718c6549721c210d614a325271389
bool connectWPS() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("\nAttempting WPS connection ...");
    bool wpsSuccess = WiFi.beginWPSConfig();
    if(wpsSuccess) {
      // Ckeck SSID
      String newSSID = WiFi.SSID();
      if(newSSID.length() > 0) {
        // WPSConfig has already connected in STA mode successfully to the new station.
        Serial.printf("WPS finished. Connected successfull to SSID '%s'\n", newSSID.c_str());
      } else {
        Serial.println("WiFi.beginWPSConfig() returns true BUT WiFi.SSID() is Empty");
        wpsSuccess = false;
      }
    }
    return wpsSuccess; 
  } 
}

@codecov-io
Copy link

Current coverage is 27.62% (diff: 100%)

Merging #2312 into master will not change coverage

@@             master      #2312   diff @@
==========================================
  Files            20         20          
  Lines          3656       3656          
  Methods         335        335          
  Messages          0          0          
  Branches        678        678          
==========================================
  Hits           1010       1010          
  Misses         2468       2468          
  Partials        178        178          

Powered by Codecov. Last update 7900132...03a8f06

@igrr igrr merged commit db5e20f into esp8266:master Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants