Problem with the SQL statement to evaluate the Input in IoT Events

0

Hi everyone, I have some trouble with IoT Events. In fact, with the SQL statement in the rule of the IoT Core module. I hope you can help me.

Case: devices monitoring temperature and humidity.

Each device sends a JSON array with the following form:

[{
	"NAME": "Device_1",
	"DATE": "10/05/2023 00:48:23",
	"data": {
		"temperature":"25.70",
		"humidity":"29"
	}
},
{
	"NAME": "Device_1",
	"DATE": "10/05/2023 00:48:34”,
	"data": {
		"temperature":"25.70",
		"humidity":"29"
	}
},
{
	"NAME": "Device_1",
	"DATE": "10/05/2023 00:48:44", 
	"data": {
		"temperature":"25.70",
		"humidity":"29"
	}
}]

The JSON array has 3 elements. I am interested in evaluating only the first element (0 index).

Through an IoT Core rule, the following variables need to be obtained, which are also defined as variables in the input in the IoT Events Detector Model:

  • NAME
  • data.temperature

The SQL statement to get this variables (payload) is:

SELECT get(get(*, 0), 'NAME') AS NAME, get(get(get(*, 0), 'data'), 'temperature') AS data.temperature FROM 'TOPIC/SUBTOPIC'

The problem is that the detector model does not get the variable 'data.temperature', not the variable 'NAME', which is passed without problems to the detector model. How do I know this? Well, when passing the variable 'data.temperature' through the following SQL statement, the detector model evaluates it without problem and the model executes well.

SELECT get(get(*, 0), 'NAME') AS NAME, 30 AS data.temperature FROM 'TOPIC/SUBTOPIC'

As background, the rule that fails, I'm using it to save the data to DynamoDB and it works without a problem.

I have tried many times modifying the SQL statement but I get no results.

Also, I have tried evaluating the rule as a batch, using the following SQL statement, but it doesn't work either.

SELECT * FROM 'TOPIC/SUBTOPIC'

NOTE: when I say that the model fails, it means that it evaluates the condition as "normal" knowing that it should be evaluated as "anomaly".

Thanks!

Claudio
已提問 1 年前檢視次數 270 次
1 個回答
0

Problem solved. It was necessary to use CAST to convert the data (string to decimal).

Claudio
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南