When you work with several YoctoHubs, it's tiresome to have to configure network parameters and HTTP callbacks every time. This week, we are going to see how to copy the configuration of a YoctoHub onto another YoctoHub with the command line.
Our command line API enables us to interact with all our modules from a terminal. Parameters are passed on the command line and the result is displayed on the standard output.
The result of the command is displayed with a "OK: XXX.YYY = " prefix. XXX corresponds to the module identifier and YYY to the command which was run. This enables us to check whether all the operations went well.
For example, to switch all the relays to the B state during one second, we use the YRelay command and we give it as arguments all, pulse, and 1000:
OK: RELAYLO1-27EAB.relay2.pulse = 1000.
OK: RELAYLO1-27EAB.relay1.pulse = 1000.
To clone the configuration of a YoctoHub, you must use the get_allSettings and set_allSettingsAndFiles commands of the YModule tool. But instead of displaying the results of this first command, you must save them in a file in order to apply them later on.
Saving the configuration parameters
The get_allSettings command returns all the configuration parameters of the module, including files potentially uploaded on the YoctoHub.
By default, these parameters are displayed on the standard output. To redirect the result of this command into a file, there are two options:
- Using the -o option
- Redirecting the terminal output with the '>' character
Saving the parameters in a file with the -o option
The global -o option enables you to specify the name of a file into which the result of the command is saved. Only the result of the command is saved in the file, the "OK: XXX.YYY = " prefix is still displayed on the terminal.
So, to save the configuration parameters of the YoctoHub-Ethernet YHUBETH1-14AC00 in a mySettings.dat file, the command is:
If there already is a file with this name, it is overwritten. You can however modify this behavior and add the result at the end of the file by adding a + at the beginning of the filename.
Saving the parameters in a file with redirection
The other option is to use redirection of the terminal input/output. This option redirects everything which is displayed by the command, including the "OK: XXX.YYY = " prefix. To obtain only the parameters, you must modify this prefix with the -f option.
The -f option specifies the display format of the command result. The default format is 'OK: [identifierOrName].[command] = [result].'. When executing, the parts between the square brackets are replaced by the corresponding data. Thus, to display only the result of the command, you must use the '[result]' string.
The command to obtain only the configuration parameters of the YoctoHub-Ethernet YHUBETH1-14AC00 in the mySettings.dat file is:
Applying the configuration parameters
The set_allSettingsAndFiles command applies all the configuration parameters and files on a module, and uploads potential custom files.
For the command to use the content of the file you have just created, you must use the file: prefix followed by the file name.
Here is the command to apply to all the connected modules the parameters that we have saved above:
Note that we added the --save option. This option saves the configuration parameters that we just now applied in the flash memory of the module. Without this option, the parameters would have been applied in the same manner, but they would be lost after the first reboot of the module.
As said above, these two commands are very useful to clone the configuration of a YoctoHub, but not only that: you can use these same two commands on any Yoctopuce module. You can for example use these commands to save the calibration performed on a Yocto-MaxiThermistor.