Reputation: 33
on android BLE, I measure real time sensing data over notification from BLE device. By default, I get the notify data 1 time per second. However, I want to delay getting data from devices in a certain period. Below is a screenshot of my code.
setNotificationCallback(mTXCharacteristic)
.with(new TemperatureMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
PrintLog.i(" "+TemperatureMeasurementParser.parse(data) + " °C");
//Toast.makeText(getContext(), " "+TemperatureMeasurementParser.parse(data) + " °C", Toast.LENGTH_LONG).show();
//super.onDataReceived(device, data);
onTemperatureMeasurementReceived(device, Float.parseFloat(TemperatureMeasurementParser.parse(data)), TemperatureMeasurementCallback.UNIT_C, null, null);
}
@Override
public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device,
final float temperature, final int unit,
@Nullable final Calendar calendar,
@Nullable final Integer type) {
mCallbacks.onTemperatureMeasurementReceived(device, temperature, unit, calendar, type);
}
public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device,
final float temperature, final int unit,
@Nullable final Calendar calendar,
@Nullable final Integer type, @Nullable final Integer batteryLevel) {
mCallbacks.onTemperatureMeasurementReceived(device, temperature, unit, calendar, type,batteryLevel);
}
});
requestMtu(260).enqueue();
enableNotifications(mTXCharacteristic).enqueue();
//sleep(10000).enqueue();
Upvotes: 3
Views: 620
Reputation: 320
As Youssif said, the sensor is most likely the peripheral device and the application is the central device. The data is transmitted via GATT/GAP, and depending on your GAP configuration you might be "bottlenecked" in the peripheral device.
this post might help you further Bluetooth Low Energy Notification Interval
A software sleep on the application is a hack solution, but none the less a solution :)
Upvotes: 1
Reputation: 13295
The notifications are being sent from the remote sensing device. Therefore, if you want to delay or change the interval at which the sensing data is received, you need to modify the code in the sensor. This is the correct and reliable way to do it. Alternatively, you can start a timer on your Android app (e.g. every 10 seconds). When you get the notifications from the remote device, don't display them. Instead, store them in global variables. Then, when the 10s timer expires, print those variables and restart the timer.
I hope this helps.
Upvotes: 2