[英]Sending and receiving data from a ble device over android
I am interfacing a BLE pedometer to an android phone. 我正在将BLE计步器连接到Android手机。 i have discovered the ble device and able to connect to it.
我发现了ble设备并能够连接到它。 I am sending 20 byte data to ble but how can i check that ble is able to receive data.
我正在向ble发送20字节数据,但如何检查ble是否能够接收数据。
public void writeDataToPedometer(BluetoothDevice device) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Log.d(TAG, "Inside Thread's catch");
e.printStackTrace();
}
BluetoothGattService mGattService = mBluetoothGatt.getService(UUID_PEDOMETER_SERVICE);
mtransmitData = new TransmitData();
if(mGattService == null) {
Log.e("YHService", "SEND UUID Service not found");
} else {
BluetoothGattCharacteristic characterstic = mGattService.getCharacteristic(UUID.fromString("0000ffb2-0000-1000-8000-00805f9b34fb"));
if(characterstic == null) {
Log.e("YHService", "SET_TIME characterstic not found");
} else {
byte command[] = new byte[20];
command[0] = 42;
command[1] = 41;
command[2] = 54;
command[3] = 54;
command[4] = 45 ;
command[5] = 52 ;
command[6] = 59 ;
for (int i = 7 ;i < 20 ; i++ )
command[i] = 0x00;
characterstic.setValue(command);
try {
Thread.sleep(500L);
} catch (InterruptedException var9) {
Log.d("Service", "Inside Catch");
var9.printStackTrace();
}
mBluetoothGatt.writeCharacteristic(characterstic);
setRecieverNotify(mGattService);
setCharacteristicNotification(characterstic, true);
}
}
}
I am using above function to Send data to ble device.Is above function OK for sending data or I should made some modification in it. 我正在使用上面的功能将数据发送到ble设备。上面的功能是否可以发送数据,或者我应该对其进行一些修改。
Where should i look for a reply from pedometer. 我应该在哪里寻找计步器的答复。 is there any Function which will get called when pedometer will send data.
计步器发送数据时会调用任何功能吗?
实现此回调: public final BluetoothGattCallback btleGattCallback = new BluetoothGattCallback() { @Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic, int status) { if(status==BluetoothGatt.GATT_SUCCESS) { //this callback gets called after a successful write operation is performed } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.