question

EllisDawson-2177 avatar image
0 Votes"
EllisDawson-2177 asked EllisDawson-2177 commented

IoT Central API Device State

We are using IoT Central and telemetry is happily being stored. If we use the API to query telemetry we get results back as follows:
{
"$id": "BD0B671C-A3EF-492B-AEE0-066BD22A9EA2",
"$ts": "2022-04-28T11:29:00.741Z",
"Heartbeat": "Pulse"
}


If I query with the following I get back our Error Events
Query
{
"query" : "SELECT Error FROM dtmi:modelDefinition:bennamann:weatherstationtest;1"
}
Result

 {
     "results": [
         {
             "Error": "Generator failed to start"
         },
         {
             "Error": "Loading Pump stalling"
         }
     ]
 }

However, if I then try to add the timestamp in either the order by or in the select we get the timestamp but not the actual error state.
Query

 {
     "query" : "SELECT $ts,Error FROM dtmi:modelDefinition:bennamann:weatherstationtest;1 ORDER BY $ts"
 }

Result

 "results": [
         {
             "$ts": "2022-03-29T11:50:36.682Z"
         },
         {
             "$ts": "2022-03-29T11:50:42.925Z"
         },
         {
             "$ts": "2022-03-29T11:52:50.782Z"
         },
         {
             "$ts": "2022-03-29T11:52:57.018Z"
         },
         {
             "$ts": "2022-03-29T11:53:09.95Z"
         },
         {
             "$ts": "2022-03-29T11:53:16.622Z"
         },
         {
             "$ts": "2022-03-29T11:55:36.681Z"
         },
         {
             "$ts": "2022-03-29T11:56:42.927Z"
         }
     ]
 }

Any ideas why this occurs and how we would get our Error Events with timestamp against them?





azure-iot-central
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

dominicbetts avatar image
2 Votes"
dominicbetts answered EllisDawson-2177 commented

If Error is defined as an Event in the device template, the implication is that an Error value isn't included in every telemetry value sent from the device. To select telemetry messages that include an Error value, try:

 {
   "query": "SELECT $ts, Error FROM dtmi:azurertos:devkit:hlby5jgib2o  WHERE Error <> ''"
 }




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you!! That was exactly the issue.

1 Vote 1 ·