简体   繁体   English

Bleno BLE库未按预期发送特征值

[英]Bleno BLE library not transmitting characteristic value as expected

I'm working on Android/iOS apps for an IOT peripheral that is sending BLE data. 我正在为正在发送BLE数据的IOT外设开发Android / iOS应用程序。 Both apps are actually working quite nicely with the physical peripheral device (which is using the Texas Instrument's BLE library). 实际上,这两个应用程序都可以与物理外围设备(使用德州仪器的BLE库)一起很好地工作。

Now that the actual peripherals are working, I'm trying to write an emulator with Bleno so the dev team can be more efficient, but am running into issues transmitting a static string value for a characteristic. 现在实际的外围设备都在工作,我正在尝试与Bleno编写模拟器,以便开发团队可以提高效率,但遇到了为特性传输静态字符串值的问题。

I'm setting up my characteristic like this: 我正在这样设置我的特征:

var bleCharacteristic = function() {
  bleCharacteristic.super_.call(this, {
    uuid: '0321',
    properties: ['read'],
    value: new Buffer('12345'),
  }); 
};

Bleno says that I have to use a node.js buffer to send string data, but on both Android and IOS, the received data is not 12345 , but rather something like this: Bleno说我必须使用node.js缓冲区发送字符串数据,但是在Android和IOS上,接收到的数据都不是12345 ,而是这样的:

{
  value: '3031333031383133303630303864666234643030323030333065303332656530313330313831333036303,
}

Thoughts on why this might be happening? 关于为什么会发生这种情况的想法? Is there some other advertisement data that I'm forgetting to set in the emulator so that the value comes back as expected? 是否忘记了在模拟器中设置一些其他广告数据,以便该值按预期返回?

Here's an example of how I am reading the payload value. 这是我如何读取有效负载值的示例。 This is from our Android app: 这来自我们的Android应用程序:

@Override
public void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, int status) {
    ...
    String payload = bytesToHex(characteristic.getValue());
    ...
}

NOTE: Let me know if there is any other relevant code that I can post. 注意:请告诉我是否还有其他相关代码可以发布。

Your characteristic setup looks fine. 您的特征设置看起来不错。 Although I know nothing about Android, in iOS, you should be able to get the value by calling this. 尽管我对Android一无所知,但在iOS中,您应该可以通过调用它来获得价值。

peripheral.readValue(for: yourCharacteristic)

You can also use BLE utility apps like LightBlue to explore your characteristics. 您还可以使用BLE实用程序应用程序(例如LightBlue)来探索自己的特征。

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

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