Saving module configuration with the command line

Saving module configuration with the command line

Once you've had a taste of Yoctopuce modules, it's not uncommon to find systems consisting of a dozen or so modules. When all these modules are installed and configured correctly, it's a good idea to save their configuration, in case you make a mistake. We've just added two commands to our command line library that simplify this operation.

Before discussing this new feature, you should remember that it was already possible to automate the saving and restoring of Yoctopuce module configuration using one of our programming libraries. But it was up to the user to write the few lines of code required.

To make life easier for our users, we decided to add two new commands to the YModule executable of our cmdline library.

Note: if you've never used the YModule tool, you can read the post explaining how our library works from the command line. The rest of the post will be easier to understand.

The saveConfig command

The first command we've added to the YModule executable is saveConfig. As its name suggests it, this function saves the module's complete configuration. This includes logical names, calibrations and uploaded files, as well as all persistent module parameters.

This command follows the same conventions as the other commands. That is, the first parameter is the identifier of the module you wish to use. Alternatively, the keyword all can be used to apply the command to all detected modules. Like the other commands, the -r option allows you to connect to VirtualHub or to a remote YoctoHub instead of the USB port.

The saveConfig command requires an additional argument in the form of an output directory. At runtime, the saveConfig command creates a JSON file for each module, containing its complete configuration. The filename used is the serial number followed by the .json extension.

In the following example, we save the configuration of all modules connected to the YoctoHub-Wireless-n in the backup directory.

YModule.exe -r all saveConfig backup
ok: Yocto-Meteo-V2 METEOMK2-114F07 settings are saved to backup\METEOMK2-114F07.json file.
ok: Yocto-MaxiDisplay YD128X64-1D105E settings are saved to backup\YD128X64-1D105E.json file.
ok: YoctoHub-Wireless-n YHUBWLN4-1FBDF4 settings are saved to backup\YHUBWLN4-1FBDF4.json file.

The restoreConfig command

The restoreConfig command is the opposite of saveConfig. This command restores the module's complete configuration (parameters + files) from a JSON file created by the saveConfig command.

The restoreConfig command also has a mandatory parameter which is the directory in which all saved files are stored. On execution, the command browses the directory and uses the file corresponding to the serial number of the current module.

Unlike other commands, it is not necessary to use the --save option. Indeed, the restoreConfig command implicitly calls the saveToFlash function so that the modified parameters are saved in a persistent way in the flash memory.

The following example restores the configurations we saved earlier.

YModule.exe -r all restoreConfig ./backup
ok: Yocto-Meteo-V2 METEOMK2-114F07 settings are restored from ./backup\METEOMK2-114F07.json file.
ok: Yocto-MaxiDisplay YD128X64-1D105E settings are restored from ./backup\YD128X64-1D105E.json file.
ok: YoctoHub-Wireless-n YHUBWLN4-1FBDF4 settings are restored from ./backup\YHUBWLN4-1FBDF4.json file.

Note that if only one module is targeted, it is also possible to directly pass the file

YModule.exe -r METEOMK2-114F07 restoreConfig ./backup/METEOMK2-114F07.json
ok: Yocto-Meteo-V2 METEOMK2-114F07 settings are restored from ./backup\METEOMK2-114F07.json file.

Advanced uses

By default, restoreConfig checks that the JSON file passed as an argument is valid for the targeted module. In other words, the application checks that the product name saved in the file is identical to the product name of the targeted module. There are, however, cases where you might want to be able to apply backups to different modules.

For example, when modifying an installation to replace a Yocto-PowerRelay-V2 with a Yocto-PowerRelay-V3. Apart from the technical characteristics of the relay, these two modules operate in the same way. It may be useful to be able to restore the configuration parameters of a Yocto-PowerRelay-V2 on a Yocto-PowerRelay-V3.

This is made possible by using true for the additional parameter force:

YModule RELAYHI3-1A88CB restoreConfig .\backup\RELAYHI3-057B0.json true
WARN: Setting file is not designed for targeted Yocto-PowerRelay-V3 (RELAYHI3-1A88CB)
ok: Yocto-PowerRelay-V3 RELAYHI3-1A88CB settings are restored from ..\backup\RELAYHI1-057B0.json file.


These two new commands have been added to version 55272 of the command line library and are available on our website.

Add a comment No comment yet Back to blog

Yoctopuce, get your stuff connected.