Skip to content

Add partition label argument to Update and ArduinoOTA class #4442

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
Nov 2, 2020
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
16 changes: 14 additions & 2 deletions libraries/ArduinoOTA/src/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ ArduinoOTAClass& ArduinoOTAClass::setPasswordHash(const char * password) {
return *this;
}

ArduinoOTAClass& ArduinoOTAClass::setPartitionLabel(const char * partition_label) {
if (!_initialized && !_partition_label.length() && partition_label) {
_partition_label = partition_label;
}
return *this;
}

String ArduinoOTAClass::getPartitionLabel() {
return _partition_label;
}

ArduinoOTAClass& ArduinoOTAClass::setRebootOnSuccess(bool reboot){
_rebootOnSuccess = reboot;
return *this;
Expand Down Expand Up @@ -235,7 +246,8 @@ void ArduinoOTAClass::_onRx(){
}

void ArduinoOTAClass::_runUpdate() {
if (!Update.begin(_size, _cmd)) {
const char *partition_label = _partition_label.length() ? _partition_label.c_str() : NULL;
if (!Update.begin(_size, _cmd, -1, LOW, partition_label)) {

log_e("Begin ERROR: %s", Update.errorString());

Expand Down Expand Up @@ -358,7 +370,7 @@ void ArduinoOTAClass::end() {

void ArduinoOTAClass::handle() {
if (!_initialized) {
return;
return;
}
if (_state == OTA_RUNUPDATE) {
_runUpdate();
Expand Down
5 changes: 5 additions & 0 deletions libraries/ArduinoOTA/src/ArduinoOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ArduinoOTAClass
//Sets the password as above but in the form MD5(password). Default NULL
ArduinoOTAClass& setPasswordHash(const char *password);

//Sets the partition label to write to when updating SPIFFS. Default NULL
ArduinoOTAClass &setPartitionLabel(const char *partition_label);
String getPartitionLabel();

//Sets if the device should be rebooted after successful update. Default true
ArduinoOTAClass& setRebootOnSuccess(bool reboot);

Expand Down Expand Up @@ -80,6 +84,7 @@ class ArduinoOTAClass
int _port;
String _password;
String _hostname;
String _partition_label;
String _nonce;
WiFiUDP _udp_ota;
bool _initialized;
Expand Down
2 changes: 1 addition & 1 deletion libraries/Update/src/Update.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UpdateClass {
Call this to check the space needed for the update
Will return false if there is not enough space
*/
bool begin(size_t size=UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW);
bool begin(size_t size=UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL);

/*
Writes a buffer to the flash and increments the address
Expand Down
4 changes: 2 additions & 2 deletions libraries/Update/src/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool UpdateClass::rollBack(){
return _partitionIsBootable(partition) && !esp_ota_set_boot_partition(partition);
}

bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, const char *label) {
if(_size > 0){
log_w("already running");
return false;
Expand Down Expand Up @@ -132,7 +132,7 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
log_d("OTA Partition: %s", _partition->label);
}
else if (command == U_SPIFFS) {
_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, label);
if(!_partition){
_error = UPDATE_ERROR_NO_PARTITION;
return false;
Expand Down