- Developing Applications with Oracle Internet of Things Cloud Service
- Use the Oracle IoT Digital Twin Simulator
- Create Simulation Models
- Create a Custom Simulation Model
Create a Custom Simulation Model
Custom simulation models let you customize the simulation of a device model. You can customize attribute values, alerts, and actions. You can also use events, data sources, expressions, and functions.
- On the Simulations page, click Add .
- On the Select an option page, select Custom.
- In the General Settings section, provide the following values:
-
Name: Name for the new simulation model. For example:
My Sensor
. -
Messaging Interval: Determines how frequently the simulator sends data messages. The default interval is every
1000
ms. -
Message Limit: The maximum number of messages a simulator device can send during a simulation. The default value is
0
, which indicates that there is no limit. The simulator sends messages for as long as the simulated device is running.
-
- In the Device Models section, select a device model for Device Model #1.
The simulator model gets the attributes, alerts, and actions from the selected device model. You can add multiple device models.
- (Optional) Under Attributes, customize the attribute simulation for the attributes defined in the selected device model.
You can customize the following fields:
-
Interactive: Select if you want the attribute to appear in the simulated device view attribute list.
-
Display Name: Specify the display label to use for the attribute.
-
Chartable: Select if you want the attribute to appear in the simulated device view data chart.
-
Units: Specify a measurement unit for the attribute. For example: Celsius (C) for temperature.
Leave the field empty if your attribute does not need a measurement unit.
-
Format: Specify the data format for numeric attributes.
For example: The format
#.####
uses four decimal points. The format###
uses three integer digits. -
Initial Value Expression: Specify an expression to initialize the attribute when the simulation starts. The expression can contain constants, values of other attributes, and functions.
For example:
-
You can use the
now()
function to initialize thestartTime
attribute. -
You can use
$temp
to initialize the value ofmintemp
with the value of thetemp
attribute. -
You can use the numeric value
37.391838
to initialize thelatitude
attribute.
-
-
Value Expression: Specify an expression to evaluate the value of the attribute at any given point of time. The expression can contain constants, values of other attributes, and functions.
For example: You can use
Math.max($maxTemp, $temp)
to calculate themaxTemp
attribute. Here,max
is a function of thejava.lang.Math
class in Java, and$maxTemp
and$temp
are attributes.
-
- (Optional) If your device model defines alerts, you can choose to customize the following fields in the Alerts section:
-
Interactive: Select if you want to trigger the alert interactively using a button. Deselect if the alert should be triggered based on a condition.
-
Display Name: Specify the label to use for the interactive alert button. Display Name is enabled only for interactive alerts.
-
Condition Expression: Specify a boolean expression, which defines the condition for triggering the alert. Condition Expression is enabled only for non-interactive alerts.
For example:
$temp >= $maxThreshold
. -
Image: Choose an image to display after the alert is triggered. You can upload the new image in the Images section.
-
Image Time: Specify the time duration, in milliseconds (ms), for which the image is displayed. After the time elapses, the image reverts back to the image corresponding to the current state of the device.
-
Expression: If your device model defines alert fields, then you can specify a value expression for each field.
-
- (Optional) If your device model defines actions, then in the Actions section, click Add Attribute and Add Event to add any additional attributes and events for an action.
-
Attribute Expression: Select the name of an available attribute and specify an expression to set the attribute value.
For example, you can set the
startTime
attribute to the following expression:$action.power ? now() : $startTime.
Here,power
is an action. -
Event Expression: Select the name of an available event and specify a boolean expression to set the event value. A true value turns on the event. A false value turns off the event.
-
- (Optional) In the Events section, click Add New Event to add one or more events for your simulation model. Use events to change the state or mode of your simulator. For example: An event to power off/on the device. You can configure the following fields for each event:
-
Name: Specify a unique identifier for the event.
-
Description: Specify a label for the event switch.
-
Image: Specify an image to display when the event is on.
-
Add Attribute: Click to add an attribute.
-
Attribute Expression: Select an available attribute and specify the expression used to set the attribute value when the event is on.
For example: You can set the
$temp
attribute tosinInRange(60, 80).
You can add multiple attributes for each event.
-
- (Optional) In the Images section, click Add New Image to Upload new image files to be used for events and alerts.
You can also modify the default images for
isOnImage
andisOffImage.
These default images represent the running and stopped states of the device simulator.The following media types are supported:-
JPG
-
GIF
-
PNG
-
Animated GIF
-
MP4
-
- (Optional) In the Data Sources section, click Add Data Source to add a data source for attribute simulation.
You can use a CSV (comma-separated value) file as the source for attribute data simulation. You can configure the following fields for a data source:
-
Name: Specify a unique identifier for the data source.
-
Loop: Select if you want the simulator to continue reading from the beginning of the CSV file after reaching the end.
-
Upload File: Click to select the CSV file to upload.
Ensure that the CSV file does not contain any column heading names. For example, if you have a
Temperature
column containing temperature values, remove the header row title, so that the rows contain data values only.
You may use the data source values in expressions. For example, to read values from the second column of a data source called
dsName,
use the following syntax:$datasource.dsName[1].
Here, the name of the data source isdsName,
and the index value of 1 specifies the second column in the data source. -
- (Optional) In the Functions section, click Add Function to define your own function.
You can use the function at any place where expressions are allowed. For example, use functions in expressions for attributes, alerts, and events.
Specify values for the following fields:
-
Name: Specify a name for the function. For example:
absDiff.
-
Definition: Use lambda syntax to define the body of the function. For example:
(param1, param2) -> Math.abs(param2 - param1)
You can now use the function in expressions. For example:
$attr0 > 50 ? absDiff($attr1, $attr2) : absDiff($attr3, $attr4).
-
- Click Save to save your custom simulation model.