Commit Graph

66 Commits

Author SHA1 Message Date
Ron Evans
2d909712ee
docs: update README with lots of info/organization and also add CONTRIBUTING guidelines
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-03 15:40:52 +02:00
deadprogram
fd89ad24a8 linux: all for DiscoverServices and DiscoverCharacteristics to discover all when no specific list of UUIDs
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-03 15:26:43 +02:00
deadprogram
ac98835ed3 linux: add UUID to DeviceService and DeviceCharacteristic
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-03 15:26:43 +02:00
deadprogram
ad6f45a730 linux: correct use of Addresser when scanning
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-03 15:26:43 +02:00
Ron Evans
ada9076886 examples: add discover example that shows services/characteristics
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-03 15:26:43 +02:00
deadprogram
d570aa58a6 docs: better explanation of peripheral UUID on macOS
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
deadprogram
8bb26c24e6 gap: correct use of Address on Linux platform
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
95cabe86a1 macos: added characteristic notifications
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
a7844e1734 macos: remove unneeded functions to export internal implementaions.
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
ea7ed874af gap: switch to use MACAddress struct when possible for shared implementation
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
dc738f9c47 macos: able to discover services and characteristics for a device
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
5f44bb4a96 macos: completed initial implementation
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
27cc0b725a docs: show that we can now scan on macOS
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
56c0c2ecda windows: use Addresser interface for the MAC address for a peripheral
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
c1114ad708 all: use Addresser interface to handle fact that macOS uses UUID instead of MAC as the BLE address for a peripheral
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
a620bacdb8 macos: able to retrieve some of the info when scanning
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
51b2b4c2b2 macos: starting point for adding macOS support
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ayke van Laethem
40e14a41fc nrf52: add support for S140 version 6
This is used on the Adafruit Circuit Playground Bluefruit bootloader,
for example.
2020-08-30 16:39:16 +02:00
Ayke van Laethem
de824e1884
nrf52: use low-frequency crystal oscillator when available
I couldn't measure a difference in my setup, apparently my multimeter is
not able to handle the high-to-low current transition when entering
sleep mode. But it _should_ reduce current consumption a little bit.
2020-08-01 18:39:34 +02:00
Ayke van Laethem
d2228b9e79
nrf52: use internal RC oscillator
This saves around 0.3mA according to my multimeter.
2020-07-30 15:12:28 +02:00
Ayke van Laethem
54cb2b25bb
linux: add GATT client support 2020-06-28 00:22:19 +02:00
Ayke van Laethem
602e656a6b
linux: improve scanning
By using the D-Bus APIs directly, I managed to avoid a deadlock that I
somehow couldn't work around with the go-bluetooth package.
2020-06-28 00:21:47 +02:00
Ayke van Laethem
15b3e8e3e2
nrf: add GATT client
This is not entirely complete (some errors are not handled properly) but
it's a start.
2020-06-28 00:21:40 +02:00
Ayke van Laethem
8129f7e092
linux: include IsRandom bit in Address type
Unlike what I previously thought, BlueZ does expose it. Unfortunately it
doesn't seem to respect it: the bit is not included in D-Bus paths.

Windows also supports the bit, which I hope to fix in a future commit.
Like BlueZ, it appears to ignore it when connecting to a device.
2020-06-11 15:53:36 +02:00
Ayke van Laethem
6c7d25c022
examples/nusserver: refactor terminal handling
The over-the-air newline format has been changed to LF always, for
simplicity. We might have used CR instead but LF works, and is the
newline format normally used on Unix (in files and stdio, except for raw
terminals).
2020-06-11 15:46:08 +02:00
Ayke van Laethem
ccb9c84db8
all: change advertisement interval type
Use a new Duration type, which is used throughout the BLE stack for
durations. The resolutions are sometimes different (connection
parameters have half the resolution) but overall it should improve the
ease of use of this type.

This commit also provides a default advertisement interval that is
recommended by Apple (which I think is as good as any recommendation).
This might help to speed up discovery by Apple (and Android?) phones.
2020-06-06 20:47:05 +02:00
Ayke van Laethem
e0314251c9
all: support HasServiceUUID on advertisement payloads
I have intentionally chosen to implement HasServiceUUID() and not
ServiceUUIDs() because returning a slice of UUIDs will likely cause a
heap allocation. And perhaps the most common use may be checking whether
a packet has a particular UUID, so no list is necessary. Getting the
full list can of course be implemented in the future, if needed.
2020-06-04 19:23:25 +02:00
Ayke van Laethem
e1e010d8ec
all: update NewAdvertisementInterval to accept time.Duration
This makes the API a bit more natural and (if needed) allows for a
slightly greater precision in specifying the advertisement interval.
2020-06-04 16:55:53 +02:00
Ayke van Laethem
d07cf38d66
all: distinguish between public and random addresses
This is necessary when connecting to a device when using the SoftDevice.
The information is not set on Linux and Windows and is ignored on those
platform when connecting.
2020-06-04 14:12:14 +02:00
Ayke van Laethem
ac6ef1697f
Update README 2020-06-04 13:59:42 +02:00
Ayke van Laethem
b568c93250
all: add support for sending notifications
This is done by enabling the Notify permission and writing to the
characteristics: writes will automatically notify connected centrals.
2020-06-03 19:42:21 +02:00
Ayke van Laethem
f69df9d879
all: fix bug that caused a copied DefaultAdapter
The DefaultAdapter was a regular value, not a pointer-to-struct. This
meant that simply copying bluetooth.DefaultAdapter caused a copy of the
object itself (instead of a copy of the reference, as intended). This
meant that write events did not arrive.
2020-06-03 01:13:46 +02:00
Ayke van Laethem
37eb64b519
linux: implement local characteristics 2020-06-02 23:57:51 +02:00
Ayke van Laethem
21100ebc19
all: add service UUIDs to advertisement packets
Support both 16-bit and 128-bit UUIDs on both Linux and Nordic chips.
2020-06-02 14:00:32 +02:00
Ayke van Laethem
49f8082e4b
all: replace GAP events with auto-restarting advertisements
There used to be GAP events (connect/disconnect). The main purpose for
these events was to allow applications to re-start advertisement when a
connection was lost - on nrf. Unfortunately things work differently on
Linux, which already has this behavior and for which I haven't yet
implemented these events. Therefore I have removed these events and
instead added code to automatically restart advertisement on connection
loss.

