相关疑难解决方法(0)

Android:通过BLE发送> 20个字节的数据

通过连接到外部BLE设备,我能够发送最多20个字节的数据.如何发送大于20个字节的数据.我已经读过,我们必须将数据分段或将特征分割为所需的部分.如果我假设我的数据是32个字节,你能否告诉我需要在我的代码中进行的更改才能使其正常工作?以下是我的代码中所需的代码段:

public boolean send(byte[] data) {
    if (mBluetoothGatt == null || mBluetoothGattService == null) {
        Log.w(TAG, "BluetoothGatt not initialized");
        return false;
    }

    BluetoothGattCharacteristic characteristic =
            mBluetoothGattService.getCharacteristic(UUID_SEND);

    if (characteristic == null) {
        Log.w(TAG, "Send characteristic not found");
        return false;
    }

    characteristic.setValue(data);
    characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
    return mBluetoothGatt.writeCharacteristic(characteristic);
}
Run Code Online (Sandbox Code Playgroud)

这是我用来发送数据的代码."发送"功能用于以下onclick事件.

sendValueButton = (Button) findViewById(R.id.sendValue);
    sendValueButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String text = dataEdit.getText().toString();                           
            yableeService.send(text.getBytes());
        }
    });
Run Code Online (Sandbox Code Playgroud)

String text大于20个字节时,仅接收前20个字节.如何纠正这个?

为了测试发送多个特性我试过这个:

sendValueButton = (Button) findViewById(R.id.sendValue);
sendValueButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth-lowenergy

47
推荐指数
7
解决办法
7万
查看次数

通过 BLE 发送超过 20 个字节

我正在尝试通过 BLE 发送一个 json 字符串,但是,就像 json 有超过 20 个字节一样,我必须发送多个 20 个字节的数据包。

我已经阅读了我找到的所有帖子。一些例子:

所有帖子都包含类似的信息。在第一篇文章中实现了一些功能,但是:

  • “BLE.INITIAL_MESSAGE_PACKET”和“BLE.DEFAULT_BYTES_IN_CONTINUE_PACKET”变量是什么?每个变量的声明在哪里?
  • “sendingLastPacket(characteristic, initial_packet, CHARACTERS)”函数在哪里?
  • 在接收端,如何合并发送端发送的所有数据包?

我还没有找到关于这个问题的任何信息.. 任何人都可以帮助我吗?

android bluetooth-lowenergy

5
推荐指数
0
解决办法
1282
查看次数

标签 统计

android ×2

bluetooth-lowenergy ×2

java ×1