examples: add example that makes connections to multiple peripherals#318
Open
deadprogram wants to merge 1 commit intodevfrom
Open
examples: add example that makes connections to multiple peripherals#318deadprogram wants to merge 1 commit intodevfrom
deadprogram wants to merge 1 commit intodevfrom
Conversation
Signed-off-by: deadprogram <ron@hybridgroup.com>
Contributor
|
What is the main purpose of the example? Show it is possible to connect to several peripherals and subscribe to notifications from them? If so, I find all this dance with specifying device addresses unnecessary -- it just bloats the example code. Can we instead just subscribe to any HR bluetooth device we can find? Simplifies code and makes it easier to try out. |
Contributor
|
I've tried to see if it works with SoftDevice (xiao-ble) and it does not seem to do. It is stuck here ☝️ Two heart rate boards are Nano-RP2040, flashed like this: |
ysoldak
reviewed
Jan 8, 2025
| // ContextWithSignal creates a context canceled when SIGINT or SIGTERM are notified | ||
| func contextWithSignal(ctx context.Context) context.Context { | ||
| newCtx, cancel := context.WithCancel(ctx) | ||
| signals := make(chan os.Signal) |
Contributor
There was a problem hiding this comment.
Suggested change
| signals := make(chan os.Signal) | |
| signals := make(chan os.Signal, 1) |
My editor warned me the channel shall be buffered here.
ysoldak
reviewed
Jan 8, 2025
| select { | ||
| case <-signals: | ||
| cancel() | ||
| } |
Contributor
There was a problem hiding this comment.
This whole block can be simplified:
go func() {
<-signals
cancel()
}()
ysoldak
reviewed
Jan 8, 2025
| // Replace this by using -ldflags="-X main.Devices='[MAC ADDRESS],[MAC ADDRESS]'" | ||
| // where [MAC ADDRESS] is the actual MAC address of the peripheral. | ||
| // For example: | ||
| // tinygo flash -target nano-rp2040 -ldflags="-X main.Devices='7B:36:98:8C:41:1C,7B:36:98:8C:41:1D" ./examples/heartrate-monitor/ |
Contributor
There was a problem hiding this comment.
Suggested change
| // tinygo flash -target nano-rp2040 -ldflags="-X main.Devices='7B:36:98:8C:41:1C,7B:36:98:8C:41:1D" ./examples/heartrate-monitor/ | |
| // tinygo flash -target nano-rp2040 -ldflags="-X main.Devices='7B:36:98:8C:41:1C,7B:36:98:8C:41:1D" ./examples/multiples/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new example that makes connections to multiple peripherals.
It has been tested and is known to be working on Linux and on HCI with NINAFW, as long as #317 has been merged first.
On Linux I tested with 6 simultaneous connections. It might allow more.
On HCI I tested with 3 simultaneous connects. Again, more might also work.