void Switch() { uint8 before, after; before = rboot_get_current_rom(); if (before == 0) after = 1; else after = 0; Serial.printf("Swapping from rom %d to rom %d.\r\n", before, after); rboot_set_current_rom(after); Serial.println("Restarting...\r\n"); System.restart(); }
// for test void serialCallBack(Stream& stream, char arrivedChar, unsigned short availableCharsCount) { if (arrivedChar == 's') { // Reboot in operation mode rboot_set_current_rom(0); Serial.println("Restarting..."); System.restart(); } }
void otaUpdate_CallBack(bool result) { Debug.println("In OTA callback..."); if(result == true) { // success uint8 slot; slot = rboot_get_current_rom(); if (slot == 0) slot = 1; else slot = 0; #ifndef DISABLE_SPIFFS Debug.printf("Firmware updated, storing AppSettings to new spiffs...\r\n"); AppSettings.load(); spiffs_unmount(); if (slot == 0) { #ifdef RBOOT_SPIFFS_0 Debug.printf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE); spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE); #else Debug.printf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE); spiffs_mount_manual(0x40300000, SPIFF_SIZE); #endif } else { #ifdef RBOOT_SPIFFS_1 Debug.printf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE); spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE); #else Debug.printf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE); spiffs_mount_manual(0x40500000, SPIFF_SIZE); #endif } AppSettings.save(); #else Debug.printf("spiffs disabled"); #endif // set to boot new rom and then reboot Debug.printf("Firmware updated, rebooting to rom %d...\r\n", slot); rboot_set_current_rom(slot); System.restart(); } else { // fail Debug.println("Firmware update failed!"); if (numOtaTrials < 6) StartOtaUpdate(); else numOtaTrials = 0; } }
void rBootHttpUpdate::applyUpdate() { timer.stop(); items.clear(); if (romSlot == NO_ROM_SWITCH) { debugf("Firmware updated."); if (updateDelegate) updateDelegate(true); } else { // set to boot new rom and then reboot debugf("Firmware updated, rebooting to rom %d...\r\n", romSlot); rboot_set_current_rom(romSlot); System.restart(); } return; }
void OtaUpdate_CallBack(bool result) { Serial.println("In callback..."); if(result == true) { // success uint8 slot; slot = rboot_get_current_rom(); if (slot == 0) slot = 1; else slot = 0; // set to boot new rom and then reboot Serial.printf("Firmware updated, rebooting to rom %d...\r\n", slot); rboot_set_current_rom(slot); System.restart(); } else { // fail Serial.println("Firmware update failed!"); } }
irom app_action_t application_function_ota_commit(const string_t *src, string_t *dst) { if(ota_state != state_successful) { string_cat(dst, "OTA: no candidate for commit\n"); ota_state = state_inactive; return(app_action_error); } if(!rboot_set_current_rom(flash_slot)) { string_format(dst, "OTA: set current slot to %d failed\n", flash_slot); ota_state = state_inactive; return(app_action_error); } return(app_action_ota_commit); }
/** * @brief Callback after an ota is done * * @param[in] result Tells whether an OTA is successful or not */ void ota_onUpdate(bool result) { PRINTF_INFO("OTA Update Callback..."); if(result == true) { // success uint8 slot; slot = rboot_get_current_rom(); if (slot == 0) slot = 1; else slot = 0; // set to boot new rom and then reboot PRINTF_INFO("Firmware updated, rebooting to rom %d...\r\n", slot); rboot_set_current_rom(slot); System.restart(); } else { // fail PRINTF_ERR("Firmware update failed!\n"); } }
void init() { Serial.begin(SERIAL_BAUD_RATE); // 115200 by default Serial.systemDebugOutput(true); // Debug output to serial //commandHandler.registerSystemCommands(); // Enable rboot in makefile! int slot = rboot_get_current_rom(); Serial.printf("\r\nCurrently running rom %d.\r\n", slot); if (!digitalRead(SWITCH_PIN)) { // Reboot in operation-mode rboot_set_current_rom(0); Serial.println("Restarting..."); System.restart(); } pinMode(GREEN_LED_PIN, OUTPUT); pinMode(RED_LED_PIN, OUTPUT); pinMode(SWITCH_PIN, INPUT); WifiStation.enable(true); WifiStation.enableDHCP(true); WifiAccessPoint.enable(false); configMode = false; smartConfigActive = false; debounceTimer.initializeMs(1200, debounceReset); configTimer.initializeMs(1000, switchDelay); attachInterrupt(SWITCH_PIN, switchPressed, RISING); setConfigMode(true); }
void setConfigMode(bool on) { if (on) { configMode = true; blinkGreenStart(500, -1); // start smart-config xTaskCreate(smartconfig_task, (const signed char* ) "smartconfig_task", 256, NULL, 2, NULL); smartConfigActive = true; } else { configMode = false; blinkStop(); smartconfig_stop(); smartConfigActive = false; WifiStation.waitConnection(connectOk, 10, connectFail); // Reboot in operation mode rboot_set_current_rom(0); Serial.println("Restarting..."); System.restart(); } }