简体   繁体   English

在节点js上使用BLENO无法使BLE特性出现在主服务中

[英]Can not get BLE characteristics to appear for primary service using BLENO on node js

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. 我已经在Rpi3的node js上使用BLENO创建了主要服务并向服务中添加了特征。

It seems that my app starts and runs ok. 看来我的应用程序启动并运行正常。 I have used two tools to view my BLE service ie Nordic nRF application and a simple app I wrote in Android. 我使用了两种工具来查看我的BLE服务,即Nordic nRF应用程序和我在Android中编写的简单应用程序。

Using these apps I can see my BLE app advertising and i can also connect to it. 使用这些应用程序,我可以看到我的BLE应用程序广告,并且我也可以连接到它。 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. 连接后,我可以看到三种服务,这两种服务是通用的,一种是我的“未知服务”,它具有与我在BLE服务器应用中设置的UUID相匹配的功能。

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 我的node.js应用的输出是

on -> stateChagne: poweredOn
ble has been powered on
-> advertising start
services set.
setServices: success

Check this one. 检查这一。 https://github.com/sandeepmistry/bleno/issues/301 . https://github.com/sandeepmistry/bleno/issues/301 However, my problem was that services were not visible. 但是,我的问题是服务不可见。

Seems I have found the problem, I had misspelled Characteristics. 似乎我发现了问题,我的特征拼写错误。

I'm new to nodejs and realise that mis-spelling can be an issue since if you mis-spell you wont override instead you will add a new property. 我是nodejs的新手,并且意识到拼写错误可能是一个问题,因为如果拼写错误,您将不会覆盖,而是会添加一个新属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM