Go Down

Topic: OTA Access Point Time Out (Read 34 times) previous topic - next topic

ukeventlighting

Wonder is someone can help me here.

I'm trying to do an OTA update using Async WebServer running an Access Point. I've been going round and round for a few days now. I have striped my code right back, but every time I try to update the BIN file the HTML page times out and 192.168.4.1 is currently unable to handle this request.

Board : Wemos D1 Mini 8266

Code: [Select]
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>

//////////////////////////////////////////////////////////////

AsyncWebServer server(80);

const char* HTMLindex = "<h1>Main Index Page</h1>";
const char* HTMLupdate = "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";
bool restartRequired = false;  // Set this flag in the callbacks to restart ESP in the main loop

void handleUpload();
bool Set_API();

/////////////////////////////////////////////////////////////////////////

void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final)
{
    if (!index)
    {
        Serial.printf("UploadStart: %s\n", filename.c_str());
    }
    for (size_t i = 0; i < len; i++)
    {
        Serial.write(data[i]);
    }
    if (final)
    {
        Serial.printf("UploadEnd: %s, %u B\n", filename.c_str(), index + len);
    }
}


////////////////////////////////////////////////////

bool Set_API()
{
    Serial.println("Set_API");

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send_P(200, "text/html", HTMLindex); });
    server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request) { request->send_P(200, "text/html", HTMLupdate); });
    server.on(
        "/doUpdate", HTTP_POST,
        [](AsyncWebServerRequest *request) {},
        [](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data,
           size_t len, bool final) { handleUpload(request, filename, index, data, len, final); });

    server.begin();
    Serial.println("HTTP server started");
    return true;
}

/////////////////////////////////////////////////////////////////////////

void setup()
{
  Serial.begin(115200);
  Serial.setDebugOutput(true);

    uint8_t i;
    Serial.println("LOADING .....");
    for (i = 0; i < 5; ++i)
    {
        Serial.println(i);
        delay(500);
    }
   
    Set_API();  // Set AP Mode SSID and Password

    Serial.print("Setting soft-AP ... ");
    Serial.println(WiFi.softAP("TEST", "") ? "Ready" : "Failed!");
}


/////////////////////////////////////////////////////////////////////////

void loop()
{

  if (restartRequired){  // check the flag here to determine if a restart is required
    Serial.printf("Restarting ESP\n\r");
    restartRequired = false;
    ESP.restart();
  }

 
}

Go Up