/// <summary> /// Get telemetry data from sensor. /// </summary> /// <param name="useNativePin">If use native pin. By default <c>True</c></param> /// <param name="timeCollectinggMessage">Canceletion time.</param> /// <returns>Mesage object <see cref="Microsoft.Azure.Devices.Client.Message"/>.</returns> public async Task <Message> GetTelemetryData(bool useNativePin = true, int timeCollectinggMessage = 15000) { int start = System.Environment.TickCount; Message msg; while (true) { if (useNativePin) { IoTHelpers.Runtime.Dht11 dht11 = new IoTHelpers.Runtime.Dht11(this.nativePin.pin); // here can f****n crash. var readging = await dht11.GetReadingAsync(20).AsTask(); msg = GetTelemetryeMessage(readging); } else { var humitire = await m_sensor.GetHumitureAsync(); msg = GetTelemetryMessage(humitire); } // break loop. var ellapsed = System.Environment.TickCount - start; if (ellapsed >= timeCollectinggMessage) { break; } } return(msg); }
/// <summary> /// Create async task for recieveing message from Dht11 pin controller. /// </summary> /// <param name="timeCollectinggMessages">Time while task will be in loop. 10 s by default.</param> /// <param name="useNativePin"> If <c>True</c> runtime.dht11 pin object will be used.</param> /// <returns>Colletion of messages rescieved from DHt11 sensor.</returns> private async Task <IEnumerable <Message> > GetHumitureMessages(bool useNativePin = false, int timeCollectinggMessages = 15000) { int start = System.Environment.TickCount; List <Message> messges = new List <Microsoft.Azure.Devices.Client.Message>(); while (true) { Message msg = null; if (useNativePin) { IoTHelpers.Runtime.Dht11 dht11 = new IoTHelpers.Runtime.Dht11(this.nativePin.pin); // here can f****n crash. var readging = await dht11.GetReadingAsync(20).AsTask(); msg = GetTelemetryeMessage(readging); } else { var humitire = await m_sensor.GetHumitureAsync(); msg = GetTelemetryMessage(humitire); } messges.Add(msg); this.HumitaireMessages = messges; // break loop. var ellapsed = System.Environment.TickCount - start; if (ellapsed >= timeCollectinggMessages) { break; } } return(messges); }