androidthings / sample-bluetooth-le-gattserver Goto Github PK
View Code? Open in Web Editor NEWBuild a Bluetooth GATT server with Android Things
License: Apache License 2.0
Build a Bluetooth GATT server with Android Things
License: Apache License 2.0
Here you just send the descriptor information to the client. All must be good & you don't need to use GATT_FAIL but BluetoothGatt.GATT_SUCCESS
instead...
isn't it?
I use Android phone and cannot pair with Android Things (Raspberry Pi 3) through Android Phone Settings -> Bluetooth -> Pair new device or createBond programmatically.
According to adopted BLE Current time Service specifications (https://www.bluetooth.com/specifications/adopted-specifications)
"A server device shall notify this characteristic to the client device depending on the value of Client Characteristic Configuration descriptor when the time of the server device is adjusted. The events that can cause the local time in the server device to change are user interaction (setting time via UI), time zone change, DST offset change, or reference time change. These events are not exclusive."
ACTION_TIME_TICK however, is sent every minute. The notifications should be sent when the time is adjusted.
Hi
I have written a simple GATT client that interacts with your server:
https://github.com/jmc420/sample-bluetooth-le-gattclient
I wrote the client because I am getting a connect followed immediately by a disconnect before the client is able to read the time characteristic.
This appears to be caused by this stack trace:
05-22 15:12:32.110 11559-11571/com.example.androidthings.gattserver W/BluetoothGattServer: Unhandled exception in callback
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at android.os.Parcel.readException(Parcel.java:1699)
at android.os.Parcel.readException(Parcel.java:1646)
at android.bluetooth.IBluetoothGatt$Stub$Proxy.sendResponse(IBluetoothGatt.java:1424)
at android.bluetooth.BluetoothGattServer.sendResponse(BluetoothGattServer.java:599)
at com.example.androidthings.gattserver.GattServerActivity$gattServerCallback$1.onDescriptorWriteRequest(GattServerActivity.kt:197)
at android.bluetooth.BluetoothGattServer$1.onDescriptorWriteRequest(BluetoothGattServer.java:261)
at android.bluetooth.IBluetoothGattServerCallback$Stub.onTransact(IBluetoothGattServerCallback.java:263)
at android.os.Binder.execTransact(Binder.java:573)
I wrote a stackoveflow question on this issue:
https://stackoverflow.com/questions/50393196/bluetooth-le-gatt-client-and-server
Does the same thing happen for you?
I run this demo in my phone,then use another phone connect this phone ,but failed.I don't know what's wrong.
I have a problem with discoverability of the device and the reconnection after i disconnect from a client.
The only solution was to reboot the rpi and i be able to re-discover and re-connect from my client app.
If you have some advice for resolving this issue.
EDIT: I have an Error 133 (0x85) when i tried to reconnect.
just a minor issue but I got the following logcat message while running on a raspberry pi 3
com.example.androidthings.gattserver I/Choreographer: Skipped 86 frames! The application may be doing too much work on its main thread.
wouldn't it be better to move the UI code mLocalTimeView.setText(displayDate);
to another thread e.g. a runnable inside a runOnUiThread?
e.g.
private void updateLocalUi(long timestamp) {
Date date = new Date(timestamp);
final String displayDate = DateFormat.getMediumDateFormat(this).format(date)
+ "\n"
+ DateFormat.getTimeFormat(this).format(date);
runOnUiThread(new Runnable() {
@Override
public void run() {
mLocalTimeView.setText(displayDate);
}
});
}
I modified it a lot for my own usage and it's no longer the original example. Do I upload it to my own GitHub with the same Apache 2 license or a different one?
In the code, Intent.ACTION_TIME_CHANGED
results in TimeProfile.ADJUST_MANUAL
(0x01) but for Intent.ACTION_TIMEZONE_CHANGED
the adjust reason value is set as 0x04.
According to the current time specs (https://www.bluetooth.com/specifications/adopted-specifications), "If the time information on the server device was set / changed manually, the “Manual Time Update” bit shall be set.
Note: If the time zone or DST offset were changed manually, this bit shall also be set."
In the example scenario, the user is asked to changed the timezone. Shouldn't the ADJUST_TIMEZONE
value be 0x05 instead of 0x04 (and shouldn't the same thing apply to DST)?
// Adjustment Flags
public static final byte ADJUST_NONE = 0x0;
public static final byte ADJUST_MANUAL = 0x1;
public static final byte ADJUST_EXTERNAL = 0x2;
public static final byte ADJUST_TIMEZONE = 0x5;
public static final byte ADJUST_DST = 0x9;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.