|
| 1 | +--- |
| 2 | +title: Query ingested telemetry data |
| 3 | +description: This article describes how to query ingested telemetry data. |
| 4 | +author: sunasing |
| 5 | +ms.topic: article |
| 6 | +ms.date: 03/11/2020 |
| 7 | +ms.author: sunasing |
| 8 | +--- |
| 9 | + |
| 10 | +# Query ingested telemetry data |
| 11 | + |
| 12 | +This article describes how to query ingested sensor data from Azure FarmBeats. |
| 13 | + |
| 14 | +Ingesting data from Internet of Things (IoT) resources such as devices and sensors is a common scenario in FarmBeats. You create metadata for devices and sensors and then ingest the historical data to FarmBeats in a canonical format. Once the sensor data is available on FarmBeats Datahub, we can query the same to generate actionable insights or build models. |
| 15 | + |
| 16 | +## Before you begin |
| 17 | + |
| 18 | +Before you proceed with this article, make sure that you've installed FarmBeats and ingested sensor telemetry data from your IoT devices to FarmBeats |
| 19 | +To ingest sensor telemetry data, visit [ingest historical telemetry data](ingest-historical-telemetry-data-in-azure-farmbeats.md) |
| 20 | + |
| 21 | +Before you proceed, also make sure you are familiar with FarmBeats REST APIs as you will query ingested telemetry using APIs. For more details on FarmBeats APIs, please see [FarmBeats REST APIs](rest-api-in-azure-farmbeats.md). **Ensure that you are able to make API requests to your FarmBeats Datahub endpoint** |
| 22 | + |
| 23 | +## Query ingested sensor telemetry data |
| 24 | + |
| 25 | +Follow the below steps to query the ingested sensor telemetry data: |
| 26 | + |
| 27 | +1. Identify the sensor you are interested in. You can do this by making a GET request on /Sensor API. Note the **id** and the **sensorModelId** of the interested sensor object. |
| 28 | + |
| 29 | +2. Make a GET/{id} on /SensorModel API for the **sensorModelId** as noted in step 1. The SensorModel has all the metadata and details about the ingested telemetry from the sensor. For example, SensorMeasure within the SensorModel object has details about what measures is the sensor sending and in what types and units. For example, |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "name": "moist_soil_last <name of the sensor measure - this is what we will receive as part of the queried telemetry data>", |
| 34 | + "dataType": "Double <Data Type - eg. Double>", |
| 35 | + "type": "SoilMoisture <Type of measure eg. temperature, soil moisture etc.>", |
| 36 | + "unit": "Percentage <Unit of measure eg. Celsius, Percentage etc.>", |
| 37 | + "aggregationType": "None <either of None, Average, Maximum, Minimum, StandardDeviation>", |
| 38 | + "description": "<Description of the measure>" |
| 39 | +} |
| 40 | +``` |
| 41 | +Make a note of the response from the GET/{id} call for the SensorModel. |
| 42 | + |
| 43 | +3. Do a POST call on /Telemetry API with the following input payload |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "sensorId": "<id of the sensor as noted in step 1>", |
| 48 | + "searchSpan": { |
| 49 | + "from": "<desired start timestamp in ISO 8601 format; default is UTC>", |
| 50 | + "to": "<desired end timestamp in ISO 8601 format; default is UTC>" |
| 51 | + }, |
| 52 | + "filter": { |
| 53 | + "tsx": "string" |
| 54 | + }, |
| 55 | + "projectedProperties": [ |
| 56 | + { |
| 57 | + "additionalProp1": "string", |
| 58 | + "additionalProp2": "string", |
| 59 | + "additionalProp3": "string" |
| 60 | + } |
| 61 | + ] |
| 62 | +} |
| 63 | +``` |
| 64 | +4. The response from the /Telemetry API will look something like this: |
| 65 | + |
| 66 | +```json |
| 67 | +{ |
| 68 | + "timestamps": [ |
| 69 | + "2020-XX-XXT07:30:00Z", |
| 70 | + "2020-XX-XXT07:45:00Z" |
| 71 | + ], |
| 72 | + "properties": [ |
| 73 | + { |
| 74 | + "values": [ |
| 75 | + "<id of the sensor>", |
| 76 | + "<id of the sensor>" |
| 77 | + ], |
| 78 | + "name": "Id", |
| 79 | + "type": "String" |
| 80 | + }, |
| 81 | + { |
| 82 | + "values": [ |
| 83 | + 2.1, |
| 84 | + 2.2 |
| 85 | + ], |
| 86 | + "name": "moist_soil_last <name of the SensorMeasure as defined in the SensorModel object>", |
| 87 | + "type": "Double <Data Type of the value - eg. Double>" |
| 88 | + } |
| 89 | + ] |
| 90 | +} |
| 91 | +``` |
| 92 | +In the above example response, the queried sensor telemetry gives data for two timestamps along with the measure name ("moist_soil_last") and values of the reported telemetry in the two timestamps. You will need to refer to the associated /SensorModel (as described in step 2) to interpret the type and unit of the reported values. |
| 93 | + |
| 94 | +## Next steps |
| 95 | + |
| 96 | +You now have queried sensor data from your Azure FarmBeats instance. Now, learn how to [generate maps](generate-maps-in-azure-farmbeats.md#generate-maps) for your farms. |
0 commit comments