Ejemplo n.º 1
0
        private async void StartAccelerometerSensor_Click(object sender, EventArgs e)
        {
            if (BandHelper.Instance.BandClient == null)
            {
                await BandHelper.Instance.Connect();
            }

            // hook up to the Accelerometer sensor ReadingChanged event
            BandHelper.Instance.BandClient.SensorManager.Accelerometer.ReadingChanged += (s, a) =>
            {
                // do work when the reading changes (i.e., update a UI element)
                BandAccelerometerReading = a.SensorReading;
            };


            // start the Heartrate sensor
            try
            {
                await BandHelper.Instance.BandClient.SensorManager.Accelerometer.StartReadingsAsync();
            }
            catch (Exception ex)
            {
                // handle a Band connection exception
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void AddAccelerometerReading(BandAccelerometerReading accelerometerReading)
        {
            _readings.Enqueue(accelerometerReading);
            if (_readings.Count > MaxQueueBufferSize)
            {
                _readings.Dequeue();
            }

            rx.OnNext(accelerometerReading);
        }
Ejemplo n.º 3
0
 private static void GetSensorValue()
 {
     BandClient.SensorManager.HeartRate.ReadingChanged += (sender, args) =>
     {
         if (args.SensorReading.Quality == HeartRateQuality.Locked)
         {
             HeartRate = args.SensorReading;
             ListHeartRate.Add(HeartRate.HeartRate);
         }
     };
     BandClient.SensorManager.Accelerometer.ReadingChanged += (sender, args) =>
     {
         Accelerometer = args.SensorReading;
     };
     BandClient.SensorManager.Calories.ReadingChanged += (sender, args) =>
     {
         //LastCalories = GetValue(BandSensorType.Calories);
         Calories = args.SensorReading;
         if (BeginCalories == null)
         {
             BeginCalories = Calories.Calories;
         }
     };
     BandClient.SensorManager.Pedometer.ReadingChanged += (sender, args) =>
     {
         // LastStep = GetValue(BandSensorType.Step);
         Pedometer = args.SensorReading;
         if (BeginStep == null)
         {
             BeginStep = Pedometer.TotalSteps;
         }
     };
     BandClient.SensorManager.Distance.ReadingChanged += (sender, args) =>
     {
         // LastDistance = GetValue(BandSensorType.Distance);
         Distance = args.SensorReading;
         if (BeginDistance == null)
         {
             BeginDistance = Distance.TotalDistance;
         }
     };
 }
        public static async Task SendAccelerometerReading(BandAccelerometerReading reading)
        {
            try
            {
                var sas = "SharedAccessSignature sr=https%3A%2F%2Fcodecamphub2-ns.servicebus.windows.net%2Fcodecamphub2%2Fpublishers%2Fband1%2Fmessages&sig=HIbitE%2FSwyURcCWMMGkY73mbMJus7F28qD81KHlUPD0%3D&se=1440285353&skn=Devices";

                // Namespace info.
                var serviceNamespace = "codecamphub2-ns";
                var hubName          = "codecamphub2";
                var deviceName       = "band1";

                // Create client.
                var httpClient = new HttpClient
                {
                    BaseAddress = new Uri(string.Format("https://{0}.servicebus.windows.net/", serviceNamespace))
                };

                var payload = JsonConvert.SerializeObject(reading);

                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", sas);

                var content = new StringContent(payload, Encoding.UTF8, "application/json");
                content.Headers.Add("ContentType", "application/atom+xml;type=entry;charset=utf-8");

                var url = string.Format("{0}/publishers/{1}/messages", hubName, deviceName);

                var postResult = await httpClient.PostAsync(url, content);

                var resultContent = postResult.Content.ToString();
                var resultStatus  = (int)postResult.StatusCode;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error sending telemetry to event hubs: " + ex.ToString());
            }
        }