- Newest
- Most votes
- Most comments
This behavior is expected with AWS IoT Greengrass. AWS IoT Greengrass uses JSON for configuration values, and JSON doesn't differentiate between integers and floats - it only specifies a "number" type. As a result, numeric values might convert to floats when processed by AWS IoT Greengrass.
To ensure your component uses the correct data type, the recommended approach is to define your numeric values as strings in your JSON messages. For example, instead of publishing { "test": 1 }, you could publish { "test": "1" }. Then, have your component parse these string values as integers or floats as needed.
This approach ensures that your values maintain the same data type both in the configuration and on your core device. By handling the type conversion in your component code, you can maintain precise control over whether a number is treated as an integer or a float.
Sources
AWS IoT Greengrass component recipe reference - AWS IoT Greengrass
Saving data as Double instead of bigint | AWS re:Post
answered a year ago
Hi JSON does not define how numbers are to be parsed, so some libraries always use floating point, which is compliant. Getting either 1 or 1.0 is expected, and may depend on the tools used. If you need an integer, you can check if the decimal part is 0, or you can encode your data as strings.
answered a year ago
Relevant content
asked 4 years ago
asked 4 years ago
- AWS OFFICIALUpdated 2 years ago
