- Newest
- Most votes
- Most comments
The error you're encountering suggests that AWS IoT Rules Engine is trying to parse your binary protobuf message as JSON before applying the decode function, which is causing the JsonParseError.
When working with raw binary protobuf payloads in AWS IoT Core rules, you need to understand that the Rules Engine first attempts to parse the incoming message as JSON before applying any SQL functions. For binary data, this parsing will fail.
To properly handle binary protobuf messages, you should modify your SQL statement to only use the decode function without trying to select other fields. Try using this SQL statement instead:
SELECT decode(*, 'proto', 'aws-iot-annlin', 'heartrate.desc', 'heartrate', 'HeartRateChunk') as decoded_chunk FROM 'sdk/test/java/chunk/+'
Notice that I've removed the *, from the beginning of your SELECT statement. This is because you can't select both the raw binary data and the decoded data in the same query when working with binary payloads.
Also, it's important to note that error actions in IoT rules are only triggered when an action fails, not when the SQL statement itself fails. If your SQL statement fails due to parsing errors, the error action won't be executed because the rule engine never gets to the action execution phase.
Make sure your descriptor files are correctly uploaded to the specified S3 bucket and that the AWS IoT role has permissions to access them. The decode function requires the following parameters:
- The encoded data (in your case, the raw binary payload represented by
*) - The decoding scheme ('proto')
- The S3 bucket name ('aws-iot-annlin')
- The descriptor file name ('heartrate.desc')
- The proto filename ('heartrate')
- The protobuf message type ('HeartRateChunk')
Sources
Working with binary payloads - AWS IoT Core
Functions - AWS IoT Core
AWS IoT Rule error action on functions | AWS re:Post
re:Post Agent identified the issue with my SQL query. This is what fixed it:
To properly handle binary protobuf messages, you should modify your SQL statement to only use the decode function without trying to select other fields. Try using this SQL statement instead:
SELECT decode(*, 'proto', 'aws-iot-annlin', 'heartrate.desc', 'heartrate', 'HeartRateChunk') as decoded_chunk FROM 'sdk/test/java/chunk/+'
Relevant content
asked 4 years ago
asked 4 years ago
asked 3 years ago
asked 2 years ago
