From 747553e03099178318d0e67d004a4a92cea0d42d Mon Sep 17 00:00:00 2001 From: Juan Manuel Servera Date: Tue, 5 Jan 2016 16:27:38 +0100 Subject: [PATCH] add a delay to avoid bluetooth conflicts --- SensorTag/SensorTag/SensorTag.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/SensorTag/SensorTag/SensorTag.cs b/SensorTag/SensorTag/SensorTag.cs index 29f8c7e..f70d980 100644 --- a/SensorTag/SensorTag/SensorTag.cs +++ b/SensorTag/SensorTag/SensorTag.cs @@ -65,7 +65,14 @@ public async Task Init() //sensors.Add(TMP007_UUID, sensor); //await sensor.EnableNotifications(); //sensor.DataReceived += Characteristic_ValueChanged; - + var irSensor = await getSensor(new Guid(TMP007_UUID)); + if (irSensor != null) + { + sensors.Add(TMP007_UUID, irSensor); + await irSensor.EnableNotifications(); + irSensor.DataReceived += IrSensor_DataReceived; + } + await Task.Delay(1000); var uuid = new Guid(HDC1000_UUID); var humSensor = await getSensor(uuid); if (humSensor != null) @@ -75,13 +82,7 @@ public async Task Init() humSensor.DataReceived += HumSensor_DataReceived; } - var irSensor = await getSensor(new Guid(TMP007_UUID)); - if(irSensor!= null) - { - sensors.Add(TMP007_UUID, irSensor); - await irSensor.EnableNotifications(); - irSensor.DataReceived += IrSensor_DataReceived; - } + } private void IrSensor_DataReceived(GattCharacteristic sender, GattValueChangedEventArgs args) @@ -257,10 +258,11 @@ public class SensorTagSensor public Guid Id { get; private set; } public GattDeviceService Service { get; private set; } + public async Task EnableNotifications() { - await Data.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); Data.ValueChanged += getData; + await Data.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); using (var writer = new DataWriter()) {