If you are trying to implement OTA functionality for your ESP32 / ESP8266 with AP Wifi Mode enabled, try this simple Arduino Library:
Library link: Github Repository
You can also install the library directly from Arduino IDE. Just click on Library Manager and search for ESP2SOTA
By installing the library, two code samples will be available, one for AP Mode and the other one for Client Mode
Sample sketch:
#include <WiFi.h>
#include <WiFiAP.h>
#include <WebServer.h>
/* INCLUDE ESP2SOTA LIBRARY */
#include <ESP2SOTA.h>
const char* ssid = "ESP2SOTA";
const char* password = "123456789abc";
WebServer server(80);
void setup(void) {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, password);
delay(1000);
IPAddress IP = IPAddress (10, 10, 10, 1);
IPAddress NMask = IPAddress (255, 255, 255, 0);
WiFi.softAPConfig(IP, IP, NMask);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
/* SETUP YOR WEB OWN ENTRY POINTS */
server.on("/myurl", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", "Hello there!");
});
/* INITIALIZE ESP2SOTA LIBRARY */
ESP2SOTA.begin(&server);
server.begin();
}
void loop(void) {
/* HANDLE UPDATE REQUESTS */
server.handleClient();
/* YOUR LOOP CODE HERE */
delay(5);
}
It’s perfect but where is the part of program with firmware update (ESP self sufficient OTA – look at pictite above)?
There is a AP_Mode.ino file in Example folder, but there is only basic AP without code for firmware load and update.
Thanks in advance for the reply.
Hola Alberto,
your library promises to solve one problem I wanted to have solved since long time. As I often use the ESP8266, I modified your AP example for it. But when compiling it, I get an error message which seems to be a problem in the library:
C:\Users\…\Arduino\libraries\ESP2SOTA\src\ESP2SOTA.cpp: In lambda function:
C:\Users\…\Arduino\libraries\ESP2SOTA\src\ESP2SOTA.cpp:29:25: error: ‘UPDATE_SIZE_UNKNOWN’ was not declared in this scope
29 | if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
| ^~~~~~~~~~~~~~~~~~~
Compilation will be terminated with this.
I hope, there will be a solution 🙂
// The only changes made to the AP example code are these 4 lines (added “ESP8266” 3 times, commented out WiFiAP.h):
#include
//#include
#include
ESP8266WebServer server(80);
Berst Regards
Reiner
Thanks so much for this, In the past I have used Elegant, but I really needed a solution for an esp32 in a box with no access to usb and no WiFi, thanks this is just brilliant! Much appreciated!
Pete
Thank you very much for your words Pete!!!!!