Skip to content

Add OTA type to onStart callback #2259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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