AWS IoT rule SQL query for mqtt nested arrays

0

I have the following mqtt message:

{
  "sensors": [
    {
      "lsid": 412618,
      "data": [
        {
          "temp_in": 72.3,
          "heat_index_in": 72,
          "dew_point_in": 55.9,
          "ts": 1652785241,
          "hum_in": 56.3
        }
      ],
      "sensor_type": 243,
      "data_structure_type": 12
    },
    {
      "lsid": 421195,
}

I can get the "sensors,0.lsid" value and the entire "data" array using this query:

 select get(sensors,0).lsid as ls, get(sensors, 0).data as data1 from "topic"

but what I really need is to get "temp_in:72.3" , i.e. the values from the second level array I've tried using this :https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-nested-queries.html, but unless i'm not following it correctly, it doesnt seem to work.

Any help would be greatly appreciated

posta 2 anni fa1299 visualizzazioni
1 Risposta
2
Risposta accettata

You can nest get() function calls as in:

select get(sensors,0).lsid as ls, get(get(sensors,0).data, 0).temp_in as temp_in from "topic"

AWS
ESPERTO
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande