Skip to content

Instantly share code, notes, and snippets.

@brghena
Created December 9, 2015 02:56
Show Gist options
  • Save brghena/0729612baae067912595 to your computer and use it in GitHub Desktop.
Save brghena/0729612baae067912595 to your computer and use it in GitHub Desktop.
Noble/Bleno Interference Example
#!/usr/bin/env node
var bleno = require('bleno');
bleno.on('stateChange', function(state) {
console.log("StateChange: " + state);
if (state === 'poweredOn') {
console.log("Starting adv...");
bleno.startAdvertising('Bleno/Noble Test');
} else {
console.log("Stopping adv");
bleno.stopAdvertising();
}
});
bleno.on('advertisingStop', function() {
console.log('Advertising stopped');
});
bleno.on('advertisingStartError', function(error) {
console.log('Advertising start with error: ' + error);
});
bleno.on('advertisingStart', function(error) {
console.log('Advertising started: ' + error);
});
#!/usr/bin/env node
var noble = require('noble');
noble.on('stateChange', function(state) {
console.log("StateChange: " + state);
if (state === 'poweredOn') {
console.log("Starting scan...");
noble.startScanning([], true);
}
});
noble.on('scanStop', function() {
console.log("scanStop");
});
noble.on('warning', function(message) {
console.log("Warning: " + message);
});
noble.on('discover', function(peripheral) {
console.log("Found a peripheral: " + peripheral.address);
});
@brghena
Copy link
Author

brghena commented Dec 9, 2015

Bleno / Noble libraries interference example.

Starting either script while the other is already running will cause the first to stop functioning without any callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment