英文:
Call a rest API once in 10 minutes in thingsboard
问题
我已在Thingsboard PE规则链中创建了一个REST API调用,仅用于检查和确认集成和数据转换器是否正常工作,简单来说,它就像一个看门狗,所以我创建了一个规则,每当我接收到遥测数据时,这个REST API调用就会发生,很可能每分钟会有大约100次调用,所以我希望使用一些脚本或其他方式创建一个计时器,在其中将检查是否有新的遥测数据进来,如果超过10分钟,它将进行REST API调用并重置计时器,否则将忽略消息,是否有实现这一目标的方法?
英文:
I have created a rest API call in Thingsboard PE rule chain, just to check and confirm that the integration and data convertor is working properly simply it was an watchdog, so i created like whenever I receive a telemetry data this rest API call will happen, more likely it will be around 100 calls per minute, so I wish to create a timer using some script or something which will have a timer in it and will check when a new telemetry data comes in and if it is greater than 10 minutes it will make the rest API call and reset the timer else will ignore the message, is there any way to achieve this?
答案1
得分: 1
获取此资产的上一个遥测数据的时间戳(如果遥测数据中没有时间戳,您可能需要更改传入的规则链并将其存储为资产变量'last_received')。
将资产变量添加到消息元数据中。
在您的API规则链中,添加一个节点来检查当前时间是否比资产'last_received'时间戳大10分钟以上。如果为真 -> 调用API,否则不执行。
return Date.now() > +metadata.last_received;
英文:
Get the timestamp of the previous telemetry for this asset (you may have to alter your incoming rulechain and store this as an asset variable ('last_received') if it doesn't have a timestamp in the telemetry).
Add the asset variable to the message metadata.
In your api rulechain, add a node to check if the current time is more than 10 minutes greater than the asset 'last_received' timestamp. If true -> call the api, else nothing.
return Date.now() > +metadata.last_received;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论