-
Notifications
You must be signed in to change notification settings - Fork 19
/
ble-advertise.js
38 lines (31 loc) · 1.03 KB
/
ble-advertise.js
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
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/
/*********************************************
This Bluetooth Low Energy module demo turns
the module on, starts it advertising as a
peripheral, and writes information when
connected.
*********************************************/
var tessel = require('tessel');
var ble = require('../').use(tessel.port['A']); // Replace '../' with 'ble-ble113a' in your own code
var interval;
ble.on('ready', function(err) {
if (err) return console.log(err);
console.log('started advertising...');
ble.startAdvertising();
});
ble.on('connect', function() {
console.log("We have a connection to master.");
var value = 0;
interval = setInterval(function iteration() {
var str = "Interval #" + value++;
console.log("Writing out: ", str);
ble.writeLocalValue(0, new Buffer(str));
}, 1000);
});
ble.on('disconnect', function() {
// Stop our interval
clearInterval(interval);
// Start advertising again
ble.startAdvertising();
});