ESP32 WiFi AP BUG!

Thread Starter

Elazar

Joined Oct 29, 2019
27
Hi AllAboutCircuits lovers,

Does anyone have some hands of experience with the ESP32 OTA procedure?

The ESP32 WIFI OTA example that comes with the Arduino IDE works fine with wifi STA mode (or WiFi client mode)

However, I can not get it to work with the AP mode? the server seems to function but the update part just doesn't work, (the webpage lodes BUT, when I press the update button it just doesn't work, the updating process doesn't start!?)

See attached OTA function code:

Any input will be appreciated!:)


C:
void OTA() {

    WiFi.mode(WIFI_AP);
    WiFi.softAP(ssid);
    //WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_AP_STACONNECTED);
    String _ip = WiFi.softAPIP().toString();
    //Serial.print("IP address: "); `
    Serial.println(_ip);

    //return index page which is stored in serverIndex
    server.on("/", HTTP_GET, []() {
      server.sendHeader("Connection", "close");
      server.send(200, "text/html", loginIndex);
    });

  server.on("/", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", serverIndex);
  });

  /*handling uploading firmware file */
  server.on("/update", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
    ESP.restart();
  }, []() {
    HTTPUpload& upload = server.upload();
    if (upload.status == UPLOAD_FILE_START) {
      Serial.printf("Update: %s\n", upload.filename.c_str());
      if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_WRITE) {
      /* flashing firmware to ESP*/
      if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_END) {
      if (Update.end(true)) { //true to set the size to the current progress
        Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
      } else {
        Update.printError(Serial);
      }
    }
  });
  server.begin();

  while (1) {
    server.handleClient();
    delay(1);
  }
}

I don't see any reason why this function only works with the STA mode?
 
Last edited by a moderator:
Top