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

gefragt vor 2 Jahren1114 Aufrufe
1 Antwort
2
Akzeptierte Antwort

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
EXPERTE
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen