Init Function

Describe the behavior of device initialization

Init function is where your device initialization happens. The function is invoked with an empty state object. Use this function to populate state fields to be used later. It could also be used to setup device credentials or configure some external resources. Here is an example of init function

function 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;

As a result of this code, each of your client 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 Init function 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.

Init function doesn't need to return a value.