Init Stage
Initialise the devices and add default values
The init stage is where the device initialisation happens. This stage is invoked with an empty state object. Use this stage to populate different parameters that the device will use in its lifetime. It is also a good place to set up device credentials or to configure some external resources. An example of an Init stage is given below.

init(state)

{
let serial = glob.get('serial_' + client());
if (!serial) //if serial is not found, then create one
{
serial = chance.guid();
glob.set('serial_' + client(), serial);
}
state.serial = serial;
next();
}
As a result of this code, each of your clients will be assigned a unique serial number which will remain persistent throughout all of the simulations. You could always delete the DBStore entries or modify them.
Note that the Init stage is invoked before the connection is made to your backend server. This is an ideal place to setup any device credentials or set the server settings.
The Init stage does not need to return a value.
Copy link