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