Skip to content

Commit

Permalink
Fix @scheib's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jyasskin committed Apr 3, 2015
1 parent 0aae047 commit 165651a
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -976,34 +976,6 @@ <h2><a>BluetoothDevice</a></h2>
<section>
<h2><a>BluetoothAdvertisingData</a></h2>

<aside class="example">
To retrieve a device and read the iBeacon data out of it,
a developer could use the following code.
Note that this API currently doesn't provide a way
to request devices with certain manufacturer data,
so the iBeacon will need to rotate its advertisements to include a known service
in order for users to select this device in the <code>requestDevice</code> dialog.

<pre class="highlight">var known_service = "A service in the iBeacon's GATT server";
return navigator.bluetooth.requestDevice([{services: [known_service]}])
.then(device => {
var rssi = device.adData.rssi;
var appleData = new DataView(device.adData.manufacturerData.get(0x004C));
if (appleData.getUint16(0, true) !== 0x1502) {
return {isBeacon: false};
}
var uuidArray = new Uint8Array(appleData.buffer, 2, 16);
var major = appleData.getUint16(18, false);
var minor = appleData.getUint16(20, false);
var txPowerAt1m = -appleData.getInt8(22);
return {isBeacon: true,
uuidArray,
major,
minor,
pathLossVs1m: txPowerAt1m - rssi};
});</pre>
</aside>

<p>
To <dfn>create a <a>BluetoothAdvertisingData</a></dfn>
from a <a>Bluetooth device</a> <var>device</var>
Expand Down Expand Up @@ -1089,6 +1061,45 @@ <h2><a>BluetoothAdvertisingData</a></h2>
<dt>readonly attribute Map serviceData</dt>
<dd>Maps <a>UUID</a>s to <a>ArrayBuffer</a>s.</dd>
</dl>

<aside class="example">
<p>
To retrieve a device and read the iBeacon data out of it,
a developer could use the following code.
Note that this API currently doesn't provide a way
to request devices with certain manufacturer data,
so the iBeacon will need to rotate its advertisements to include a known service
in order for users to select this device in the <code>requestDevice</code> dialog.
</p>

<pre class="highlight">var known_service = "A service in the iBeacon's GATT server";
return navigator.bluetooth.requestDevice([{services: [known_service]}])
.then(device => {
var rssi = device.adData.rssi;
var appleData = new DataView(device.adData.manufacturerData.get(<a
href="https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers"
title="Apple, Inc.'s Company Identifier">0x004C</a>));
if (appleData.byteLength != 23 ||
appleData.getUint16(0, false) !== 0x0215) {
return {isBeacon: false};
}
var uuidArray = new Uint8Array(appleData.buffer, 2, 16);
var major = appleData.getUint16(18, false);
var minor = appleData.getUint16(20, false);
var txPowerAt1m = -appleData.getInt8(22);
return {isBeacon: true,
uuidArray,
major,
minor,
pathLossVs1m: txPowerAt1m - rssi};
});</pre>

<p>
The format of iBeacon advertisements was derived from
<a href="http://www.warski.org/blog/2014/01/how-ibeacons-work/">How do iBeacons work?</a>
by Adam Warski.
</p>
</aside>
</section>
</section>
</section>
Expand Down

0 comments on commit 165651a

Please sign in to comment.