-
Notifications
You must be signed in to change notification settings - Fork 142
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
hci: add advertiser support for ManufacturerData and ServiceData #307
Conversation
gap_linux.go
Outdated
@@ -125,6 +125,26 @@ func (a *Advertisement) Stop() error { | |||
return nil | |||
} | |||
|
|||
// SetServiceData sets the service data for the advertisement. | |||
func (a *Advertisement) SetServiceData(sd []ServiceDataElement) error { |
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.
@aykevl do you happen to know how I can do this? 😸
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.
What is your goal?
If you want to change advertisement data then I think you can stop and restart the advertisement with the new service data. Looking at the API I don't see a straightforward way to update any part of the advertisement. But this is straightforward to do from userspace: simply stop and restart the advertisement with the new parameters.
See:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.LEAdvertisement.rst
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.LEAdvertisingManager.rst
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.
If you want to change advertisement data then I think you can stop and restart the advertisement
OK I will probably do that in a separate PR.
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.
@aykevl I took your advice and got rid of SetServiceData()
entirely. PTAL.
gap_linux.go
Outdated
@@ -125,6 +125,26 @@ func (a *Advertisement) Stop() error { | |||
return nil | |||
} | |||
|
|||
// SetServiceData sets the service data for the advertisement. | |||
func (a *Advertisement) SetServiceData(sd []ServiceDataElement) error { |
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.
What is your goal?
If you want to change advertisement data then I think you can stop and restart the advertisement with the new service data. Looking at the API I don't see a straightforward way to update any part of the advertisement. But this is straightforward to do from userspace: simply stop and restart the advertisement with the new parameters.
See:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.LEAdvertisement.rst
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.LEAdvertisingManager.rst
gap_nrf528xx-advertisement.go
Outdated
// TODO: implement | ||
return nil |
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.
Looks like this can be implemented here, but it needs a different API.
https://docs.nordicsemi.com/bundle/s132_v6.0.0_api/page/group_b_l_e_g_a_p_f_u_n_c_t_i_o_n_s.html#ga9969047f4e7485c3f856c841978cc31a
Instead of a SetServiceData
, you'd need to construct an entirely new advertisement payload (bluetooth.AdvertisementOptions
) and set it as a whole.
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.
How about preserve the initial options and then set a new payload when SetServiceData
is changed?
Please see the new example beacon
for how I am trying to use this function.
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.
See my other comment above.
2cc12eb
to
7dbb60e
Compare
7dbb60e
to
95bf26a
Compare
@@ -420,3 +441,51 @@ func (a *Advertisement) Start() error { | |||
func (a *Advertisement) Stop() error { | |||
return a.adapter.hci.leSetAdvertiseEnable(false) | |||
} | |||
|
|||
// SetServiceData sets the service data for the advertisement. |
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.
Here are some points I think it might be helpful to cover in the method documentation here, to make it more clear how SetServiceData
needs to be used and what its effects are:
- It causes a new advertisement to be broadcast, with the updated service data that has been passed in.
- Just updating the data in the
[]ServiceDataElement
that has already been passed in toConfigure
viaAdvertisementOptions.ServiceData
will not change the data being broadcast in the advertisement.SetServiceData
must be called for the new data to go into effect. - What happens if
Configure
orStart
have not yet been called on theAdvertisement
? - What effect does this have if the
Advertisement
has been configured with theInterval
option?
After some consideration, I think that it is better to just call This makes it more straightforward to understand what is happening, and to consequently then make the various platform implementations work as expected. @colececil I think this implementation answers the questions you raised:
That is accommodated by the pattern in this updated PR.
That is no longer a problem since there is only 1 way to set this data.
This is also not a problem now.
This is just a normal advertising option, nothing specific to the I have updated this PR accordingly, including the new example. It works correctly with the |
I just added another commit to this PR that allows the |
8ee03a0
to
cf6f9c8
Compare
OK this PR is rebased and squashed. Works correctly on HCI and Linux. nrf is currently broken (See #310) and Windows does not support |
579edec
to
6871cd0
Compare
@colececil @aykevl or anyone else, any thoughts here? I think this is ready to merge. |
@deadprogram I haven't had the chance to check it out in detail, but the new approach you described does indeed sound more straightforward and less confusing. A couple questions:
Thanks! |
Not setting
That would almost certainly result in some receivers not getting the advertisement data, since you do not know how often they are scanning for updates.. |
Signed-off-by: deadprogram <[email protected]>
…advertising correctly. Needed to update ServiceData after Advertisment is already started. Signed-off-by: deadprogram <[email protected]>
6871cd0
to
0734b61
Compare
Rebased against the latest |
OK I realized from some testing I needed to add another commit. The problem was that multiple calls to |
Signed-off-by: deadprogram <[email protected]>
23cd9dc
to
85dac3b
Compare
Overall this is working great for me on Was also able to confirm using AdvertisementType option appears to working as expected using nRF Connect. At some point it might be nice to add this option for SoftDevice as well. Thank you @deadprogram, this is really good :) |
…figure() followed by adv.Start() followed by adv.Stop() multiple times. This is required in order to update advertising ServiceData. Signed-off-by: deadprogram <[email protected]>
Signed-off-by: deadprogram <[email protected]>
…otherwise different adverting types do not work correctly Signed-off-by: deadprogram <[email protected]>
85dac3b
to
1e01e58
Compare
I've addressed all of the feedback, and squashed commits as much as makes sense. Now going to merge this so further work can proceed. Thanks very much to @colececil @aykevl @bgould for feedback and testing! |
FYI for @colececil @bgould or anyone else interested in BTHome, I just started this little helper package https://github.com/hybridgroup/go-bthome |
That's awesome @deadprogram! Thanks! |
FWIW ... advertisements using SoftDevice are working with this program on |
@bgould that is interesting to know, might help to track down the problem there... |
@deadprogram Good news! I updated my project (https://github.com/colececil/automatic-soil-monitor) to use the revised API here, along with the BTHome helper package you created, and it's still working as expected! And it's working well with Home Assistant: |
That is good to hear, thank you for testing @colececil ! |
This PR adds advertiser support for ManufacturerData and ServiceData to the HCI implementation.
Addresses #306