通过连接到外部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) 我正在尝试通过 BLE 发送一个 json 字符串,但是,就像 json 有超过 20 个字节一样,我必须发送多个 20 个字节的数据包。
我已经阅读了我找到的所有帖子。一些例子:
所有帖子都包含类似的信息。在第一篇文章中实现了一些功能,但是:
我还没有找到关于这个问题的任何信息.. 任何人都可以帮助我吗?