Skip to content

Unable to bring up ArduinoOTA on an esp8266 which is also an AP #1482

Closed
@rDr4g0n

Description

@rDr4g0n

I am attempting to have an esp8266 function as a wireless AP and also be updatable via OTA, but this does not seem to work. If the esp connects to an existing AP, OTA works as expected, but if the esp brings up its own AP, OTA fails with:

[begin] roundedSize:       0x0003F000 (258048)
[begin] updateEndAddress:  0x00100000 (1048576)
[begin] currentSketchSize: 0x0003F000 (258048)
[begin] _startAddress:     0x000C1000 (790528)
[begin] _currentAddress:   0x000C1000 (790528)
[begin] _size:             0x0003EB40 (256832)
Start
Connect Failed
Error[2]: Connect Failed
premature end: res:0, pos:0/256832
rror[4]: End Failed
ERROR[0]: No Error

In the sample sketch below there is a function beginAP which brings up an access point, and a function connectToAP which connects to an existing access point. The sketch below works as expected, but if connectToAP is commented out and beginAP is uncommented, the issue appears.

#include <ArduinoOTA.h>

const char* ssid = "clownshoes";
const char* password = "clownshoes";
const char* ota_hostname = "clownshoes";
IPAddress apIP(192, 168, 1, 1);

// starts an access point
void beginAP(const char* ssid, const char* password, IPAddress ip){
    //WiFi.mode(WIFI_AP);
    WiFi.mode(WIFI_AP_STA);
    WiFi.softAPConfig(ip, ip, IPAddress(255, 255, 255, 0));
    WiFi.softAP(ssid, password);
    Serial.print("AP is up at ");
    Serial.println(WiFi.softAPIP());
}

// connects to an access point
void connectToAP(const char* ssid, const char* password){
    Serial.print("");
    WiFi.begin(ssid, password);
    while(WiFi.status() != WL_CONNECTED){
        Serial.print(".");
        delay(500);
    }
    Serial.print("\nConnected to '");
    Serial.print(ssid);
    Serial.print("' and got IP ");
    Serial.println(WiFi.localIP());
}

// starts OTA server
void beginOTA(const char* hostname){
    ArduinoOTA.setHostname(hostname);
    ArduinoOTA.onStart([]() {
        Serial.println("Start");
    });
    ArduinoOTA.onEnd([]() {
        Serial.println("\nEnd");
    });
    ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    });
    ArduinoOTA.onError([](ota_error_t error) {
        Serial.printf("Error[%u]: ", error);
        if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
        else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
        else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
        else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
        else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });
    ArduinoOTA.begin();
    Serial.print("OTA is up");
}

void setup(){
    Serial.begin(9600);
    //beginAP(ssid, password, apIP);
    connectToAP(ssid, password);
    delay(500);
    beginOTA(ota_hostname);
}

void loop(){
    ArduinoOTA.handle();
}

If this is merely a configuration issue on my side, it may be beneficial for it to be documented.

Thanks for the work! This sdk is killer :D

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions