mongoose-os-libs/bt-common

Ability to change bluetooth state without reboot

Opened this issue · 0 comments

To allow for better user flexibility, please make it possible for changes in mgos_sys_config.bt to be applied runtime, without the necessity for reboot.

This actually applies to many libraries -- they all have an _init() function which allocates resources, brings up hardware and applies configuration. For many libraries the last step is trivial to implement and make public, so that applications can apply their modified mgos_sys_config to the module. WiFi is a good example, it just needs bool mgos_wifi_set_config(const struct mgos_config_wifi *cfg) made public.

For this particular usecase, we need deregister functionality for gatts, so that bt-service-config can implement its _set_config() method and register/deregister at will. It should be possible for changes to bt.adv_enable and bt.enable to be applied by the application too -- the only way to disable BT now is to use bt.keep_enabled, but it's a sneaky way to do it. Also, it seems the BT service is enabled on boot regardless of whether a good WiFi STA config is present. BT is only disabled after successful association. What happens if your router blows up or otherwise disappears? Your neighbors take over the device :)