首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在节点js上使用BLENO获取主服务的BLE特征。

无法在节点js上使用BLENO获取主服务的BLE特征。
EN

Stack Overflow用户
提问于 2017-06-04 23:11:41
回答 2查看 1.6K关注 0票数 0

我有一个简单的应用程序如下所示。我已经创建了一个主服务,并在Rpi3上的节点js上使用BLENO为我的服务添加了特性。

看来我的应用程序启动并运行正常。我使用了两个工具来查看我的BLE服务,即北欧nRF应用程序和我用Android编写的一个简单的应用程序。

使用这些应用程序,我可以看到我的BLE应用广告,我也可以连接到它。在连接时,我可以看到三个服务,它们是两个通用的,一个是我的“未知服务”,它与我在BLE服务器应用程序中设置的UUID相匹配。

我现在遇到的问题是,当我付出我的服务时,它告诉我没有为我的服务设定任何特征。

如果有人能检查下面的代码,并检查我的服务中没有出现任何特性的可能原因,我将不胜感激。

代码语言:javascript
复制
`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应用程序的输出是

代码语言:javascript
复制
on -> stateChagne: poweredOn
ble has been powered on
-> advertising start
services set.
setServices: success
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-06 23:22:03

好像我发现了问题,我拼错了特征。

我是nodejs的新手,我意识到拼写错误可能是个问题,因为如果你拼写错误,你不会重写,而是会添加一个新的属性。

票数 0
EN

Stack Overflow用户

发布于 2017-07-06 08:51:22

看看这个。https://github.com/sandeepmistry/bleno/issues/301。然而,我的问题是,服务是看不见的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44359701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档