Skip to content

Commit 898b9fe

Browse files
committed
added event usage docs in readme
updated example
1 parent e03c1dc commit 898b9fe

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ It will provide a webpage for updating the firmware/filesystem of `ESP8266` or `
3737
- Update credentials customization (default: `No credentials`)
3838
- Username
3939
- Password
40+
- Update Events:
41+
- onUpdateBegin
42+
- onUpdateEnd
43+
- Force Aborting Update using events
4044
- FileSystem Options:
4145
- SPIFFS
4246
- LittleFS
@@ -60,25 +64,44 @@ This Library is available in `Arduino Library Repository` and `PIO` and you can
6064
```
6165
2. Create an object from `ESPAsyncHTTPUpdateServer`
6266
``` C++
63-
ESPAsyncHTTPUpdateServer _updateServer;
64-
AsyncWebServer _server(80);
67+
ESPAsyncHTTPUpdateServer updateServer;
68+
AsyncWebServer server(80);
6569
```
6670
3. Setup the update server before starting the webServer
6771
``` C++
68-
_updateServer.setup(&_server);
69-
_server.begin();
72+
updateServer.setup(&server);
73+
server.begin();
7074
```
7175
#### Custom Route
7276
``` C++
73-
_updateServer.setup(&_server, "/customroute");
77+
updateServer.setup(&server, "/customroute");
7478
```
7579
#### Credentials
7680
``` C++
77-
_updateServer.setup(&_server, "username", "password");
81+
updateServer.setup(&server, "username", "password");
7882
```
7983
or
8084
``` C++
81-
_updateServer.setup(&_server, "/customroute", "username", "password");
85+
updateServer.setup(&server, "/customroute", "username", "password");
86+
```
87+
#### Events
88+
```c++
89+
updateServer.onUpdateBegin = [](const UpdateType type, int &result)
90+
{
91+
//...
92+
};
93+
94+
updateServer.onUpdateEnd = [](const UpdateType type, int &result)
95+
{
96+
//...
97+
};
98+
```
99+
#### Aborting the update
100+
```c++
101+
updateServer.onUpdateBegin = [](const UpdateType type, int &result)
102+
{
103+
result = UpdateResult::UPDATE_ABORT;
104+
};
82105
```
83106

84107
### Styling and Customizing OTA Page

examples/simple_server/simple_server.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ void setup() {
4848

4949
//setup the updateServer with credentials
5050
updateServer.setup(&server, "admin", "admin");
51+
//hook to update events if you need to
52+
updateServer.onUpdateBegin = [](const UpdateType type, int &result)
53+
{
54+
//you can force abort the update like this if you need to:
55+
//result = UpdateResult::UPDATE_ABORT;
56+
Serial.println("Update started : " + String(type));
57+
};
58+
updateServer.onUpdateEnd = [](const UpdateType type, int &result)
59+
{
60+
Serial.println("Update finished : " + String(type) + " result: " + String(result));
61+
};
62+
5163
server.begin();
5264
}
5365

0 commit comments

Comments
 (0)