-->
Page 1 of 2

ESP8266 Wireless Protected Setup (WPS) and Debugging

PostPosted: Tue Aug 25, 2015 11:33 am
by dakazmier
First off, kudos to the community and to Ivan Grokhotkov in particular for getting the new SDK into the Arduino build for the ESP8266. We have been wanting to setup WPS for some time now and having the core support for the Push Button mode is going to be awesome... if I could just get it working ;)

So, a few comments and questions and hopefully this thread can serve as a guiding light for all in the future who want to implement WPS-PBC on their ESP8266.

#1) How in the world do you put the ESP8266 into debug mode??? I see in the code all this great debugging information like
Code: Select allDEBUGV("wps cb status: %d\r\n", status);
but I can't ever see it. I see in the debug.h file this define:
Code: Select all#define DEBUGV(...)
so perhaps I just need to overwrite it? How can I get this debugging information back out of the module??

#2) I have a push button on my hardware, when that is pressed I am calling
Code: Select all beginWPSConfig();
. It is returning TRUE but that can't be, because I haven't pressed the button on my router as well ;) So... assuming it was working properly, how do we retrieve the SSID and Key(password) that the module associates with so that we can connect again after a power cycle? I know I can call
Code: Select allWiFi.SSID();
to retrieve the SSID, but what about the key(password/passphrase)?

Thanks for any and all assistance!!

Re: ESP8266 Wireless Protected Setup (WPS) and Debugging

PostPosted: Wed Aug 26, 2015 3:37 pm
by dakazmier
Okay, answering my first question, I had to call Serial.setDebugOutput(1); right after my Serial.begin and change the debug header file /Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-1044-g170995a/cores/esp8266/debug.h to #define DEBUGV(...) ets_printf(__VA_ARGS__) and now I can see debug output!

Next, getting WPS working... When I press my WPS button the first 2 lines of the debug below are mine and the rest are from ESP8266WiFi.cpp... no idea why this crashed my board, so I welcome any and all ideas:

Code: Select allWPS Button Pushed
Calling WiFi.beginWPSConfig()
wps begin
wifi_wps_enable
wps scan
build public key start
build public key finish
beacon timeout
state: 5 -> 0 (1)
rm 0
wifi evt: 1

stopAll 3ffe9e7c 3ffe9e7c

Re: ESP8266 Wireless Protected Setup (WPS) and Debugging

PostPosted: Wed Aug 26, 2015 4:51 pm
by dakazmier
For those following along, I made some more progress but continue to have some crasher issues. I can not get through the WPS process about half of the time.... The issue is in the core ESP8266wifi.cpp library and a function call that passes a parameter by reference. When I change this to pass by value it seems to work about 50% of the time, crashing my board the half of the time. I opened an issue on github, please see this for the details: https://github.com/esp8266/Arduino/issues/724

Re: ESP8266 Wireless Protected Setup (WPS) and Debugging

PostPosted: Mon Aug 31, 2015 7:36 am
by dakazmier
I have great news: I have gotten WPS to work!

It turns out that the problem I am was having with pass-by-reference call in the WPS callback was not because of the pass-by-reference, its because I was executing the entire code during the interrupt. Being fairly new to embedded development I didn't realize this was a problem. So now, I set a global variable
Code: Select allWPS_START = 1;
when my WPS button is pushed, then I check for this in
Code: Select allloop()
and process accordingly.

Some WPS caveats to be aware of:
1. The ESP8266 will actually store the SSID and Passcode in its own flash if WPS connected successfully. So, as long as you don't call
Code: Select allWiFi.begin(...)
you can reconnect after a reboot, etc.
2. Because there is not a way to get the WPS status back yet, you just have to check to see if the connection works. Here is my code where I put the unit into AP mode if I don't connect:
Code: Select all        int count = 0;

        Serial.print("Checking connection status");
        while ( (WiFi.status() != WL_CONNECTED) && BREAK_EVENT < 1 && count < 300)
        {
            count++;
            if( count % 20 == 0) {
               Serial.print(".");
            }
            t.update();
            delay(100);
        }
        Serial.println("\nConnection status: " + String(WiFi.status()) );
       
        if ( BREAK_EVENT ){
          Serial.println("BREAK");
          return;
        }

        if (WiFi.status() != WL_CONNECTED)
        {
           Serial.println("Could not connect, starting AP mode");
           SERVER_init_APMode();
           return;
        }


I hope this helps someone else in the future!

Regards,

--Mike