-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
examples: add example that makes connections to multiple peripherals #318
base: dev
Are you sure you want to change the base?
Conversation
Signed-off-by: deadprogram <[email protected]>
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. |
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:
|
// 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signals := make(chan os.Signal) | |
signals := make(chan os.Signal, 1) |
My editor warned me the channel shall be buffered here.
select { | ||
case <-signals: | ||
cancel() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole block can be simplified:
go func() {
<-signals
cancel()
}()
// 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/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 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.