WPS

Give it a try, it costs you nothing !
Post Reply
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

WPS

Post by Fernando Perez »

I want to make a proposal to improve Annex.
I hope no one feel upset (Robin ;) ), but a lack of Annex is still like connecting to the Wifi network when we give away our homemade gadgets to a friend or family member of a certain age.

Ruled out the procedure for it to connect to a weird router called ESP-*?%&!!!$$=<, wait patiently for it to tell you it doesn't have internet, then type in your browser 192.168.4.1, scroll through the windows and fill out a form with rare data and a password obtained from the sticker on your router by using a magnifying glass, it remains only to experiment with other methods.

Currently, all our routers have a WPS button. By means of this program, which you can load in an ESP32 through the cordially hated Arduino IDE, you will see appear in the serial terminal, after pressing the WPS button of your router, not only its SSID, but also the access password.
I have achieved it by "slightly" adapting the WPS.ino example that comes in the folder:

D:\Portables\Arduino\portable\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi\examples\WPS
(Ignore the references to "portable", which in my case I do not have the standard installation.)

I propose to translate this program to Annex which, sure, is technically possible, but it is beyond me.
If it is achieved, our programs could be configured to connect to Wifi obtaining the data by WPS.

Code: [Local Link Removed for Guests]

#include <WiFi.h>
#include <esp_wps.h>
#include <esp_wifi.h>

#define ESP_WPS_MODE      WPS_TYPE_PBC
#define ESP_MANUFACTURER  "ESPRESSIF"
#define ESP_MODEL_NUMBER  "ESP32"
#define ESP_MODEL_NAME    "ESPRESSIF IOT"
#define ESP_DEVICE_NAME   "ESP STATION"

static esp_wps_config_t config;

void wpsInitConfig(){
  config.crypto_funcs = &g_wifi_default_wps_crypto_funcs;
  config.wps_type = ESP_WPS_MODE;
  strcpy(config.factory_info.manufacturer, ESP_MANUFACTURER);
  strcpy(config.factory_info.model_number, ESP_MODEL_NUMBER);
  strcpy(config.factory_info.model_name, ESP_MODEL_NAME);
  strcpy(config.factory_info.device_name, ESP_DEVICE_NAME);
}

String wpspin2string(uint8_t a[]){
  char wps_pin[9];
  for(int i=0;i<8;i++){
    wps_pin[i] = a[i];
  }
  wps_pin[8] = '\0';
  return (String)wps_pin;
}

void WiFiEvent(WiFiEvent_t event, system_event_info_t info){
  switch(event){
    case SYSTEM_EVENT_STA_START:
      Serial.println("Iniciando modo Estacion");
      break;
    case SYSTEM_EVENT_STA_GOT_IP:
      Serial.println("Conectado a :" + String(WiFi.SSID()));
      Serial.print("Obtenida IP: ");
      Serial.println(WiFi.localIP());
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      Serial.println("Desconectado, intentando reconectar");
      WiFi.reconnect();
      break;
    case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
      Serial.println("Establecida conexion por WPS");
      Serial.println("Deteniendo WPS y conectándose a: " + String(WiFi.SSID()));
      esp_wifi_wps_disable();
      delay(10);
      WiFi.begin();
      break;
    case SYSTEM_EVENT_STA_WPS_ER_FAILED:
      Serial.println("WPS ha fallado, reintentando");
      esp_wifi_wps_disable();
      esp_wifi_wps_enable(&config);
      esp_wifi_wps_start(0);
      break;
    case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
      Serial.println("Superado tiempo espera WPS, reintentando");
      esp_wifi_wps_disable();
      esp_wifi_wps_enable(&config);
      esp_wifi_wps_start(0);
      break;
    case SYSTEM_EVENT_STA_WPS_ER_PIN:
      Serial.println("WPS_PIN = " + wpspin2string(info.sta_er_pin.pin_code));
      break;
    default:
      break;
  }
}

void setup(){
  Serial.begin(115200);
  delay(10);
  Serial.println();
  WiFi.onEvent(WiFiEvent);
  WiFi.mode(WIFI_MODE_STA);
  Serial.println("Iniciando busqueda WPS");
  wpsInitConfig();
  esp_wifi_wps_enable(&config);
  esp_wifi_wps_start(0);
}

void loop(){
        // ---------------------------
      wifi_config_t config;
      esp_err_t err = esp_wifi_get_config(WIFI_IF_STA, &config);
      if (err == ESP_OK) {
        printf("SSID: %s, PW: %s\n", (char*) config.sta.ssid, (char*) config.sta.password);
      } else {
        printf("Couldn't get config: %d\n", (int) err);
      }
      // ---------------------------
      delay(5000);
}

User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: WPS

Post by Electroguard »

No, I won't feel upset Fernando.
I've known Francesco's baby since before it was even born, and have felt like a protective uncle when suggestions were made which might have caused misuse or abuse to the beautiful baby - but whenever I stood up to defend and protect it in the past it seemed resented, making me the enemy target (as with your specific mention of my name)... but the future of Annex has nothing to do with me, so I am really not concerned what direction it takes.
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: WPS

Post by cicciocb »

HI Fernando,
the WPS could be a good idea but, again, you will still miss an important information: the IP address assigned by the router.

This cannot be done directly with Annex as requires some additional libraries so must be done in the firmware.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: WPS

Post by Fernando Perez »

I understand, Francesco, although if we can read the assigned IP, it will be valid only for that session, the session in which we get the SSID and PW.
That does not have to be the same in the following connections.
Ok, I'll keep thinking. :cry:
Just one question: The Arduino program saves somewhere in the ESP32 the data obtained when connecting via WPS. How can that part of memory be cleared, so that each time it is executed it starts over from scratch?
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: WPS

Post by Fernando Perez »

Please, Robin, don't be angry. I didn't mean to upset you. It was just a joke. I apologize.
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: WPS

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Dec 06, 2022 11:27 am I understand, Francesco, although if we can read the assigned IP, it will be valid only for that session, the session in which we get the SSID and PW.
That does not have to be the same in the following connections.
Ok, I'll keep thinking. :cry:
Just one question: The Arduino program saves somewhere in the ESP32 the data obtained when connecting via WPS. How can that part of memory be cleared, so that each time it is executed it starts over from scratch?
I think that is stored inside the nvs partition that is not modified when you flash again the module.
Probably the easiest way is to format the module
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: WPS

Post by Electroguard »

I'm not angry Fernando, I promise I won't drive around the Bay of Biscay corner from Landes to come knocking on your door, and it's too far to throw stones... but I've got a telescope and have my eye on you.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: WPS

Post by Fernando Perez »

Well Robin, you lose it, because I live in a very "bonita" city and with a bay considered one of "The most beautiful bays in the world".
https://world-bays.com/
https://world-bays.com/santander-bay/

I took this photo this summer:
Image

And you don't have to do those rounds, we have communication with you by weekly Ferries from Plymouth & Portsmouth.

A cordial greeting.
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: WPS

Post by Electroguard »

atlantic.jpg

No ferries near Mimizan France where I am amigo, just endless atlantic beaches and sand dunes.
Santander Bay is a couple of hours drive around the Bay of Biscay.

ICU.jpg

I drove through Santander once in a blizzard, slipping and sliding in a camper van up a steep snow-covered hill that climbed up for ever.
I remember looking forward to the downhill drop on the other side, but it never came... after an hour of low gear climbing it just eventually leveled off to a high plateau up in the clouds.
The coast of norther Spain certainly has some spectacular scenery.
You do not have the required permissions to view the files attached to this post.
Post Reply