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

demandé il y a 2 ans1113 vues
1 réponse
2
Réponse acceptée

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
EXPERT
répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions