Problem with IOT Core converting double to int in JSON parser

1

I have a temperature sensor device that I am creating. Everything is working. I can publish to IOT Core and I have rule setup to send the data to AWS Timestream. However, I find that the JSON parser in AWS IoT Core is converting floats/doubles into ints IF they end in .0. So, a value sent through as 30.0 gets converted to 30. This happens whether I send the JSON object from the device or from the IOT Client on AWS IoT core.

Here is my example object:
{"location":"synders", "type": "weather", "id": "synders_5cE89C", "temperature": 23.0, "humidity": 35.0, "rain": 0.0, "groundtemperature": 0.0, "groundmoisture": 0}

Here is what is received from the test client:
{
"location": "synders",
"type": "weather",
"id": "synders_5cE89C",
"temperature": 23,
"humidity": 35,
"rain": 0,
"groundtemperature": 0,
"groundmoisture": 0
}

If I change the data to use anything other than .0, it works as expected:

{"location":"synders", "type": "weather", "id": "synders_5cE89C", "temperature": 23.1, "humidity": 35.1, "rain": 0.1, "groundtemperature": 0.1, "groundmoisture": 0}

Becomes in the IoT client:
{
"location": "synders",
"type": "weather",
"id": "synders_5cE89C",
"temperature": 23.1,
"humidity": 35.1,
"rain": 0.1,
"groundtemperature": 0.1,
"groundmoisture": 0
}

This is a problem because Timestream thinks the values are bigints instead of doubles because the decimal place is missing. This causes an error and the data is not recorded.

It is not necessary to publish data from the device to see the issue. I've only used the AWS IoT MQTT client.

I have to think the solution is quite simple and I missed something in the docs or a setting somewhere. Suggestions anyone?

Help
Mark

Edited by: MarkBuckaway on Feb 4, 2021 8:19 AM

asked 3 years ago546 views
2 Answers
1

As it turns out, it's a bit more complicated than that. I contact AWS Support, and after a few exchanges, they confirmed there is a problem with IoT Core converting doubles, but the work around is to set the database query to use the cast operator with the 2015-10-08
SQL version. The newer version does not correctly support the cast, and will not work.

So, the Rule ended up being:

SELECT cast(temperature as double) as temperature, cast(humidity as double) as humidity, cast(rain as double) as rain, cast(groundtemperature as double) as groundtemperature, groundmoisture FROM 'tms/weather/#'

Using SQL version 2015-10-08

Once I did that, data was received and injected to Timestream correctly.

Mark

answered 3 years ago
0

Similar topic - https://forums.aws.amazon.com/thread.jspa?messageID=965764버

Try casting the values to double in the IoT rule.

Edited by: rschultz on Mar 2, 2021 7:40 AM

answered 3 years 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