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
asked a year ago263 views
1 Answer
0

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

Claudio
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions