我有一个简单的应用程序,如下所示。我在 Rpi3 上的节点 js 上使用 BLENO 创建了一个主要服务并为我的服务添加了特性。
看来我的应用程序启动并运行正常。我使用了两个工具来查看我的 BLE 服务,即 Nordic nRF 应用程序和我在 Android 中编写的一个简单应用程序。
使用这些应用程序,我可以看到我的 BLE 应用程序广告,我也可以连接到它。连接后,我可以看到三个服务,两个是通用服务,一个是我的“未知服务”,它具有匹配的 UUID,正如我在我的 BLE 服务器应用程序中设置的那样。
我遇到的问题是,当我使用服务时,它告诉我没有为我的服务设置特征。
如果有人可以查看下面的代码并检查我的服务中没有出现任何特征的可能原因,我将不胜感激。
`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.');
});`
我的 node.js 应用程序的输出是
on -> stateChagne: poweredOn
ble has been powered on
-> advertising start
services set.
setServices: success