Created
July 31, 2016 17:28
-
-
Save jweinberg/d3d43c886bec167ba42ba72ab38ac78e to your computer and use it in GitHub Desktop.
This file contains 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
var noble = require('noble'); | |
var serviceUuids = ['6e400001b5a3f393e0a9e50e24dcca9e'] | |
var characteristicUuids = ['6e400002b5a3f393e0a9e50e24dcca9e'] | |
noble.on('stateChange', function(state) { | |
if (state === 'poweredOn') { | |
noble.startScanning(serviceUuids, false); | |
} else { | |
noble.stopScanning(); | |
} | |
}); | |
noble.on('discover', function(peripheral) { | |
console.log('peripheral with ID ' + peripheral.id + ' found'); | |
peripheral.once('connect', function() { | |
console.log("Connected"); | |
peripheral.on('servicesDiscover', function(services) { | |
var service = services[0]; | |
console.log('Found service ' + service) | |
service.on('characteristicsDiscover', function(characteristics) { | |
var characteristic = characteristics[0]; | |
console.log("characteristi found " + characteristics); | |
var i = 0; | |
setInterval(function() { | |
const buf = Buffer([i, 0xFF, 0xFF]); | |
characteristic.write(buf, true); | |
i = (i + 1) % 255 | |
}, 100); | |
}); | |
console.log('Discovering characteristics'); | |
service.discoverCharacteristics(characteristicUuids) | |
}); | |
peripheral.discoverServices(serviceUuids); | |
}); | |
peripheral.connect(); | |
console.log(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment