aws iot sql question

0

Is there a way to change the hexadecimal number of mqtt payload to decimal in aws iot sql? For example) 07e7 -> 2023, 08 -> 08, 19 -> 25, 13a5 -> 5029, 0064 -> 100 The byte is fixed, and I want to change the hexadecimal number to decimal according to the byte.

질문됨 10달 전219회 조회
2개 답변
0

Yes, it is possible to convert hexadecimal numbers to decimal in AWS IoT SQL. Here is one way to do it:

Use the CAST function to convert the hexadecimal string to a BIGINT. This will interpret the hex string as a base 16 number and convert it to a decimal integer.

For example:

SELECT CAST('07e7' AS BIGINT) AS decimal_value

Would output:

decimal_value 2023

The CAST function handles strings of different lengths, so you can convert 1 byte hex values like '08' up to 8 byte values like '13a5'.

Some examples:

SELECT CAST('08' AS BIGINT) AS decimal_value

Would output:

decimal_value
8

SELECT CAST('19' AS BIGINT) AS decimal_value

Would output:

decimal_value 25

SELECT CAST('13a5' AS BIGINT) AS decimal_value

Would output:

decimal_value 5029

profile pictureAWS
답변함 10달 전
  • Thank you. But error.....

    SqlParseException Unknown data type 'BIGINT' BIGINT) AS decimal_value ---------------------^ at 1:22

0

This conversion from HEX to Decimal didnt work for us. It's not listed in the documentation either, https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-sql-function-cast

Are you sure it should work?

Dave
답변함 3달 전

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

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

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