Skip to content
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

How to update without restarting the device #170

Closed
JoseAntonioMG opened this issue Dec 15, 2023 · 3 comments · Fixed by #180
Closed

How to update without restarting the device #170

JoseAntonioMG opened this issue Dec 15, 2023 · 3 comments · Fixed by #180

Comments

@JoseAntonioMG
Copy link

Device used: Esp32
IDE: Arduino IDE
Description: I can only run the OTA update when restarting the device. How can I check ThingsBoard if there is a new update and, if so, update without having to restart the device?

Thanks.

@MathewHDYT
Copy link
Contributor

Which example did you use, because the folder contains two OTA examples with different behaviour for the ESP32 on Arduino.

Process OTA MQTT, where we have to check ourselves if an update was requested.

Subscribe OTA MQTT, where we receive a callback if an update was requested.

So from what you wrote I think you need to have a look at the latter of the two examples. Additionally the final restart at the end of the update is non optional and has to be done always, to actually switch the current loaded firmware.

@JoseAntonioMG
Copy link
Author

I am using the Process_OTA_MQTT method, where in the description it is commented that it is "immediate", however subscribe_OTA_MQTT, it is specified that it is "Not immediate".
I understand that after updating it is necessary to restart the device, but this is supposed to happen automatically, without human intervention. I mean that Process_OTA_MQTT can only be activated if the device has been manually restarted, or in any case, schedule a daily restart to update.

@MathewHDYT
Copy link
Contributor

I think there is a misunderstanding.

The Start_Firmware_Update method used in the Process OTA MQTT example, is meant for devices that check themselves if an update is assigned to the given device on ThingsBoard. If it is the update is started, however for every check that is done the Start_Firmware_Update method has to be recalled.

This is not the case with the Subscribe_Firmware_Update method used in the Subscribe OTA MQTT example. Here you subscribe once to the assignment of any firmware, but if new firmware is assigned already the update will not start immediately. Instead it will only start if the device is active (turned on and connected) and an assignment is registered.


The most common use case is calling Start_Firmware_Update, when a device starts and then subscribing to future changes with Subscribe_Firmware_Update.

I understand that after updating it is necessary to restart the device, but this is supposed to happen automatically, without human intervention

In the examples it should, if the example is used it calls esp_restart(); in the updatedCallback if the update was successful. However this is not done in the library directly but has to be done by the user, because every supported device needs to restart differently and call different methods.

I mean that Process_OTA_MQTT can only be activated if the device has been manually restarted, or in any case, schedule a daily restart to update

If you are using the Process OTA MQTT example it calls Start_Firmware_Update once and will not call it again if the call was successful. This is done because polling the firmware update every X seconds is very CPU intensive. However if you want to do that you can simply adjust the example like this.

...
if (!updateRequestSent) {
    ...
    tb.Start_Firmware_Update(callback);
    updateRequestSent = false;
}
...

This is not recommended however. If you want to update once the firmware has been assigned in the cloud the Subscribe_Firmware_Update is "immediate" as well. Immediate in the previous context just meant that unlike Start_Firmware_Update the Subscribe_Firmware_Update method does not start the update, if there is firmware assigned already, but instead waits until it registers that the firmware changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants