-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
executable file
·415 lines (399 loc) · 29.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Sabertooth</title>
<link rel="icon" href="https://avatars3.githubusercontent.com/u/19232538?v=3&s=200">
<link rel="shortcut icon" type="image/png" href="https://avatars3.githubusercontent.com/u/19232538?v=3&s=200"/>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/github-light.css">
<meta name="viewport" content="width=device-width">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href='https://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<!-- start Mixpanel --><script type="text/javascript">(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
mixpanel.init("7fba5a7488b96deeff583810ce98fc1b");</script><!-- end Mixpanel -->
</head>
<body>
<a href="#" ><img class="scrollToTop" src="./assets/scroll.png"></img></a>
<div class="wrapper">
<header>
<h1><img id="logo" src="https://avatars3.githubusercontent.com/u/19232538?v=3&s=200"/><br>   Sabertooth<br></h1>
<h3><br>A Javascript Library for interacting with Bluetooth Low Energy Devices.</h3>
<p></p>
<!-- Place this tag where you want the button to render. -->
<div class="badges">
<iframe src="http://ghbtns.com/github-btn.html?user=sabertooth-io&repo=web-bluetooth&type=watch&count=true" height="30" width="130" frameborder="0" scrolling="0" style="width:100px; height: 30px;" allowTransparency="true"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=sabertooth-io&repo=web-bluetooth&type=fork&count=true" height="30" width="118" frameborder="0" scrolling="0" style="width:118px; height: 30px;" allowTransparency="true"></iframe>
</div>
<p class="view">
<a href="https://github.com/sabertooth-io/web-bluetooth">View on GitHub</a>
<br>
<a href="https://npmjs.com/package/web-bluetooth">View package on npm</a>
<br>
View package on Bower (coming soon!)
</p>
<hr>
<p>
<a href="#intro">Intro</a>
<br>
<a href="#overview">Overview</a>
<br>
<a href="#getting-started">Getting Started</a>
</p>
<hr>
<h4>Docs</h4>
<p>
<a href="#general-accessibility">General Accessibility</a>
<br>
<a href="#gatt-support">GATT Services Support</a>
<hr>
<a href="#general-newdevice">Creating a new Bluetooth Device</a>
<br><a href="#general-methods">Device Methods</a>
<br>   <a href="#method-connect">.connect()</a>
<br>   <a href="#method-disconnect">.disconnect()</a>
<br>   <a href="#method-connected">.connected()</a>
<br>   <a href="#method-getvalue">.getValue()</a>
<br>   <a href="#method-writevalue"> .writeValue()</a>
<br>   <a href="#method-startnotifications">.startNotifications()</a>
<br>   <a href="#method-stopnotifications">.stopNotifications()</a>
<br>   <a href="#method-addcharacteristic">.addCharacteristic()</a>
</p>
<hr>
<h4>Demos</h4>
<p>
<a href="#demos">Heart Rate Service</a><br>
<a href="#demos">Battery Service</a>
</p>
<hr>
<h4>Appendix</h4>
<p>
<a href="#authors-contributors">Authors & Contributors</a>
</p>
</header>
<section>
<h3>
<a id="intro" class="anchor" href="#welcome-to-github-pages" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Bridging the gap between the web and the physical world through Bluetooth.</h3>
<img class="intro-infographic" src="assets/BLE-WebInfographic.svg" height="80%" width="80%" horizontal-align="center">
<p>Bluetooth devices are everywhere, and as developers, we want to write useful, fun, and powerful applications for them. Until recently, this meant writing native applications that had to be installed on user devices- a burdensome process for both users and developers. With the number of Bluetooth devices around us, a more direct and intuitive interface was long overdue. <br><br>Now, thanks to the <a href="https://www.w3.org/community/web-bluetooth/">Web Bluetooth Community Group</a> and their work to bring us the <a href="https://webbluetoothcg.github.io/web-bluetooth/">Web Bluetooth API</a>, we have the ability to interact directly with Bluetooth Low Energy (part of the Bluetooth 4.0 standard) devices through the browser. Connecting, reading, and writing to and from Bluetooth devices is all made possible through the Web Bluetooth API and modern web browsers like Chrome, Firefox, and Opera who are incresingly adding support for new features in the Web Bluetooth API Spec.</p>
<p>We at Sabertooth are excited by the potential for the Web Bluetooth API, but also recognize that developers like ourselves just want to build things, not spend time wading through documentation and hiking up the learning curve with every new technology we use. Sabertooth is an attempt to harness the power of the Web Bluetooth API and make it easily accessible to developers through a simple and intuitive library. In short, we want you to start building powerful, browser-based Bluetooth applications quickly and effortlessly, and have fun doing it.</p>
<h3>
<a id="overview" class="anchor" href="#designer-templates" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Overview</h3>
<p>Sabertooth is a configurable application library for integrating Bluetooth functionality with client-side Javascript.</p>
<h3>
<a id="getting-started" class="anchor" href="#creating-pages-manually" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Getting Started</h3>
<p>Sabertooth has a few easy ways to quickly get started, each one appealing to your preferences.</p>
<blockquote >Note: Sabertooth package names and file names appear as 'web-bluetooth' throughout the documentation, consistent with actual package names and file names you will encounter when searching for or working with Sabertooth.</blockquote>
<br>
<!-- <h4>Download</h4>
<p>You can install Sabertooth by downloading our minified framework <a href="https://github.com/sabertooth-io/web-bluetooth/archive/master.zip" target="_blank">here</a>.</p>
<p>Make the library available by referencing it in your index.html file.</p>
<pre><code class="code"><script>/lib/web-bluetooth.js</script></code></pre> -->
<h4>Install with npm</h4>
<p>You can install Sabertooth as the npm package 'web-bluetooth' <a href="https://npmjs.com/package/web-bluetooth" target="_blank"> here</a>.</p>
<p>Or run the command-line script below in the project directory in which you would like to use Sabertooth.</p>
<pre><code class="code">$ npm install web-bluetooth</code></pre>
<!--FIXME: We're not doing an iffy anymore, what is the right thing to show here? -->
<p><code>require('web-bluetooth')</code> will load all of the files necessary to run Sabertooth.</p>
<pre><code class="code">const BluetoothDevice = require('web-bluetooth');</code></pre>
<!-- <h4>Install with Bower</h4>
<p>You can install web-bluetooth with <a href="http://bower.io/" target="_blank">Bower</a></p>
<pre><code class="code">$ bower install web-bluetooth</code></pre> -->
<h3 id="general-accessibility">
<span aria-hidden="true" class="octicon octicon-link"></span>General Accesibility
</h3>
<p>While the Web Bluetooth API is still in development, certain features have been made available.
</p>
<div>
<blockquote>
Note: The functionality of Sabertooth is contingent upon the permissions and availabilities of the Web Bluetooth API. The Web Bluetooth API is still in development and many features have not been
implemented across browsers. For the current status of the API, please follow this
<a href="https://webbluetoothcg.github.io/web-bluetooth/" target="_blank">link</a>.
</blockquote>
</div>
<table class="tables">
<tr>
<th id="feature-type">Feature</th>
<th>ChromeOS</th>
<th>Android Mobile</th>
<th>MacOSX</th>
</tr>
<tr>
<td id="feature-type">Device Discovery</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td id="feature-type">Device Connecting</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td id="feature-type">Device Disconnecting</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td id="feature-type">Device Services Read</td>
<td>✓</td>
<td>✓</td>
<td></td>
</tr>
</table>
<blockquote >Note: To enable the browser to use the Web Bluetooth API (and Sabertooth), experimental flags must be enabled and an https server are required.<br>
<img style="width: 480px; margin-top: 10px;" src="https://developers.google.com/web/updates/images/2015-07-22-interact-with-ble-devices-on-the-web/web-bluetooth-flag.png" />
Please see <a href="https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web">Interact with BLE Devices on the Web</a> for more information.
</blockquote>
<br>
<h3><span aria-hidden="true" class="octicon octicon-link"></span>GATT Attributes</h3>
<p>A basic understanding of the <a href="https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx">Generic Attribute Profile (GATT)</a> is helpful when writing applications to interact with Bluetooth devices, but using Sabertooth requires an understanding of two main GATT attributes, GATT services and GATT characteristics.</p>
<p><b>GATT Services</b> are collections of GATT characteristics, and <b>GATT Characteristics</b> are attributes that contain values.</p>
<img style="height: 250px" src="https://cdn-learn.adafruit.com/assets/assets/000/013/828/original/microcontrollers_GattStructure.png?1390836057" />
<p>Sabertooth abstracts over the core features of the Web-Bluetooth API, and allows for the use of virtually any GATT service or GATT characteristic, as well as non-GATT services and non-GATT characteristics.</p>
<p>For the complete list of normative GATT services click <a href="https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx" target="_blank">here</a>. As the Web Bluetooth API continues to be developed and as this library matures, full support for more service types will be made available.</p>
<!-- <p>For the complete list of GATT services and GATT characteristics currently fully supported by Sabertooth click <a href="#serviceschars" target="_blank">here</a>.</p> -->
<h3 id="general-newdevice">
<span aria-hidden="true" class="octicon octicon-link"></span>Creating a New Bluetooth Device
</h3>
<h4 class="method-name" id="method-newdevice">
new BluetoothDevice(<i>filters</i>)
</h4>
<p>To begin interacting with a Bluetooth device, create a new instance of <code>BluetoothDevice</code> and save the result to a variable. <code>BluetoothDevice</code> is a constructor that takes in an object <code>filters</code> containing attributes advertised by the Bluetooth device.</p>
<p>
<b>Parameters</b>
<br>
<code>filters</code> - an object containing at least one valid filter corresponding to attributes advertised by the bluetooth device through which Sabertooth will attempt to request and connect to the device. Below is a schema representing the optional parameters that can be passed into the <code>BluetoothDevice</code> constructor to create a new <code>BluetoothDevice</code> instance. At least one of the key-value pairs below is needed to request a device and establish an initial connection.
<blockquote >
Note: Parameters passed into the <code>filters</code> object of the <code>BluetoothDevice</code> constructor are inclusive; a request and connection to a device can only succeed if the device satisfies all of the provided filters.
</blockquote><br>
<pre><code>{
name: 'device_name',
namePrefix: 'devicePrefix',
uuid: 'uuid',
services: ['service', 'service', 'service'],
<i>optional_services: ['service','service','service']</i>
}</code></pre>
<code>name </code> - the advertised the name of the device; often set by the manufacturer unless modified by the device user<br>
<code>namePrefix</code> - an initial substring of any length that matches an advertised device name<br>
<code>uuid</code> - represents a 128-bit <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier">universally unique identifier</a> (uuid). A valid uuid is a string that matches
the regexp <code>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/</code><br>
<code>services</code> - an array including at least one service being advertised by the device.
<blockquote> Note: Not all services present on a device are advertised. Attempting to access a device by including a filter for a service present on a device but not being advertised by the device will cause the request to the device to fail.</blockquote>
<br><code>optional_services</code> - an array of services for which data exchange with the device will be allowed, following a successful connection to the device.
<blockquote>Note: Any services on the device included in <code>services</code> will be accessible following a successful connection to the device, so a service need not be included in <code>optional_services</code> if the same service has already been included in <code>services</code>. Services can not be added to a device after the device instance has been created.</blockquote>
<br>
<b>Returns</b>
<br>
A new <code>BluetoothDevice</code> instance on which Sabertooth methods can be called.
</p>
<b>Example</b>
<pre><code>var exampleDevice = new BluetoothDevice({
name: 'Surge'
});</code></pre>
<p>In the example above, a new <code>BluetoothDevice</code> instance <code>exampleDevice</code> has been created with a valid request filter. The device <code>name</code> is one of the many properties advertised by Bluetooth devices and serves as a possible identifier for establishing initial connections to the device. In this example, the device <code>name</code> will act as the provided filter.
</p>
<p>
Below are several other examples of ways in which a new <code>BluetoothDevice</code> instance can be created using different filters or combinations of filters.
<pre><code><i>/* Attempts to request a device advertising a name
* beginning with the substring 'Po'
*/</i>
var exampleDevice = new BluetoothDevice({
namePrefix: 'Po'
});</code></pre>
<pre><code><i>/* Attempts to request a device advertising the name
* 'Polar H7 Heart Rate Sensor' and ALSO advertising the
* GATT service 'heart_rate'
*/</i>
var exampleDevice = new BluetoothDevice({
name: 'Polar H7 Heart Rate Sensor'
service: ['heart_rate']
});</code></pre>
</p>
<hr>
<h3 id="general-methods">
<span aria-hidden="true" class="octicon octicon-link"></span>General Methods
</h3>
<h4 class="method-name" id="method-connect">
.connect()
</h4>
<p>Method establishes a persistent connection with a Bluetooth device.</p>
<p>
<b>Parameters</b>
<br>None.
</p>
<p>
<b>Returns</b>
<br>A Promise to the device GATT server for the connected device.
</p>
<b>Example</b>
<pre><code>exampleDevice.connect();</code></pre>
<p>In the example above, a connection to a previously created <code>BluetoothDevice</code> instance named <code>exampleDevice</code> will be attempted.
</p>
<hr>
<h4 class="method-name" id="method-disconnect">
.disconnect()
</h4>
<p>Method removes a previous connection with a Bluetooth device.</p>
<b>Parameters</b>
<p>None.</p>
<b>Returns</b>
<p>A boolean representing the success of the attempt to disconnect from the device where <code>true</code> represents success.</p>
<b>Example</b>
<pre><code>exampleDevice.disconnect();</code></pre>
<p>In the example above, an attempt to disconnect from a previously created <code>BluetoothDevice</code> instance named <code>exampleDevice</code> will be attempted.
</p>
<hr>
<h4 class="method-name" id="method-connected">
.connected()
</h4>
<p>Method returns the current connection status of the device.</p>
<b>Parameters</b>
<p>None.</p>
<b>Returns</b>
<p>A boolean representing the success of the attempt to disconnect from the device where <code>true</code> is connected and <code>false</code> is disconnected.</p>
<b>Example</b>
<pre><code>exampleDevice.connected();</code></pre>
<p>In the example above, an attempt will be made to check the connection status of a previously created <code>BluetoothDevice</code> instance named <code>exampleDevice</code>.
</p>
<hr>
<h4 class="method-name" id="method-getvalue">
<span aria-hidden="true" class="octicon octicon-link"></span>.getValue(<i>characteristic</i>)
</h4>
<p>Method attempts to read the value of provided characteristic from a connected <code>BluetoothDevice</code> instance.</p>
<b>Parameters</b>
<p>
<code>characteristic</code> - a GATT characteristic or 128-bit uuid string that resolves to a characteristic accessible on the device.
</p>
<b>Returns</b>
<p>
An <code>object</code> containing the <a href="https://tc39.github.io/ecma262/#sec-arraybuffer-constructor">ArrayBuffer</a> value read from the connected <code>BluetoothDevice</code> instance, saved to the key <code>.rawValue</code>. For characteristics fully supported by Sabertooth, the return <code>object</code> will also include any parsed values for available descriptors of the requested characteristic as key-vlaue pairs with the descriptor as the key and the parsed value as the value.
</p>
<b>Example</b>
<pre><code>exampleDevice.getValue('battery_level')
.then(value => {
console.log(value.battery_level);
});</code></pre>
<p>In the above example, the <code>.getValue()</code> method is called on the <code>BluetoothDevice</code> instance <code>exampleDevice</code>, which returns an <code>object</code>, in this example referenced as <code>value</code>. <code>value</code> contains the ArrayBuffer returned from the device stored to the property <code>rawValue</code>, and because 'battery_level' is a fully supported characteristic in Sabertooth, <code>value</code> also contains the parsed integer value for the instance's battery level, stored on the <code>value</code> object as the key <code>battery_level</code>. In this example, the parsed integer value representing the device's battery level is being logged to the console.</p>
<hr>
<h4 class="method-name" id="method-writevalue">
<span aria-hidden="true" class="octicon octicon-link"></span>.writeValue(<i>characteristic</i>, <i>value</i>)
</h4>
<p>Method takes a characteristic and value and attempts to write the provided value to the provided characteristic on the device.</p>
<b>Parameters</b>
<p>
<code>characteristic</code> - a GATT characteristic or 128-bit uuid string that resolves to a characteristic accessible on the device instance.
<br><code>value</code> - an ArrayBuffer or DataView
</p>
<b>Returns</b>
<p>A boolean representing the success of the attempt to write to the provided characteristic where <code>true</code> represents success.</p>
<b>Example</b>
<pre><code>exampleDevice.writeValue('gap.device_name', 'myFitbit' )
.then(writeSuccess => {
console.log(writeSuccess);
}); </code></pre>
<p>In the above example, .writeValue() changes the name of the instantiated device to myFitbit.</p>
<hr>
<h4 class="method-name" id="method-startnotifications">
<span aria-hidden="true" class="octicon octicon-link"></span>.startNotifications(<i>characteristic</i>, <i>callback</i>)
</h4>
<p>Method takes a characteristic name and a callback function. Provided that the characteristic has a 'notify' property, .startNotifications() will pass the event object broadcasted by the characteristic as the parameter of the callback, and run the callback each time a new event occurs.</p>
<b>Parameters</b>
<p>
<code>characteristic</code> - a GATT characteristic or 128-bit uuid string that resolves to a characteristic accessible on the device instance.
<br><code>callback</code> - a callback triggered as result of a notification from the provided characteristic advertised by the device. The parameter <code>eventObj</code> will automatically be passed into <code>callback</code> for each notification received from the device.
<br><p class="level2Param"><code>eventObj</code> - an <code>object</code> passed as the sole parameter into the callback provided. <code>eventObj</code> contains the ArrayBuffer value notified from the connected <code>BluetoothDevice</code> instance, saved to the key <code>.rawValue</code>. For characteristics fully supported by Sabertooth, <code>eventObj</code> will also include any parsed values for available descriptors of the requested characteristic as key-vlaue pairs with the descriptor as the key and the parsed value as the value.
</p>
</p>
<b>Returns</b>
<p>
None.
</p>
<b>Example</b>
<pre><code>exampleDevice.startNotifications('heart_rate_measurement', eventObj => {
var newHR = eventObj.heart_rate_measurement;
console.log(newHR);
}); </code></pre>
<p>In the above example, the <code>.startNotifications()</code> method is called on the <code>BluetoothDevice</code> instance <code>exampleDevice</code>, which attempts to initiate a stream of notifications from the Bluetooth device, where the provided callback, in this example an anonymous function with the parameter <code>eventObj</code>, will be applied to the <code>eventObj</code> returned from each notification from the device. In this example, <code>eventObj</code> contains the ArrayBuffer returned from the device notification, stored to the property <code>rawValue</code>, and because 'heart_rate_measurement' is a fully supported characteristic in Sabertooth, <code>eventObj</code> also contains the parsed integer value for the device's heart rate measurement, stored on the <code>eventObj</code> object as the key <code>heart_rate_measurement</code>. In this example, the parsed integer value representing the notification's heart rate measurement is being logged to the console.</p>
<hr>
<h4 class="method-name" id="method-stopnotifications">
<span aria-hidden="true" class="octicon octicon-link"></span>.stopNotifications(<i>characteristic</i>)
</h4>
<p>This method stops the notifications from the provided characteristic for the <code>BluetoothDevice</code> instance.</p>
<p>
<b>Parameters</b>
<br>None.
</p>
<p>
<b>Returns</b>
<br>None.
</p>
<b>Example</b>
<pre><code>exampleDevice.stopNotifications('heart_rate_measurement'); </code></pre>
<p>In the above example, the <code>.stopNotifications()</code> method is called on the <code>BluetoothDevice</code> instance <code>exampleDevice</code>, which attempts to end a stream of notifications from the Bluetooth device.</p>
<hr>
<h4 class="method-name" id="method-addcharacteristic">
<span aria-hidden="true" class="octicon octicon-link"></span>.addCharacteristic(<i>characteristic</i>, <i>service</i>, <i>properties</i>)
</h4>
<p>This method adds Sabertooth support for the provided characteristic to device instance on which the method was called.
<br><br>
<b>Parameters:</b>
<br>
<code>characteristic</code> - a GATT characteristic or 128-bit uuid string that resolves to a characteristic accessible on the device instance<br>
<code>service</code> - a GATT service or 128-bit uuid string that resolves to a service accessible on the device instance<br>
<code>properties</code> - an array containing at least one property existing on the characteristic to be added. Currently, Sabertooth supports the properties <b>'read'</b>, <b>'write'</b>, and <b>'notify'</b>.
<br><br>
<b>Returns:</b>
<br>
A boolean representing the success of the attempt to add the characteristic to the device instance where <code>true</code> represents success.
</p>
<blockquote >Note: For characteristics added to the device instance, Sabertooth cannot parse values read from the device or prepare values to be written to the device. Returned values from device calls to the .readValue() method will return an object containing the raw data returned from the device; device calls to the .writeValue() method will attempt to write the provided value directly to the device in its provided form.
</blockquote>
<br>
<pre><code>exampleDevice.addCharacteristic(
'9a66fd22-0800-9191-11e4-012d1540cb8e',
'9a66fd21-0800-9191-11e4-012d1540cb8e',
['read','write','notify']); </code></pre>
<p>In the above example, the <code>.addCharacteristic()</code> method is called on the <code>BluetoothDevice</code> instance <code>exampleDevice</code>, which returns an <code>object</code>, in this example referenced as <code>value</code>, containing the parsed integer value for the instance's battery level, stored on the <code>value</code> object as the key <code>battery_level</code>.</p>
<hr>
<h3 id="demos">
Demos
</h3>
<h4>Heart Rate Service</h4>
<a href="https://github.com/sabertooth-io/demo-heart_rate_service" target="_blank"><img src="assets/heart_rate_service.png" height="80%" width="80%" horizontal-align="center"></a>
<p>This demo uses the Sabertooth library to connect to a heart rate monitor broadcasting a Heart Rate Service characteristic and reads it's measurement.</p>
<p>
<a href="https://github.com/sabertooth-io/demo-heart_rate_service" target="_blank">Visit the GitHub page.</a>
</p>
<h4>Battery Service</h4>
<a href="https://github.com/sabertooth-io/demo-battery_service" target="_blank"><img src="assets/battery_service.png" height="80%" width="80%" horizontal-align="center"></a>
<p>This demo uses the Sabertooth library to connect to a device broadcasting a Battery Service characteristic and reads it's level.</p>
<p>
<a href="https://github.com/sabertooth-io/demo-battery_service" target="_blank">Visit the GitHub page.</a>
</p>
<p>Notes: <br>
• Requires Android 6.0 Marshmallow, ChromeOS, or Chrome for Linux.<br>
• Enable the 'Web Bluetooth' flag.
<hr>
<h3>
<span id="authors-contributors" aria-hidden="true" class="octicon octicon-link"></span>Authors and Contributors
</h3>
<p>Sabertooth is a team of four software developers enthusiastic to be contributing to the open source community. Visit their GitHub pages for more information.</p>
<ul>
<li>Aaron Peltz | <a href="https://github.com/apeltz/" target="_blank">GitHub</a></li>
<li>Alex Patch | <a href="https://github.com/the-gingerbread-man/" target="_blank">GitHub</a></li>
<li>Carlos Corral | <a href="https://github.com/ccorral/" target="_blank">GitHub</a></li>
<li>Daniel Lee | <a href="https://github.com/dslee393/" target="_blank">GitHub</a></li>
</ul>
</section>
</div>
<script src="scripts/scale.fix.js"></script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</body>
</html>