1
votes

How to use AWS IoT Rule Query Statement to get temperature and humidity from the following MQTT payload to 'example' topic?

[
  {
    "timestamp": "2019-08-26T14:21:46Z",
    "type": "Gateway",
    "mac": "XXYYZZXXYYZZ",
    "gatewayFree": 96,
    "gatewayLoad": 0.26
  },
  {
    "timestamp": "2019-08-26T14:21:46Z",
    "type": "S1",
    "mac": "XXYYZZXXYYXX",
    "bleName": "",
    "rssi": -53,
    "battery": 100,
    "temperature": 0.69,
    "humidity": 37.28
  },
  {
    "timestamp": "2019-08-26T14:21:46Z",
    "type": "iBeacon",
    "mac": "XXYYZZXXYYYY",
    "bleName": "",
    "ibeaconUuid": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
    "ibeaconMajor": 0,
    "ibeaconMinor": 0,
    "rssi": -64,
    "ibeaconTxPower": -59,
    "battery": 0
  }
]

So far, I cannot find it on AWS IoT SQL Reference.

2

2 Answers

1
votes

Try this, it's working!

SELECT (SELECT temperature, humidity from input) as output FROM 'iot/topic' 

I have modified the input JSON to have a key -- see below.

Here is the modified input:

{
   "input": [ ... your json array elements ... ]
}

Here is the output:

{
  "output": [
    {},
    {
      "temperature": 0.69,
      "humidity": 37.28
    },
    {}
  ]
}

cheers,
ram

0
votes

Also try this one...

{
    "sql": "SELECT * FROM 'iot/example' WHERE mac = 'XXYYZZXXYYXX'",
    ...
}

Cheers!