Udostępnij za pośrednictwem


SensorEvents.GetSensorEventsAsync Method

Definition

Returns a list of sensor events data. Time span for query is limited to 90 days at a time. Returns last 90 days events when startDateTime and endDateTime are not provided.

public virtual System.Threading.Tasks.Task<Azure.Response> GetSensorEventsAsync (string sensorId, string sensorPartnerId, DateTimeOffset? startDateTime = default, DateTimeOffset? endDateTime = default, bool? excludeDuplicateEvents = default, Azure.RequestContext context = default);
abstract member GetSensorEventsAsync : string * string * Nullable<DateTimeOffset> * Nullable<DateTimeOffset> * Nullable<bool> * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.GetSensorEventsAsync : string * string * Nullable<DateTimeOffset> * Nullable<DateTimeOffset> * Nullable<bool> * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function GetSensorEventsAsync (sensorId As String, sensorPartnerId As String, Optional startDateTime As Nullable(Of DateTimeOffset) = Nothing, Optional endDateTime As Nullable(Of DateTimeOffset) = Nothing, Optional excludeDuplicateEvents As Nullable(Of Boolean) = Nothing, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

sensorId
String

Id of the associated sensor.

sensorPartnerId
String

Id of the associated sensor partner.

startDateTime
Nullable<DateTimeOffset>

Search span start time of sensor events (inclusive), sample format: yyyy-MM-ddTHH:mm:ssZ. It is truncated upto seconds if fraction is provided.

endDateTime
Nullable<DateTimeOffset>

Search span end time of sensor events (inclusive), sample format: yyyy-MM-ddTHH:mm:ssZ. It is truncated upto seconds if fraction is provided.

excludeDuplicateEvents
Nullable<Boolean>

Flag to exclude duplicate events and take the latest ones only (Default: true).

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service. Details of the response body schema are in the Remarks section below.

Exceptions

sensorId or sensorPartnerId is null.

Service returned a non-success status code.

Examples

This sample shows how to call GetSensorEventsAsync with required parameters and parse the result.

var credential = new DefaultAzureCredential();
var client = new FarmBeatsClient(credential).GetSensorEventsClient(<2022-11-01-preview>);

Response response = await client.GetSensorEventsAsync("<sensorId>", "<sensorPartnerId>");

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("value")[0].ToString());

This sample shows how to call GetSensorEventsAsync with all parameters, and how to parse the result.

var credential = new DefaultAzureCredential();
var client = new FarmBeatsClient(credential).GetSensorEventsClient(<2022-11-01-preview>);

Response response = await client.GetSensorEventsAsync("<sensorId>", "<sensorPartnerId>", DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, true);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("value")[0].GetProperty("sensorId").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("sensorPartnerId").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("partyId").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("boundaryId").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("eventDateTime").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("ingestionDateTime").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("measures").GetProperty("<test>").ToString());
Console.WriteLine(result.GetProperty("skipToken").ToString());
Console.WriteLine(result.GetProperty("nextLink").ToString());

Remarks

Below is the JSON schema for the response payload.

Response Body:

Schema for SensorEventListResponse:

{
  value: [
    {
      sensorId: string, # Optional. Id of the sensor.
      sensorPartnerId: string, # Optional. Id of the sensor partner.
      partyId: string, # Optional. Id of the associated party.
      boundaryId: string, # Optional. Id of the associated boundary.
      eventDateTime: string (ISO 8601 Format), # Optional. DateTime of sensor event observation.
      ingestionDateTime: string (ISO 8601 Format), # Optional. DateTime of sensor event ingestion to data store.
      measures: Dictionary<string, any>, # Optional. Sensor measures.
    }
  ], # Required. List of requested objects.
  skipToken: string, # Optional. Token used in retrieving the next page. If null, there are no additional pages.
  nextLink: string, # Optional. Continuation link (absolute URI) to the next page of results in the list.
}

Applies to