You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey. I am trying to design my own wifi manager program for ESP32.
Initially, I start ESP32 in access point and start a weberver where user can select wifi network and input ID and Password credentials. After submitting the ID and Password, I turn OFF the wifi and wait for 5 seconds. After that, I start wifi in Station mode and attempt to connect to the select WIFI network with given ID and Password credentials, If failed, start an access point again.
This is the setup code which attempts to connect to WIFI, if not succesfull, start and Acces point:
void setup() {
for (int i = 0; i < 10; ++i){
list_of_networks[i] = (char*)malloc( 256 ); // string length up to 255 bytes + null
}
Serial.begin(115200);
if(!SPIFFS.begin(true)){
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
number_of_wifi_networks=scan_wifi_networks();
for (int i=0;i<=number_of_wifi_networks;i++)
{
Serial.println(list_strings[i]);
}
delay(2000);
if (drd->detectDoubleReset())
{
Serial.println("Double Reset Detected");
handle_access_point();
}
else
{
Serial.println("No Double Reset Detected");
WiFi.mode(WIFI_STA);//start program by attempting to connect to wifi
char temp_buffer_ID[100];
char temp_buffer_Pass[100];
readFile(SPIFFS, "/ID.txt").toCharArray(temp_buffer_ID, sizeof(temp_buffer_ID));
readFile(SPIFFS, "/Pass.txt").toCharArray(temp_buffer_Pass, sizeof(temp_buffer_Pass));
Serial.print("Spiffs id converted to char array=");
Serial.println(temp_buffer_ID);
Serial.print("Spiffs password converted to char array=");
Serial.println(temp_buffer_Pass);
WiFi.begin(ssid,password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
handle_access_point();
return;
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
}
void attempt_wifi_connection(String ID_string, String Pass_string){
//void attempt_wifi_connection(char* ID_string, char* Pass_string){
Serial.println("turning OFF wifi and waiting for 5 sec");
WiFi.mode(WIFI_OFF); // First turn OFF the WIFI interface
delay(5000); //Needed, at least in my tests WiFi doesn't power off without this for some reason
Serial.println("5 seconds had passed");
char temp_buffer_ID[100]; // temporary storage for char array ID
char temp_buffer_Pass[100]; // temporary storage for char array Password
//Convert String type ID and password to char array
ID_string.toCharArray(temp_buffer_ID, sizeof(temp_buffer_ID));
Pass_string.toCharArray(temp_buffer_Pass, sizeof(temp_buffer_Pass));
Serial.print("Attempting to connect to the wifi with ID and password=");
Serial.println(temp_buffer_ID);
Serial.println(temp_buffer_Pass);
WiFi.mode(WIFI_STA);//start program by attempting to connect to wifi
WiFi.begin(temp_buffer_ID,temp_buffer_Pass);
//WiFi.begin(ID_string.c_str(),Pass_string.c_str());
if(WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.println("WiFi Failed!");
handle_access_point();
return;
}
Serial.println("Connection sucessful");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
However, I am noticing a strange behaviour when submitting the ID and password, I can see that attempt_wifi_connect function executes but immediately after 5 seconds delay the device restarts without even printing the following line:
Serial.println("5 seconds had passed");
I have tried googling but could not find a real solution to this problem. Is this a known issue?
The text was updated successfully, but these errors were encountered:
Hey. I am trying to design my own wifi manager program for ESP32.
Initially, I start ESP32 in access point and start a weberver where user can select wifi network and input ID and Password credentials. After submitting the ID and Password, I turn OFF the wifi and wait for 5 seconds. After that, I start wifi in Station mode and attempt to connect to the select WIFI network with given ID and Password credentials, If failed, start an access point again.
This is the setup code which attempts to connect to WIFI, if not succesfull, start and Acces point:
Access point code:
However, I am noticing a strange behaviour when submitting the ID and password, I can see that attempt_wifi_connect function executes but immediately after 5 seconds delay the device restarts without even printing the following line:
Serial.println("5 seconds had passed");
I have tried googling but could not find a real solution to this problem. Is this a known issue?
The text was updated successfully, but these errors were encountered: