Skip to content

Commit

Permalink
Add getCommand() api for OTA update type (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored and me-no-dev committed Jul 15, 2016
1 parent 1f7989b commit c4f9f10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void ArduinoOTAClass::_onRx(){
nonce_md5.add(String(micros()));
nonce_md5.calculate();
_nonce = nonce_md5.toString();

char auth_req[38];
sprintf(auth_req, "AUTH %s", _nonce.c_str());
_udp_ota->append((const char *)auth_req, strlen(auth_req));
Expand Down Expand Up @@ -326,4 +326,8 @@ void ArduinoOTAClass::handle() {
}
}

int ArduinoOTAClass::getCommand() {
return _cmd;
}

ArduinoOTAClass ArduinoOTA;
1 change: 1 addition & 0 deletions libraries/ArduinoOTA/ArduinoOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ArduinoOTAClass
void onProgress(THandlerFunction_Progress fn);
void begin();
void handle();
int getCommand(); // get update command type after OTA started- either U_FLASH or U_SPIFFS

private:
int _port;
Expand Down
9 changes: 8 additions & 1 deletion libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ void setup() {
// ArduinoOTA.setPassword((const char *)"123");

ArduinoOTA.onStart([]() {
Serial.println("Start");
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";

// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
Expand Down

0 comments on commit c4f9f10

Please sign in to comment.