- Use case
- prerequisites
- Step 1: Adding temperature validation node
- Step 2: Validation script debugging
- TL;DR
Use case
Let’s assume your device is using DHT22 sensor to collect and push temperature readings to ThingsBoard. DHT22 sensor is good for -40 to 80°C temperature readings.
In this tutorial we will configure Mecanismo de Regra RETINA to store all temperature within -40 to 80°C range and will discard all other readings. Although this scenario is fictional, you will learn how to define JS functions to validate incoming data and use this knowledge in real-life applications.
We assume you have completed the following guides and reviewed the articles listed below:
- Getting Started guide.
- Rule Engine Overview.
Step 1: Adding temperature validation node
We will modify default rule chain and will add filter rule node with temperature validation script. We will place this rule node between default “message type switch” and “save timeseries” rule nodes. Please note that we have removed irrelevant rule nodes from the root rule chain as well.
Let’s assume the data that arrive to a system may or may not have the “temperature” field. We will treat all data that does not have “temperature” field as valid. In order to do this we will use the following function
1
return typeof msg.temperature === 'undefined' || (msg.temperature >= -40 && msg.temperature <= 80);
Step 2: Validation script debugging
Let’s check that our script is correct by using built-in “Test filter function” button
You can check few more cases when temperature is not set or it exceeded the specified thresholds.
TL;DR
Download and import attached json file with a rule chain from this tutorial. Don’t forget to mark new rule chain as “root”.
-
Getting started guides - Esses guias fornecem uma visão geral rápida dos principais recursos do RETINA. Projetado para ser concluído em 15-30 minutos.
-
Guias de Instalação - Aprenda a configurar o RETINA em vários sistemas operacionais disponíveis.
-
Connect your device - Learn how to connect devices based on your connectivity technology or solution.
-
Data visualization - These guides contain instructions how to configure complex ThingsBoard dashboards.
-
IoT Data analytics - Learn how to use rule engine to perform basic analytics tasks.
-
amostras de hardware - Learn how to connect various hardware platforms to ThingsBoard.
-
Advanced features - Learn about advanced ThingsBoard features.
-
Contribution and Development - Learn about contribution and development in ThingsBoard.