示例#1
0
        //------------------------------------------------------------------------------------------------------------------------
        #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)
                {
                }
            }
        }
示例#2
0
        //------------------------------------------------------------------------------------------------------------------------
        #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)
                {
                }
            }
        }
示例#3
0
        //------------------------------------------------------------------------------------------------------------------------
        #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)
                {
                }
            }
        }
示例#4
0
 //------------------------------------------------------------------------------------------------------------------------
 private async void OnSensedValue(AzureIOTPayoad payload)
 {
     payload.name = RaspName;
     await deviceClient.SendEventAsync(new Message(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(payload))));
 }