Bluetooth device settings don't take effect when expected
Describe the bug
I am building a bluetooth project that needs to be 'open security' (no pairing required)
There's a very strange inconsistency with when this setting actually gets applied. For example, if I build after changing the setting, initially the micro:bit behaviour doesn't change. After I do some set of things I can't identify the significance of, I get the new pairing settings
For example, in one case I had an extension that used bluetooth:
In this configuration, the 'open' pairing was not taking effect
By adding the 'accelerometer service' (which had already been initialised in 'setup as input micro:bit', so this was a duplicate) and then downloading the code to my micro:bit the behaviour changed
To Reproduce Here's a reproducer that works for me without my custom extension:
- create a new MakeCode project
- Add bluetooth extension (but leave all settings as normal)
- Use https://googlechrome.github.io/samples/web-bluetooth/device-info.html?namePrefix=BBC+micro%3Abit to verify that the device is visible in the Bluetooth dialog pairing mode, but not in 'normal' mode [this is expected]
- You can skip these steps, but they were my way of verifying that the right CODAL config where Bluetooth is enabled, not radio, had been applied
- bond from phone, confirm this works
- flash from phone - no need to enter pairing mode
- IE: bluetooth extensions is working right
- Change project settings in MakeCode to 'no pairing required', save
- Download code to micro:bit
- use https://googlechrome.github.io/samples/web-bluetooth/device-info.html?namePrefix=BBC+micro%3Abit to verify that the device is visible in the Bluetooth dialog pairing mode, but not in 'normal' mode [this is NOT expected]
- micro:bit is NOT visible when not in pairing mode, but the open setting means it should be
- Add any block from the Bluetooth library, redownload
- Still not visible. (this is weird because in my previous case with my extension, this change DID make the micro:bit visible)
- Add data logging extension, redownload:
- Test in the same page, but the micro:bit is now visible even when not in pairing mode.
My expectation is that as soon as I toggle that setting, the next time I flash the micro:bit the setting will be applied I also don't understand what is causing/triggering the rebuild for it to work
CC @martinwork perhaps you've seen this @microbit-carlos has some theories!
@jaustin @microbit-carlos Related: https://github.com/microsoft/pxt-microbit/issues/5416#issuecomment-1942868964
As Martin has mentioned in https://github.com/microsoft/pxt-microbit/issues/5416#issuecomment-1942868964, I've also experienced this when changing extension versions or yotta config flags inside the pxt.json file, changes that should trigger a cloud rebuild often take several attempts to trigger. Sometimes it helps if I add a C++ extension to the project (or remove it), or adding more yotta flags with random names (so that it doesn't affect anything important), and sometimes it helps if I exit the project by going to the Makecode home page and then reopen it.
@abchatra Just to clarify, that while this does affect Bluetooth, it is not an issue with Bluetooth itself. The main issue is that changes to the pxt.json file are not applied until an "additional trigger" (like adding extensions, closing and reopening the project, or sometimes making multiple changes to the pxt.json file) somehow forces MakeCode to recompile with the right settings.