Exemplo n.º 1
0
 /// <summary>
 /// Light sensor reading changed. Send data to Azure Event Hub if checkbox checked in the UI
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 async private void light_ReadingChanged(LightSensor sender, LightSensorReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         txtLightSensor.Text = args.Reading.IlluminanceInLux.ToString();
         if (Convert.ToBoolean(chkLightSensor.IsChecked))
         {
             ConnecTheDotsSensor sensor = sensors.Find(item => item.measurename == "Light");
             if (sensor != null)
             {
                 sensor.value       = args.Reading.IlluminanceInLux;
                 sensor.timecreated = DateTime.UtcNow.ToString("o");
                 sendMessage(sensor.ToJson());
             }
         }
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Acceleromter reading changed. Send data to Azure Event Hub if checkbox checked in the UI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        async private void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                ConnecTheDotsSensor sensor = sensors.Find(item => item.measurename == "AccelX");
                if (sensor != null)
                {
                    sensor.value         = args.Reading.AccelerationX;
                    sensor.timecreated   = DateTime.UtcNow.ToString("o");
                    txtAccelXSensor.Text = sensor.value.ToString();
                    if (Convert.ToBoolean(chkAccelXSensor.IsChecked))
                    {
                        sendMessage(sensor.ToJson());
                    }
                }

                sensor = sensors.Find(item => item.measurename == "AccelY");
                if (sensor != null)
                {
                    sensor.value         = args.Reading.AccelerationY;
                    sensor.timecreated   = DateTime.UtcNow.ToString("o");
                    txtAccelYSensor.Text = sensor.value.ToString();
                    if (Convert.ToBoolean(chkAccelYSensor.IsChecked))
                    {
                        sendMessage(sensor.ToJson());
                    }
                }

                sensor = sensors.Find(item => item.measurename == "AccelZ");
                if (sensor != null)
                {
                    sensor.value         = args.Reading.AccelerationZ;
                    sensor.timecreated   = DateTime.UtcNow.ToString("o");
                    txtAccelZSensor.Text = sensor.value.ToString();
                    if (Convert.ToBoolean(chkAccelZSensor.IsChecked))
                    {
                        sendMessage(sensor.ToJson());
                    }
                }
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Timer tick for sending simulated data read from sliders on main page of the app
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Timer_tick(object sender, object e)
 {
     try {
         ConnecTheDotsSensor sensor = sensors.Find(item => item.measurename == "Temperature");
         if (sensor != null)
         {
             sensor.value       = this.TemperatureSlider.Value;
             sensor.timecreated = DateTime.UtcNow.ToString("o");
             sendMessage(sensor.ToJson());
         }
         sensor = sensors.Find(item => item.measurename == "Humidity");
         if (sensor != null)
         {
             sensor.value       = this.HumiditySlider.Value;
             sensor.timecreated = DateTime.UtcNow.ToString("o");
             sendMessage(sensor.ToJson());
         }
     }
     catch (Exception exception)
     {
         Debug.WriteLine("Exception while sending data: {0}", exception.Message);
     }
 }