Bleno 外设本身改变特征值时如何实现更新值回调

Bleno 外设本身改变特征值时如何实现更新值回调,bleno,Bleno,假设外围设备正在监听某个套接字或管道,我正在其中发送一个值,该值将修改该特性。如何通知中央设备的更改?外围设备和中央设备都在Linux平台上运行。因为不管Linux设备的Pizza示例是什么,只有当central正在写东西时,设备才会通知central。假设值是由Bleno之外的某个程序更改的,我应该在其中实现updateValueCallback?是在onSubscribe上还是在Notify上 您应该使用onSubscribe事件 onSubscribe在中央GATT服务器从您的外围设备订阅

假设外围设备正在监听某个套接字或管道,我正在其中发送一个值,该值将修改该特性。如何通知中央设备的更改?外围设备和中央设备都在Linux平台上运行。因为不管Linux设备的Pizza示例是什么,只有当central正在写东西时,设备才会通知central。假设值是由Bleno之外的某个程序更改的,我应该在其中实现updateValueCallback?是在onSubscribe上还是在Notify上

您应该使用onSubscribe事件

onSubscribe在中央GATT服务器从您的外围设备订阅通知时激发,而onNotify在中央GATT服务器订阅通知后在发送通知时激发

例如,我将我的特征定义如下:

var customCharacteristic = function() {
    bleno.Characteristic.call(this, {
        uuid: 'UUID_HERE',
        properties: ['read', 'notify', '... etc'],
        //Subscribe event
        onSubscribe = function(maxSize, updateValueCallback){
            console.log('subscribe'); //output that we've subscribed
            //Now the central has subscribed, poll something 
            //(the sensor or whatever you're using) every half 
            //second to see if the value has updated
            setInterval(function() {
                //poll sensor or get value or something
                updateValueCallback(new Buffer([VALUE]);
            }, 500);
        },
        //Notify event
        onNotify = function(){
            console.log('notify'); //to show when notification is being sent
        }
    });
}

//Don't forget to deal with when the central unsubscribes, you might want to stop the interval ticker!
大致基于文章,结合。

中的一些想法,您应该使用onSubscribe事件

onSubscribe在中央GATT服务器从您的外围设备订阅通知时激发,而onNotify在中央GATT服务器订阅通知后在发送通知时激发

例如,我将我的特征定义如下:

var customCharacteristic = function() {
    bleno.Characteristic.call(this, {
        uuid: 'UUID_HERE',
        properties: ['read', 'notify', '... etc'],
        //Subscribe event
        onSubscribe = function(maxSize, updateValueCallback){
            console.log('subscribe'); //output that we've subscribed
            //Now the central has subscribed, poll something 
            //(the sensor or whatever you're using) every half 
            //second to see if the value has updated
            setInterval(function() {
                //poll sensor or get value or something
                updateValueCallback(new Buffer([VALUE]);
            }, 500);
        },
        //Notify event
        onNotify = function(){
            console.log('notify'); //to show when notification is being sent
        }
    });
}

//Don't forget to deal with when the central unsubscribes, you might want to stop the interval ticker!

大致以文章为基础,结合。

中的一些想法,您找到了解决方案吗?您找到了解决方案吗?虽然这看起来是Bleno最正确的用法,但情况并不理想。我认为OP想要的是一个简单的updateCharValuecharUUID,NewValue,但它似乎出于某种原因不存在。虽然这看起来是Bleno最正确的用法,但这不是一个理想的情况。我认为OP想要的是一个简单的updateCharValuecharUUID,NewValue,但由于某种原因它似乎并不存在。