I have a simple app shown below. I have created a primary service and added characteristics to my service using BLENO on node js on Rpi3.
It seems that my app starts and runs ok. I have used two tools to view my BLE service i.e. Nordic nRF application and a simple app I wrote in Android.
Using these apps I can see my BLE app advertising and i can also connect to it. When connected I can see three services which are two generic and one being my "unknown service" which has matching UUID as i have set in my BLE server app.
The problem I am having is when I expend my service, it tells me there are no characteristics set for my service.
I would appreciate if someone could review the code below and check possible reason for no characteristics appearing in my service.
`var bleno = require("bleno");
var BlenoPrimaryService = bleno.PrimaryService;
var Characteristic = bleno.Characteristic;
var Descriptor = bleno.Descriptor;
//var UserConfigCharecteristic = require('./user-config-characteristic');
bleno.on('stateChange', function (state) {
console.log('on -> stateChagne: ' + state);
if (state === 'poweredOn') {
console.log('ble has been powered on');
bleno.startAdvertising('rpi-ble-app', ['fffffffffffffffffffffffffffffff0']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function () {
console.log('-> advertising start');
bleno.setServices([
new BlenoPrimaryService(
{
uuid: 'fffffffffffffffffffffffffffffff0',
charecteristics: [
new Characteristic({
uuid: 'fffffffffffffffffffffffffffffff1', // or 'fff1' for 16-bit
properties: ['read', 'write'], // can be a combination of 'read', 'write', 'writeWithoutResponse', 'notify', 'indicate'
secure: [], // enable security for properties, can be a combination of 'read', 'write', 'writeWithoutResponse', 'notify', 'indicate'
value: null, // optional static value, must be of type Buffer - for read only characteristics
descriptors: [],
onReadRequest: null, // optional read request handler, function(offset, callback) { ... }
onWriteRequest: null, // optional write request handler, function(data, offset, withoutResponse, callback) { ...}
onSubscribe: null, // optional notify/indicate subscribe handler, function(maxValueSize, updateValueCallback) { ...}
onUnsubscribe: null, // optional notify/indicate unsubscribe handler, function() { ...}
onNotify: null, // optional notify sent handler, function() { ...}
onIndicate: null // optional indicate confirmation received handler, function() { ...}
})
]
}
)], function (error) {
console.log('setServices: ' + (error ? 'error ' + error : 'success'));
});
});
bleno.on('servicesSet', function () {
console.log('services set.');
});`
Output for my node.js app is
on -> stateChagne: poweredOn
ble has been powered on
-> advertising start
services set.
setServices: success
via Beraben Systems
No comments:
Post a Comment