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
질문됨 일 년 전269회 조회
1개 답변
0

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

Claudio
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