Skip to content

Commit c4f9f10

Browse files
andigme-no-dev
authored andcommitted
Add getCommand() api for OTA update type (esp8266#2259)
1 parent 1f7989b commit c4f9f10

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

libraries/ArduinoOTA/ArduinoOTA.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void ArduinoOTAClass::_onRx(){
180180
nonce_md5.add(String(micros()));
181181
nonce_md5.calculate();
182182
_nonce = nonce_md5.toString();
183-
183+
184184
char auth_req[38];
185185
sprintf(auth_req, "AUTH %s", _nonce.c_str());
186186
_udp_ota->append((const char *)auth_req, strlen(auth_req));
@@ -326,4 +326,8 @@ void ArduinoOTAClass::handle() {
326326
}
327327
}
328328

329+
int ArduinoOTAClass::getCommand() {
330+
return _cmd;
331+
}
332+
329333
ArduinoOTAClass ArduinoOTA;

libraries/ArduinoOTA/ArduinoOTA.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ArduinoOTAClass
4040
void onProgress(THandlerFunction_Progress fn);
4141
void begin();
4242
void handle();
43+
int getCommand(); // get update command type after OTA started- either U_FLASH or U_SPIFFS
4344

4445
private:
4546
int _port;

libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ void setup() {
2727
// ArduinoOTA.setPassword((const char *)"123");
2828

2929
ArduinoOTA.onStart([]() {
30-
Serial.println("Start");
30+
String type;
31+
if (ArduinoOTA.getCommand() == U_FLASH)
32+
type = "sketch";
33+
else // U_SPIFFS
34+
type = "filesystem";
35+
36+
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
37+
Serial.println("Start updating " + type);
3138
});
3239
ArduinoOTA.onEnd([]() {
3340
Serial.println("\nEnd");

0 commit comments

Comments
 (0)