Device Resources
The Resources page is where you may add attributes (or "alias"es) to your devices (e.g., temperature, status, etc.). Resources represent a device's digital twin in the cloud, like a data model shared by all devices. A resource is identified by its alias, and the resource's unit (e.g., °C) can be specified to further clarify the alias's measurement. It is possible to restrict values to ranges (0-100) or to discrete values ("open", "closed", "jammed"). The current resource value for a given device is visible when browsing the device in the project and is accessible to scripts, which can then act on reported values in any number of ways.
Limitation
Resources are limited in size to 64KB each.
Define Your Device Resources
Global Resource
When you click "+ NEW RESOURCE", you will be prompted for four steps:
1.Resource definition
For the resource definition, the Alias
is the resource name,
you should define the data format(only one can be selected):
String
refers to a unicode sequence of characters.Number
refers to any positive or negative value.Boolean
refers to a binary variable (i.e., true or false).
You also can define what possible values of this resource and what unit will this resource use.
Note
- Optionally, you can restrict these resources to specific Possible Values, i.e. environmental sensor information normally won't be set from cloud to the device.
- If you want to review the last data from device signal page, you should enable the
Store last value per device
setting.
2.Data storage
For the data storage you can change below setting by switch on/off:
- Data retention- 3/6/12/36/60/120 months
3.Communication
For the communication you can change below settings by switch on/off:
- Trigger scripting event
- Synchronous mode (default)- Trigger the script once and wait for it to finish.
- Asynchronous mode- Trigger the script in the background and do not wait. The scripting engine may retry if the execution fails.
- Write data from West Connectivity
- Do not synchronize with device
- Synchronize with device (default)- Writing data will be send to the device and wait for confirm before applying.
- Remote-Sync- Synchronize your data from a source to a targeted connector.
4.Timeout event (advanced)
On the Communication settings page, click on TIMEOUT EVENT (ADVANCED) to expand the timeout settings.
For the timeout event you can change below setting by switch on/off:
- Timeout Rule- 1/2/5/10/30/60/120/360/600/1200 minutes
Important
This feature will trigger a Timer service event. Please ensure you add the Timer service from Marketplace before enabling this feature.
Device defined resource
Device defined resource often be used for Industrial Internet of Things solutions, it uses a dedicated data structure allowing different data model per device.
For this purpose 2 main resources are used all of type String
, you could enable Device defined by switch on:
data_in
a JSON structure of data sent by the deviceconfig_io
a JSON structure defining the data model, called channels, of the data_in payload.
So you would define the temperature
in config_io
resource as follow:
{
"channels": {
"temperature": {
"display_name": "Temperature",
"description": "Value sent by the sensor",
"properties": {
"data_type": "TEMPERATURE"
}
}
}
}
And the device would need to send the defined channels to the data_in
resource as:
Un-defined resources
Devices are not restricted to write to only defined resources. Devices write to "alias"es which may or may not correspond to defined resources. All device messages are sent via the Device2 micro-service event handler to the script and can be processed as other device message, but only writes to defined resources will have the value stored in the device state under the "reported" values, available to devices via "read" and visible when viewing the device data.
Set resource to send data to the device
Typically, devices report values to resources that are "read-only" in the cloud. It is possible to enable sending data to the device with the "Send data from the cloud" option, which can be used to support command-and-control behavior. This is done through the setIdentityState
Device2 micro-service function.
All resources have a "reported" value which represents the last value written by the device (using the write API). Resources that are cloud-writeable have an additional "set" value containing the value to send to the device. The device is then expected to acknowledge the received value which updates the "reported" to match the "set". Devices will use either the read API or the long-polling API to receive control requests and then write appropriate resource updates to reflect its having acted on the request.
When fetching the device state from the scripting you will have access to both values.
Note
You can also disable the synchronization for a give resource, if so the "set" & "reported" will always be the same, and the data will not get pushed to the device. However the device can still actively access it on demand.