Self-defined Function while creating a Digital twin?

121 views Asked by At

It is possible to add a self-defined function while creating a digital Twin in Ditto as shown below.

"attributes": {
    "location": "Germany"
},
"features": {
    "temperature": {
        "properties": {
            "value": 100
        }
    },
    "humidity": {
        "properties": {
            "value": 100
        }
    }
},
"BuiltinFuntion": {
    if(Temparature > 20){
   alert("Some message")
}
}

Note: One solution is to constantly check with Ditto HTTP APIs value and give alert message whenever it cross the threshold value. But I do not want to hit the APIs everytime. So please let me know if there is any alternate solution.

1

There are 1 answers

0
Thomas Jäckle On BEST ANSWER

In order not to poll Ditto's API for changes, there are various other APIs supporting push-notifications.

For example, you can use the WebSocket API and use an filter expression defining filter=gt(features/temperature/properties/value,20) when subscribing for events. Or you can use the SSE (Server Sent Events) API to do the same.

Both, the WebSocket and SSE API may directly be used in the browser - I suppose your alert you want to show is JavaScript, so I assumed your target environment for receiving push notifications is a browser.