File distribution with templating

How to automate edge device production roll-out with individual differences?

In many IoT device management scenarios a huge number of embedded devices need to be controlled. But for one reason or another they are mostly similar, but not 100% identical. In this case it is very convenient to have a mechanism that can introduce slight configuration differences based on device group membership. A typical example is that localization options need to be implemented or that different locations have different Wifi credentials. All this can easily be addressed with qbee templating.

With file distribution it is easy to play out files. It can be selected to which individual device or group of edge devices a file is played out. But sometimes it can be useful to be able to adopt the file according to which group it is distributed to. Let's assume I have a file that should contain a text with a personalized greeting according to which group the device belongs to.

So a hello.txt file looks like this:

    Hello World,
    How are you?

Now there is a device tree with three groups each containing devices:

-> All devices
    -> Oslo
    -> Berlin
    -> London

Now we can use key-value templating on the original file by using Mustache notation with double curly brackets and save the original text file as a template file called hello.tmpl (the name is freely selectable):

    Hello {{city}},
    How are you?

Then we go into file distribution and define that the template (which needs to be uploaded to the file manager) is distributed to the device into the home folder as hello.txt. In addition the "Template" function is checked which allows to define key-value paramters. In this case we use "Oslo" as the value for the key "city"

basic templating

With the next qbee agent run the file hello.txt will be on all devices in the Oslo group with the following text:

    Hello Oslo,
    How are you?

Any time the value is changed the file gets rewritten with the new value expanded in the file. The same can be done with different names for the other groups. Please note that the key template file is the same for all three groups. Only the key value pair will change according to group. The value can also be delivered through the qbee API coming from a third party system.

How can this be useful?

This can be used to define configuration in configuration files (for example IP addresses or any other parameter). It can also be used to control scripts in different ways. Please see here for learning how to run a script once or here how to control script parameters. A typical way of using this to define a config file based on group membership can be seen in this example. This uses software management instead of file distribution but the templating works in exactly the same way.

How to use command-to-run?

Any time a new file is created on the device the command to run is called (if there is anything there). This means that the qbee agent triggers this any time there is a change in the key value pairs. This can be used for a lot of things as described above.