[英]Android device as BLE central and read/write operations without any trigger from peripheral
My Android app is made as a BLE central device. 我的Android应用是作为BLE中央设备制成的。 I have a device which is peripheral.
我有一个外围设备。 I want to send some data from Android app to peripheral device without any request from the peripheral.
我想将一些数据从Android应用发送到外围设备,而无需外围设备的任何请求。 Can I achieve this ?
我能做到吗?
In my peripheral device to write data i am using below code : 在我写数据的外围设备中,我使用以下代码:
BluetoothGattCharacteristic charac = Service
.getCharacteristic(UUID.fromString(SampleGattAttributes.LOCAL_TIME));
byte[] value = new byte[1];
String valuetosend = "data from client to server";
value = valuetosend.getBytes();
charac.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
charac.setValue(value);
Log.d("BluetoothLeservice::","Write Status:" + charac.getValue());
boolean status = mBluetoothGatt.writeCharacteristic(charac);
Do I have to do in the same way for central also? 我是否也必须以同样的方式来做中央? Any reference links would be helpful.
任何参考链接都将有所帮助。
I think the process is same, you have to write data to the particular characteristic and service. 我认为过程是相同的,您必须将数据写入特定的特性和服务。 You should know the value of the characteristic and service.
您应该知道特性和服务的价值。 In your case it is
SampleGattAttributes.LOCAL_TIME
. 您的情况是
SampleGattAttributes.LOCAL_TIME
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.