New tools to update your modules

New tools to update your modules

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.

    YWireless wireless = YWireless.FindWireless("reference");
    YModule module = wireless.get_module();
    byte[] default_config =  module.get_allSettings();
    saveFile("default.bin", default_config);
    ...



You can then apply these parameters to other modules with the set_allSettings() method.

    byte[] default_config = loadFile("default.bin");
    YModule module = YModule.FirstModule();
    while (module != null) {
        if (module.get_productName() == "YoctoHub-Wireless") {
            module.set_allSettings(default_config);
        }
        module = module.next();
    }



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.

    YModule module = YModule.FirstModule();
    ...
    ...
    string path = "c:\\tmp\METEOMK1.17328.byn";
    string newfirm = module.checkFirmware(path, false);
    if (newfirm != "") {
        Console.WriteLine("firmware " + newfirm + " is compatible");
    }
    ...


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.

    YModule module = YModule.FirstModule();
    ...
    ...
    string path = "c:\\tmp";
    string newfirm = module.checkFirmware(path, true);
    if (newfirm != "") {
        Console.WriteLine("firmware " + newfirm + " is compatible and newer");
    }
    ...



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.

    YModule module = YModule.FirstModule();
    ...
    ...
    string url = module.checkFirmware("www.yoctopuce.com", true);
    if (url != "") {
        Console.WriteLine("new firmware is available at " + url );
    }
    ...



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.

    string newfirm = module.checkFirmware("www.yoctopuce.com", true);
    .....
    YFirmwareUpdate fw_update = module.updateFirmware(newfirm);



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

  1. saving the module parameters
  2. restarting the module in "update" mode
  3. updating the firmware
  4. starting the module with the new firmware version
  5. 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.

YFirmwareUpdate fw_update = module.updateFirmware(newfirm);
....
int status = fw_update.startUpdate();
while (status < 100 && status >= 0) {
    int newstatus = fw_update.get_progress();
    if (newstatus != status) {
        Console.WriteLine(status + "% "
            + fw_update.get_progressMessage());
    }
    YAPI.Sleep(500, ref errmsg);
    status = newstatus;
}

if (status < 0) {
    Console.WriteLine("Firmware Update failed: "
        + fw_update.get_progressMessage());
} else {
    Console.WriteLine("Firmware Updated Successfully!");
}



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.




1 - shelendra Saturday,may 16,2015 6H29

Tried updating Yoctopuce thermocouple module using android app ( from google play) got an error saying update the hub first

2 - martinm (Yocto-Team)Monday,may 18,2015 19H09

We'll have a look at it. Thanks for reporting it.

3 - seb (Yocto-Team)Friday,may 22,2015 7H20

We have released a new version of Yocto-Firmware that should fix this issue. Thanks for the report.

Yoctopuce, get your stuff connected.