Skip to content

Commit

Permalink
Add some noble script prototyping
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Schneider committed Feb 17, 2018
1 parent 7636149 commit 1be55a6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/index.js
@@ -0,0 +1,58 @@
const noble = require('noble');

noble.on('scanStart', function (state) {
console.log('Start scannig', state);
});

noble.on('scanStop', function (state) {
console.log('Stop scanning', state);
});

noble.on('stateChange', function (state) {
console.log('State change', state);
});

noble.on('warning', function (state) {
console.log('Warning', state);
});

noble.on('discover', function (peripheral) {
peripheral.connect(function (error) {
if (error) {
console.log(error);
return;
}

console.log('Peripheral ID', peripheral.id);
peripheral.discoverServices([], function (error, services) {
// console.log(error);
// console.log(services);

services.forEach(function(service) {
console.log(' ' + service.name);

service.discoverCharacteristics([], function(error, characteristics) {
characteristics.forEach(function (characteristic) {
let characteristicInfo = ' ' + characteristic.uuid;

if (characteristic.name) {
characteristicInfo += ' (' + characteristic.name + ')';
}

characteristic.discoverDescriptors(function(error, descriptors) {
descriptors.forEach(function (descriptor) {
descriptor.readValue([function(error, data) {
characteristicInfo += data.toString();
}]);
})
});

console.log(' ' + characteristicInfo);
})
});
});
});
});
});

noble.startScanning();

0 comments on commit 1be55a6

Please sign in to comment.