Created
May 26, 2017 14:56
-
-
Save peterfoot/980eb1174b37aec02f100d721b20c50c to your computer and use it in GitHub Desktop.
iBeacons in UWP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App() | |
{ | |
this.InitializeComponent(); | |
this.Suspending += OnSuspending; | |
_watcher = new BluetoothLEAdvertisementWatcher(); | |
_watcher.Received += _watcher_Received; | |
_watcher.Start(); | |
} | |
private void _watcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args) | |
{ | |
foreach(BluetoothLEManufacturerData md in args.Advertisement.ManufacturerData) | |
{ | |
if(md.CompanyId == 0x4C) // Apple | |
{ | |
DataReader reader = DataReader.FromBuffer(md.Data); | |
byte advertismentType = reader.ReadByte(); // 0x02 - iBeacon | |
byte len = reader.ReadByte(); // 0x15 (21) - iBeacon | |
int a = reader.ReadInt32(); | |
short b = reader.ReadInt16(); | |
short c = reader.ReadInt16(); | |
byte[] d = new byte[8]; | |
reader.ReadBytes(d); | |
Guid uuid = new Guid(a, b, c, d); | |
ushort major = reader.ReadUInt16(); | |
ushort minor = reader.ReadUInt16(); | |
Debug.WriteLine(uuid + " " + major + " " + minor + " " + args.RawSignalStrengthInDBm); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment