SaaS Composer Version: Version v3.4.10
Description
This tutorial demonstrates how to use SaaS Composer function to get real-time data from an IoT Edge data source and write values back to it, triggered by a click event.
Steps
1. Add an object to serve as a button and enable Event Interactive.
2. Open the Event Headers and enter the following JavaScript code.
Make sure to replace the data source name and target tag path with your own values: TenantName, DeviceName, and TagName.
# JavaScript
// Check if the datapoints for the given source-target pair exist
if (dataRefreshUtil.getCurValueBySourceTarget('IoTEdgeData','TenantName#default#DeviceName#defaultModule<>TagName').datapoints) {
// Retrieve the first datapoint value (res01) and the timestamp (time_res) from the datapoints array
var res01 = dataRefreshUtil.getCurValueBySourceTarget('IoTEdgeData','TenantName#default#DeviceName#defaultModule<>TagName').datapoints[0][0];
var time_res = dataRefreshUtil.getCurValueBySourceTarget('IoTEdgeData','TenantName#default#DeviceName#defaultModule<>TagName').datapoints[0][1];
}
// Logs the value of res01 to the console
console.log(res01);
// Assign the value of res01 to the offon variable (This will be used for checking on/off status)
var offon = res01;
// Set the value to "1" if offon is "0" or 0, otherwise set it to "0"
var valueToSet = (offon === "0" || offon === 0) ? "1" : "0";
// Use dataRefreshUtil to update the value of the target datapoint (IoTEdge Device's Tag)
dataRefreshUtil.setValue(
"IoTEdgeData", // The data source name
"loThub-SC-simple-json-datasource", // The data source type
{
"target": "TenantName#default#DeviceName#defaultModule<>TagName", // The target where the value needs to be set
"value": valueToSet // The new value to be set ("1" or "0")
}
);
TIP: You can copy the target tag path directly from the Data Binding window.




