Home > Back-end >  Writing the correct SQL statement in AWS IoT rule
Writing the correct SQL statement in AWS IoT rule

Time:11-16

I am working on AWS IoT to develop my custom solution based on a set of sensors, and I have a problem regarding how to write the SQL statement related to the kind of data I receive from a Zigbee sensor.

An example of what I receive from my sensor is reported here:

{
  "type": "reportAttribute",
  "from": "WIFI",
  "deviceCode": "aws_device_code",
  "to": "CLOUD",
  "mac": "30:ae:7b:e2:e1:e6",
  "time": 1668506014,
  "data": {...}
}

What I would like to do is to select messages that have the from field equal to GREENPOWER, something along the lines of SELECT * FROM 'test' WHERE from = 'GREENPOWER', but from is also a keyword in SQL hence my problem. I am no expert whatsoever in SQL, so I am not sure how this can be done. I am also looking for a way to modify the received data, but solving this problem on AWS would be much easier.

Thank you very much for your help!

CodePudding user response:

There are quite a lot of SQL functions that exist in AWS IoT Rule. You can find them here: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html

In your case, something like this should work:

SELECT * FROM 'test' WHERE get(*, "from") = "GREENPOWER"
  • Related