Skip to content
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

task_wdt: - async_tcp (CPU 0/1) ESP32 #70

Open
krupis opened this issue Dec 7, 2020 · 0 comments
Open

task_wdt: - async_tcp (CPU 0/1) ESP32 #70

krupis opened this issue Dec 7, 2020 · 0 comments

Comments

@krupis
Copy link

krupis commented Dec 7, 2020

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

}

Access point code:

void handle_access_point() {

  WiFi.mode(WIFI_AP);
  WiFi.softAPdisconnect (true);
  WiFi.softAP("ESPNOW123", nullptr, 3);
  Serial.print("MAC address of this node is ");
  Serial.println(WiFi.softAPmacAddress());
  Serial.println();
  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP());


  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    //request->send(SPIFFS, "/index.html", String(), false);
    request->send(200, "text/html", SendHTML());
    Serial.println("executing index page");
  });

  
  server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/style.css", "text/css");
  });

 server.on("/static", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/static.html", String(), false, processor_static);
    Serial.println("executing static page");
  });

server.on("/action_page", HTTP_GET, [](AsyncWebServerRequest * request) {
    Serial.println("executing action page");
    int paramsNr = request->params();
    String inputMessage_ID;
    String inputMessage_Pass;
    Serial.println(paramsNr);

        if (request->hasParam("Network_ID")) {
          inputMessage_ID = request->getParam("Network_ID")->value();
          Serial.print("Input message ID: ");
          Serial.println(inputMessage_ID);
          writeFile(SPIFFS, "/ID.txt", inputMessage_ID.c_str());
        }

        if (request->hasParam("Network_pass")) {
          inputMessage_Pass = request->getParam("Network_pass")->value();
          Serial.print("Input message pass: ");
          Serial.println(inputMessage_Pass);
          writeFile(SPIFFS, "/Pass.txt", inputMessage_Pass.c_str());
        }


    //request->send(SPIFFS, "/action_page.html");
    request->send(200, "text/html", "<h1>The following values has been changed:</h1> <br>  Network_ID: " + inputMessage_ID +"<br> Network_Pass:"+inputMessage_Pass+"<br><a href=\"/\">Return to Home Page</a>");
    delay(1000);
    attempt_wifi_connection(inputMessage_ID,inputMessage_Pass);
  });

  server.begin();
}
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");

image

I have tried googling but could not find a real solution to this problem. Is this a known issue?

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

No branches or pull requests

1 participant