zmk icon indicating copy to clipboard operation
zmk copied to clipboard

feat(ble): Add the ability to enable and disable advertising

Open ReFil opened this issue 1 year ago • 9 comments

Currently advertising cannot be disabled, In some circumstances it may be desirable to disable advertising to the host e.g. seeking consistency between an endpoint switch and percieved board behaviour.

This adds 3 new options to &bt, ADV_ON, ADV_OFF and ADV_TOG as well as the metadata and documentation for the behaviour. ble.c has been updated with a static flag that gets checked in update_advertising() and doesn't permit any adveritising state other than ZMK_ADV_NONE unless it's set. it's defaulted to true so standard board behavior shouldn't change.

The ability to get the current adverising state has also been added, it could have utility in custom display widgets.

Tested on a development board, I've noticed some hosts cache the advertising info so it still shows up as a connectible device if the switch is used whilst the bluetooth devices menu is open, but it still cannot be connected to. Using an app like nRF connect or a different host it can be seen that the device properly stops advertising

ReFil avatar Oct 10 '24 13:10 ReFil

Regarding docs I think there might end up being some confusion when people see "This turns on advertising", use the behavior expecting to be able to connect a new device yet nothing happens because they haven't selected an unused profile.

nmunnich avatar Oct 10 '24 15:10 nmunnich

I see your point, it would still advertise if it's in an occupied profile but wouldn't pair and work properly. Perhaps it would be better worded as "Permits advertising (note that other conditions must be met for the device to be visible)"?

ReFil avatar Oct 10 '24 17:10 ReFil

That still sounds like it's a bit unclear to some. What would you consider to be the difference between what you've defined as BT_ADV_OFF and a hypothetical BT_OFF command?

nmunnich avatar Oct 10 '24 18:10 nmunnich

Functionally there's not really any difference I suppose

ReFil avatar Oct 10 '24 18:10 ReFil

I think renaming and rephrasing it appropriately would be both clearer and make it usable by non-tech people, then. Sometimes a user might want to just turn off BT after all.

nmunnich avatar Oct 10 '24 18:10 nmunnich

Hmm, I'm not sure about describing it as turning off Bluetooth when it doesn't do that. My concern is users may wonder if it affects split connections if it's described as shutting off Bluetooth

ReFil avatar Oct 10 '24 18:10 ReFil

Rebased and ready for review

ReFil avatar Aug 02 '25 19:08 ReFil

An improvement over this that I would personally love to see would be to persist the setting across reboots, similar to how bt profiles or output switching works.

dapetcu21 avatar Aug 14 '25 13:08 dapetcu21

Cherry-picked on top of #3060, testing on Electronic Materials Office Ltd. Altar I's output selection SP3T switch. Can confirm that ADV_ON and ADV_OFF work exactly as expected. Thanks for working on this!

kurtis-lew avatar Oct 30 '25 13:10 kurtis-lew