//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public async void Watch() { //start polling while (true) { try { var sensorValue = buttonSensor.CurrentState; var payload = new AzureIOTPayoad() { Button = (sensorValue == SensorStatus.Off) ? 0 : 1, ThingName = "Button" }; if (OnNewValueAcquiredCb != null) { OnNewValueAcquiredCb(payload); } //sleep for 500ms await Task.Delay(500); } catch (Exception ex) { } } }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public async void Watch() { while (true) { try { var sensorValue = rotaryAngleSensor.SensorValue(); var payload = new AzureIOTPayoad() { RotaryAngleSensor = sensorValue, ThingName = "RotaryAngleSensor" }; if (OnNewValueAcquiredCb != null) { OnNewValueAcquiredCb(payload); } await Task.Delay(2000); } catch (Exception ex) { } } }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public async void Watch() { while (true) { try { var sensorValue = lightSensor.SensorValue(); var payload = new AzureIOTPayoad() { Light = sensorValue, ThingName = "Light" }; if (OnNewValueAcquiredCb != null) { OnNewValueAcquiredCb(payload); } await Task.Delay(500); } catch (Exception ex) { } } }
//------------------------------------------------------------------------------------------------------------------------ private async void OnSensedValue(AzureIOTPayoad payload) { payload.name = RaspName; await deviceClient.SendEventAsync(new Message(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(payload)))); }