How to: Do Simulation

The guide demonstrates how to create expressions that generate a sinusoidal signal and a saw signal for simulation and testing purposes.

Open Monokot Server Administrator and double-click Scripts on the Server Explorer pane. Click New Expression and set the name Sin for the expression that appears. Insert the following code into the expression code editor:

// "token" is a property in which you can put a custom value that 
// will be available during the next code execution
context.token += 0.1;

var value = Math.sin(context.token) * 50;
return value;

Go to the Triggers tab and click Add Periodic. Now, we have created an expression that will be executed every 500 ms.

In the same way, create a second expression named Saw and specify a periodic trigger for it, but to simulate the saw signal, use the following code:

// default, token is null
if (context.token == null)
    context.token = 0;
else context.token += 1;

if (context.token > 50)
    context.token = -50;

var value = context.token;
return value;

In order for the changes to take effect on the server, click the Sync button. Now, if you write the data (for example, in InfluxDB) generated by these expressions, you will see something similar as in the figure below:

Last updated