Supporting multiple (incoming) connections as a peripheral would be
useful, but is not currently supported.
2020-06-01 23:29:31 +02:00
Ayke van Laethem
c034fbca54
all: change NewAdvertisement to DefaultAdvertisement
Instead of attempting to allocate multiple advertisement instances, only
use one by default. If needed, a NewAdvertisement method could be added
in the future for devices that actually do support multiple
advertisements at a time.

The motivation for this change is fix an inconsistency with the nrf51
(which already had the behavior of DefaultAdvertisement) and the
discovery that nrf52 devices also don't seem to support more than one
advertisement instance, even though their API does allow for multiple
instances. But the primary motivation is that for consistency with
hosted systems, it would be best if the nrf port would automatically
re-enable advertisement when a connection is lost (or made).

While BlueZ does support more than one instance, it is implemented by
simply iterating through the active advertisement instances so could
also be implemented by doing that manually. I haven't checked the
behavior of Windows and MacOS - but as always, the API is not yet stable
and can be changed if needed.
2020-06-01 18:09:44 +02:00
Ayke van Laethem
086c797e0f
all: simplify advertisement configuration
This changes the previous raw advertisement packets to structured
advertisement configuration. That means you can set the local name not
with a raw byte array but with a normal string.

While this departs a bit from the original low-level interface as is
often used on microcontroller BLE stacks, it is certainly easier to use
and better matches higher level APIs that are commonly provided by
general-purpose operating systems. If there is a need for raw BLE
packets (for baremetal systems only), this can easily be added in the
future.
2020-06-01 14:20:34 +02:00
Ayke van Laethem
0474d7b750
all: change DefaultAdapter function to global
All initialization can be done in the Enable call. This makes the API a
bit simpler and a bit more consistent between Nordic chips and other BLE
interfaces.
2020-06-01 13:27:56 +02:00
Ayke van Laethem
d9d425504c
README: add note on API stability 2020-05-31 17:01:04 +02:00
Ayke van Laethem
47097f9d96
Add used API to README 2020-05-31 16:50:59 +02:00
Ayke van Laethem
518debbbfe
Move to github.com/tinygo-org/bluetooth 2020-05-31 16:45:26 +02:00
Ayke van Laethem
f91f73ede2
Add S110 version 8.0.0 SoftDevice for nrf51822
The nrf51822 chip is still widely available, for example in the BBC
micro:bit. Therefore it's a good idea to support it too.

Unfortunately, Nordic decided to change the API in some significant ways
so many parts are not compatible between S110 for nrf51 and the other
nrf52* SoftDevices.
2020-05-31 15:40:57 +02:00
Ayke van Laethem
c26709f8c6 Update README 2020-05-30 23:42:45 +02:00
Ayke van Laethem
22553053ff Add initial Windows support
Only scanning has been implemented so far. The most work was really just
understanding WinRT well enough to get to this point.
2020-05-30 21:51:27 +02:00
Ayke van Laethem
7a11ef8562
Add support for scanning for devices
There are some limitations, but it basically works (on both Linux and
nrf).
2020-05-28 11:57:02 +02:00
Ayke van Laethem
93550127da
nrf: handle other GAP events even without event handler
There was a bug (fixed by this commit) that if there was no event
handler, other GAP events would also be ignored.
2020-05-27 16:50:41 +02:00
Ayke van Laethem
5ed4112930
go fmt 2020-05-27 16:50:21 +02:00
Ayke van Laethem
8162ae22f7
Handle BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST
Yet another event that must be handled. This is needed for newer Android
devices (with Android 10).
2020-05-25 17:52:08 +02:00
Ayke van Laethem
2d541f01eb
Handle BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST
Use the default PPCP parameters, don't set anything specific for this
connection.
2020-05-25 17:33:00 +02:00
Ayke van Laethem
f2f9a517d0
Add flag for debug printing
This should normally be false, but can be set to true for debugging.
2020-05-25 17:26:24 +02:00