const string HUE_BRIDGE_ADDRESS = http192.168.10.113;
private const int LIGHT_ID = 1;

private async Task TurnLightAsync(int i, bool b)
        {
            try
            {
                var client = new HttpClient();


                string url = String.Format({0}apinewdeveloperlights{1}state, HUE_BRIDGE_ADDRESS, i);
                var httpContent = new StringContent(String.Format(@{{on{0}}}, b.ToString().ToLower()));


                var response = await client.PutAsync(url, httpContent);
                response.EnsureSuccessStatusCode();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }




 

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync();





DeviceInformation device = devices.FirstOrDefault(d = d.Name == TI BLE Sensor Tag);
if (device == null) return;





Find the devices that expose the service  
var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess));






private PnpObjectWatcher _watcher;

private async void InitDeviceWatcher(DeviceInformation device)
        {
            _deviceContainerId = { + device.Properties[System.Devices.ContainerId] + };


            _watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer,
                new string[] { System.Devices.Connected }, String.Empty);


             Add event handlers
            _watcher.Updated += watcher_Updated;
            _watcher.Start();
        }








var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess), new String[] { System.Devices.ContainerId }); DeviceInformation device = devices.FirstOrDefault(d = d.Name == TI BLE Sensor Tag);
if (device == null) return; 
InitDeviceWatcher(device);








private async void watcher_Updated(PnpObjectWatcher sender, PnpObjectUpdate args)
        {
            var connectedProperty = args.Properties[System.Devices.Connected];
            bool isConnected = false;
            if ((_deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected))
            {
                if (isConnected)
                {
                    Debug.WriteLine(Connected);
                }
                else
                {
                    Debug.WriteLine(Disconnected);
                }
            }
        }





private async void watcher_Updated(PnpObjectWatcher sender, PnpObjectUpdate args)
        {
            var connectedProperty = args.Properties[System.Devices.Connected];
            bool isConnected = false;
            if ((_deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected))
            {
                if (isConnected)
                {
                    Debug.WriteLine(Connected);
                    TurnLightAsync(LIGHT_ID, true);
                }
                else
                {
                    Debug.WriteLine(Disconnected);
                    await TurnLightAsync(LIGHT_ID, false);
                }
            }
        } 

