Running Stage(s)

The majority of the device logic is written in the running state(s). These stages must return a payload to be sent to the server.

The core of your device logic can be divided into different parts through its lifecycle. We can use multiple running stages to partition the device simulation into logical segments.

For Example, if we are trying to simulate a smart lock, we could have a booting stage that simulates how the device behaves when being switched on, then we could have an online stage that defines how the device behaves under normal working conditions and finally we could have an offline stage which simulates how the device would behave without a network condition and so on.

Partitioning the device logic into multiple such stages makes it easier for others to understand the device logic and also help while troubleshooting any issues that may arise while running a functional test for the device. There is no limit to the number of such stages that can be created. Let's see how to work with these different stages.

To add a new stage to the Device Model, move your mouse over the line between the stages where you want to add the new stage, a plus button will appear. On clicking this plus button, a new stage will be created. A new stage can be created anywhere between the Init and the Finished stages, but not outside them.

To rename any of the stages, click on their names, a text field will appear and you can rename the stages.

To delete any stage, move your mouse to the icon above the stage you want to delete, a cross icon will appear. On clicking the cross icon, the stage will be deleted.

To transition to another stage from a given stage use the next() function. If the next() function takes the name of any stage as the parameter. If no parameter is supplied to the next() function it will transition to the next stage on the timeline.

{
    let serial = glob.get('serial_' + client());
    if (!serial)
    {
        serial = chance.guid();
        glob.set('serial_' + client(), serial);
    }
    state.serial = serial;  
  
    next() //Transitions to the next stage on the timeline
    //Or
    next("Other_Stage") //Transitions to the given stage
}

Last updated