Skip to content

Instantly share code, notes, and snippets.

@hardillb
Created February 6, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardillb/9a8b76c325e063b39e45 to your computer and use it in GitHub Desktop.
Save hardillb/9a8b76c325e063b39e45 to your computer and use it in GitHub Desktop.
Simple HelloWorld bleno iBeacon test app
var bleno = require('bleno');
var uuid = 'B9407F30F5F8466EAFF925556B57FE6D';
var major = 0;
var minor = 0;
var measuredPower = -59;
var data = new Buffer('HelloWorld');
bleno.on('stateChange', function(state) {
if (state === 'poweredOn') {
bleno.startAdvertisingIBeacon(uuid, major, minor, measuredPower);
console.log('Advertising');
} else {
bleno.stopAdvertising();
console.log('Stopped Advertising');
}
});
bleno.on('startAdvertising', function(err){
if (!err) {
bleno.setServices([
new bleno.PrimarySerivce({
uuid: 'B9407F30F5F8466EAFF925556B57FE6D',
characteristics : [
new bleno.Characteristic({
uuid: 'bb9a18a633564f4ca5b5-19a738bc3ae9',
properties: ['read', 'writeWithoutResponse'],
onReadRequest: function(offset, callback) {
if (offset > data.length) {
callback(bleno.Characteristic.RESULT_INVALID_OFFSET);
} else {
callback(bleno.Characteristic.RESULT_SUCCESS, data.slice(offset));
}
},
onWriteRequest: function(newData, offset, withoutResponse, callback) {
if (offset > 0) {
callback(bleno.Characteristic.RESULT_INVALID_OFFSET);
} else {
console.log(newData.toString('utf8'));
callback(bleno.Characteristic.RESULT_SUCCESS);
}
}
})
]
})
]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment