Commit Graph

132 Commits

Author SHA1 Message Date
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
Ayke van Laethem
d715f7d4df
Support BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST
This is generated by BlueZ (or Chromium?) and by some Android devices
(but not on my Android device for some reason). We currently default to
the lowest possible MTU for ease of implementing, but could perhaps
support a larger MTU in the future.
2020-05-25 16:56:36 +02:00
Ayke van Laethem
44147f2a86
Add Go module support
This also updates the muka/go-bluetooth package (which required a few
changes).
2020-05-25 00:10:28 +02:00
Ayke van Laethem
f87fda3204
Add smoke tests that run in CI 2020-05-24 19:19:37 +02:00
Ayke van Laethem
6f9f11dbac
Fix timeout when reading Generic Attribute 2020-05-23 20:25:03 +02:00
Nikolas Sepos
e75f949904
Port current codebase to S140 softdevice 2020-03-06 14:24:50 +01:00
Ayke van Laethem
f86fd36240
softdevice: make code more flexible for other SoftDevices
This is required for adding S140 support. It relies on the following
TinyGo PR:
https://github.com/tinygo-org/tinygo/pull/942
2020-03-06 13:46:42 +01:00
Ayke van Laethem
00e2592aff linux: add support for services
Unfortunately, I couldn't get characteristics to work.
2019-11-16 19:11:59 +00:00
Ayke van Laethem
23c2fa38e4
softdevice: fix some comments 2019-11-16 19:01:22 +01:00
Ayke van Laethem
6ded078c91
softdevice: fix event handler 2019-11-16 19:00:18 +01:00
Ayke van Laethem
ca2f0920f9
Make heartrate example more interesting
Display heartrate ticks on the console (that can be adjusted) to make
this example more interesting.
2019-11-16 15:09:49 +01:00
Ayke van Laethem
e453c4d3f9
Add Linux support
Very much experimental, no BLE service support yet and BLE LocalName in
advertisement packet doesn't seem to work. So rather useless at the
moment.
2019-11-09 17:55:19 +01:00
Ayke van Laethem
6e4cf6f8e0
gatts: implement write event for characteristics 2019-11-09 13:55:34 +01:00
Ayke van Laethem
1d44126ac9
gap: implement basic event handling: connect/disconnect 2019-11-09 13:50:00 +01:00
Ayke van Laethem
62131e4c55
Allow setting permission flags on characteristics 2019-11-09 13:02:58 +01:00
Ayke van Laethem
6553fe682d
Split characteristic in config and handle
This allows setting up a characteristic with many properties but avoids
needing to keep the memory of that around (in Go) when the
characteristic is needed at a later time. Instead, only a handle
(currently 16 bits) is kept around to reference to the characteristic.
2019-11-09 12:26:06 +01:00
Ayke van Laethem
0cabe28570
Initial commit 2019-11-08 10:58:02 +01:00