New tools to update your modules

By Sébastien Rinsoz, in Programming, december 05,2014.

Until now, the only way to update a Yoctopuce module was to use the VirtualHub. Since version 18640 of our libraries, you can update your module firmware with the Yoctopuce libraries. We also published an Android application enabling you to update your modules. Let's have a look at these new ways of updating.

The new updating tools

If you simply want to update your modules without coding, you can use command line tools or our Android application.

The command line library

All the command line tools can now update Yoctopuce modules thanks to the downloadAndUpdate command. The module selection mechanism works like for a traditional command. The [target] is the name of the module that you want to update. You can also use the "any" or "all" aliases, or even a name list, where the names are separated by commas, without spaces.

C:\>Executable[options][target]command[parameters]

The following example updates all the Yoctopuce modules connected by USB.

C:\>YModule all downloadAndUpdate
ok: Yocto-PowerRelay RELAYHI1-266C8(rev=15430) is up to date.ok: 0 / 0 hubs in 0.000000s.ok: 0 / 0 shields in 0.000000s.ok: 1 / 1 devices in 0.130000s 0.130000s per device.ok: All devices are now up to date.C:\>

The Android application Yocto-Firmware

You can update your module firmware from your Android phone or tablet with the Yocto-Firmware application. This application lists all the Yoctopuce modules connected by USB and checks if a more recent firmware is available on www.yoctopuce.com. If a more recent firmware is available, you can update the module. The application is responsible for downloading and installing the new firmware while preserving the module parameters.

Please note: while the firmware is being updated, the module restarts several times. Android interprets a USB device reboot as a disconnection and reconnection of the USB device and asks the authorization to use the USB port again. The user must click on OK for the update process to end successfully.

Screenshots of the Yocto-Friwmare application

Updating the firmware with the programming library

If you need to integrate firmware updates in your application, the libraries offer you an API to update your modules. Note: the JavaScript, Node.js, and PHP libraries do not yet allow you to update the modules. These functions will be available in the next build.

Saving and restoring parameters

The get_allSettings() method returns a binary buffer enabling you to save a module persistent parameters. This function is very useful to save the network configuration of a YoctoHub for example.

Finding the correct firmware

The first step to update a Yoctopuce module is to find which firmware you must use. The checkFirmware(path, onlynew) method of the YModule object does exactly this. The method checks that the firmware given as argument (path) is compatible with the module. If the onlynew parameter is set, this method checks that the firmware is more recent than the version currently used by the module. When the file is not compatible (or if the file is older than the installed version), this method returns an empty string. In the opposite, if the file is valid, the method returns a file access path.

The following piece of code checks that the c:\tmp\METEOMK1.17328.byn is compatible with our module.

The argument can be a directory (instead of a file). In this case, the method checks all the files of the directory recursively and returns the most recent compatible firmware. The following piece of code checks whether there is a more recent firmware in the c:\tmp\ directory.

You can also give the "www.yoctopuce.com" string as argument to check whether there is a more recent published firmware on our web site. In this case, the method returns the firmware URL. You can use this URL to download the firmware on your disk or use this URL when updating the firmware (see below). Obviously, this possibility works only if your machine is connected to Internet.

Updating the firmware

A firmware update can take several minutes. Therefore, the update process is run as a background task and is driven by the user code thanks to the YFirmwareUdpate class.

To update a Yoctopuce module, you must obtain an instance of the YFirmwareUdpate class with the updateFirmware method of a YModule object. The only parameter of this method is the path of the firmware that you want to install. This method does not immediately start the update, but returns a YFirmwareUdpate object configured to update the module.

The startUpdate() method starts the update as a background task. This background task automatically takes care of

saving the module parameters

restarting the module in "update" mode

updating the firmware

starting the module with the new firmware version

restoring the parameters

The get_progress() and get_progressMessage() methods enable you to follow the progression of the update. get_progress() returns the progression as a percentage (100 = update complete). get_progressMessage() returns a character string describing the current operation (deleting, writing, rebooting, ...). If the get_progress method returns a negative value, the update process failed. In this case, the get_progressMessage() returns an error message.

The following piece of code starts the update and displays the progress on the standard output.

Conclusion

As you can see, we did everything we could to make the life of developers easier. However, if your application is interrupted during the update process, the module can stay stuck in "update" mode and the parameters are then lost. As a safety measure, we recommend to always save the module important parameters before an update.