Description
i_update_confirm()
confirms the successful update of the new application. This means the bootloader will cancel any further update configurations (e.g. no fall back to a previous application). In order to check if the bootloader is currently configured to do any system updates use b_update_is_bootloader_command_pending()
.
Syntax
i_update_confirm();
b_update_is_bootloader_command_pending();
Parameters
none
Returns
i_update_confirm returns:
int: 0 : OK
b_update_is_bootloader_command_pending returns:
bool:
true – an update is configured in the bootloader settings, the next system start will flash a new application from SerialFlash
false – no update pending.
Example Code
#include "Update.h"
#include "FileTransfer.h"
void setup()
{
SerialFlash.begin();
while(!Serial);
Serial.print("Current app. version:");
Serial.println(" V" + String(BOOTLOADER_SETTING.u32_get_app_version()));
if(b_update_is_bootloader_command_pending())
{
// Do some checks here (e.g. does a server connection work etc.)
Serial.println("There is a fall back pending");
Serial.println("Confirm the update process");
i_update_confirm();
}
}
void loop()
{
int i_Ret = 0;
SerialFlashFile appFile;
appFile = SerialFlash.open("ConfirmUpdate.ino.bin");
if(appFile)
{
Serial.println("ConfirmUpdate.ino.bin exists");
if(appFile.size() == 0)
Serial.println("but is empty - invalid -");
else
{
Serial.println("File version: V"+String( appFile.getVersion()));
if(BOOTLOADER_SETTING.u32_get_app_version() >= appFile.getVersion())
{
Serial.println("Current application >= the file.");
Serial.println("Erasing the file");
appFile.erase();
}
else
{
if(!i_update_recover("ConfirmUpdate.ino.bin"))
Serial.println("Error. Preparing update");
else
{
Serial.println("OK - Update is prepared.\n - Now restart the system -");
while(1){ yield(); };
}
}
}
appFile.close();
}
Serial.println("Waiting for the PC to send: ConfirmUpdate.ino.bin");
do
{
i_Ret = i_FileTrans_ReceiveFile(&Serial, &SerialFlash, 0, "ConfirmUpdate.ino.bin");
} while( i_Ret != 1 );
Serial.println("OK. Update file received");
}
Notes and Warnings
Make sure that the new application is compiled for the right target hardware variant and of type .bin (binary application file). A binary can be created and exported with the help of the Arduino IDE (see menu):
– Sketch -> Export compiled Binary
– Sketch -> Show Sketch folder
The function i_update_recover() creates / replaces the binary file called “recover.bin” in the SerialFlash file system.
FYI: i_update_recover() basically uses i_update_create_image() to create “recover.bin” and then calls i_update( “recover.bin”, “newApp.bin” );
See also
SerialFlash – see getVersion()
BOOTLOADER SETTINGS – Library – see u32_get_app_version()