简体   繁体   English

BLE GATT上传数据-Android

[英]BLE GATT upload data - Android

Trying to connect to BLE device(GATT Server) Using Samsung Galaxy S4, I succeeded to connect to device and got heartbeat. 尝试连接到BLE设备(GATT服务器)使用Samsung Galaxy S4,我成功连接到设备并获得了心跳。

now I need to send 1280 bytes as 16 chunks of 80 bytes. 现在我需要将1280字节作为16个80字节的块发送。 the Device after receiving those 16 chunks should reply with 16 upload status, 设备在收到这16个块后应回复16个上传状态,

what I get is only one upload status for one of the chunks (not specific one , randomly) 我得到的只是其中一个块的一种上传状态(不是特定的一个,是随机的)

I tried to change the sending interval by (this.wait, Thread.sleep..) with many values , without any good result. 我试图通过(this.wait,Thread.sleep ..)更改发送间隔,但具有许多值,但没有任何良好的结果。

Similar application with Objective-c (iPhone ) works fine with device :( 与Objective-c(iPhone)相似的应用程序在设备:(

** I thought it might be related to the Any hints about the issue ? **我认为这可能与有关该问题的任何提示有关? or a way to manage transmission rate (interval)** 或管理传输速率(间隔)的方法**

runOnUiThread(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < chunkToUpload; ++i) {
                sendNthModeData(i);
                try {   
                    //this.wait(100);
                    Thread.sleep(30,1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    });

You need to wait for onCharacteristicWrite to be called in the BluetoothGattCallback before you can send the next bit of data, otherwise the other data will get dropped on the ground. 您需要等待BluetoothGattCallback中的onCharacteristicWrite被调用,然后才能发送下一部分数据,否则其他数据将被丢弃。 So in your override of onCharacteristicWrite , if you have more to write then spin up a Runnable for that write. 因此,在重写onCharacteristicWrite ,如果还有更多要写的onCharacteristicWrite ,则为该写操作增加一个Runnable。

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

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