-
-
Notifications
You must be signed in to change notification settings - Fork 752
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
coded phy works (better) with S140 6.1.x #2465
Comments
BTW, it is probably about extended advertising since even with passive scan the data array returned is 34 bytes so over normal advertising limit of 31 bytes
so I guess that is why the https://github.com/espruino/BangleApps/tree/master/apps/shownearby works fine with 6.0.0. and the thermometer is not visible. |
Ahh, that's interesting - thanks! I wonder if there isn't something else that could be done to help us receive bigger advertising on the 6.0.0 softdevice, if that's the underlying issue? Sorry but just to check, you say you swapped the softdevice hex and made no other changes to the compile and it was all ok? Definitely moving to the new SD would be good if it does improve the situation - but I'm a bit anxious about doing OTA updates for Bangle.js given how much grief I get from users every time there's even a minor app update :( |
yes except that I am building with 2048 instead of 4096 as mentioned here #2000 (comment) so that internal flash writing is stable on both. Then you can upgrade/downgrade softdevices and it works on both. So we actually don't need to force people to upgrade. But if we put 6.1.1 to the repo and build with that then 6.0.0 won't be tested much.
Not sure if nrf52 to nrf52 (i.e. Bangle2 to Bangle2) could do better with 6.0.0 or it s not there at all, that is another thing that is mentioned in 6.1.0 release notes ( And btw did scanning with phy set to "both" or "2mbps" worked for you at some point? like However with 6.1.x I tried to redefine "both" to use } else if (jsvIsStringEqual(advPhy,"both")) {
m_scan_param.scan_phys = BLE_GAP_PHY_1MBPS|BLE_GAP_PHY_CODED;
if (m_scan_param.interval<m_scan_param.window*2) m_scan_param.interval=m_scan_param.window*2;
m_scan_param.extended = 1;
} with interval being twice the window as suggested in migration guide pdf and this works very nice, I get one list with both normal and coded phy advertisements when scanning. |
Thanks - I've just moved to 2048b writes - probably a good idea anyway. Does that affect DFU do you know? If that was writing 4096b then we might be in a situation where you wrote the new softdevice but the device was then unable to update itself? I guess mostly DFU works in 2k blocks so maybe there is no point where it writes more.
That's a tricky one, because when you
I'm not honestly sure - I found it quite hard to test when I was doing it, so maybe it never worked. |
So I was testing this and changed the code here https://github.com/espruino/Espruino/blob/master/targets/nrf5x/bluetooth.c#L2990 so all three bits could be set independently #if NRF_SD_BLE_API_VERSION>5
if (jsvObjectGetBoolChild(options, "extended"))
m_scan_param.extended = 1;
JsVar *advPhy = jsvObjectGetChildIfExists(options, "phy");
if (jsvIsUndefined(advPhy)) {
// default
} else {
char phys[18]; // up to "1mbps,2mbps,coded"
size_t len=jsvGetString(advPhy,phys,18);
phys[len]=0;
int phycount=0;
if (strstr(phys,"2mbps")!=NULL) {
m_scan_param.scan_phys |= BLE_GAP_PHY_2MBPS;
m_scan_param.extended = 1;
phycount++;
}
if (strstr(phys,"1mbps")!=NULL) {
m_scan_param.scan_phys |= BLE_GAP_PHY_1MBPS;
phycount++;
}
if (strstr(phys,"coded")!=NULL) {
m_scan_param.scan_phys |= BLE_GAP_PHY_CODED;
m_scan_param.extended = 1;
phycount++;
}
if (strstr(phys,"both")!=NULL) {
m_scan_param.scan_phys = BLE_GAP_PHY_1MBPS|BLE_GAP_PHY_CODED;
m_scan_param.extended = 1;
phycount=2;
}
if (phycount==0)
jsWarn("Unknown phy %q\n", advPhy);
else
if (m_scan_param.interval<m_scan_param.window*phycount) m_scan_param.interval=m_scan_param.window*phycount;
}
jsvUnLock(advPhy);
#endif and the result is that very few combinations work , only
According to this https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v6.1.1/structble__gap__scan__params__t.html?cp=5_7_4_4_2_1_4_10_6#a369859ca03e34c8220452ae95d1aa02f (while the explanation is a bit confusing) I understand it like this
Maybe some of those combinations may make sense only when connecting, not scanning (as per documentation) I am still not sure about extending the window when scanning more phys. Why for coded the interval should be window*2 as per migration guide and why not for 1+2mbps. I don't know why it would not simply switch PHY in next rounds since e.g. window 100,interval 100, timeout 2000 should cycle through three advertising channels every 100 units so why not change phy then and do it again (in same way for 1mbps+coded and 1+2mbps. Anyway, thank for changing the block size. As for the scanning stuff mentioned above I think it would make sense to redefine Or if "both" is not descriptive enough the code above can work too with 2mbps option removed, but that would break current documentation. I also looked into setAdvertising with coded phy (including enabling
I never had any issue with DFU update on 6.1.x so maybe as you say it does not use such big block. |
And BTW the double interval size when scanning for both phys on 6.1.x is needed, I have added overriding window/interval like jsvUnLock(advPhy);
#endif
uint32_t scan_window=jsvObjectGetIntegerChild(options, "window");
if (scan_window>=4 && scan_window<=16384) m_scan_param.window=scan_window;
uint32_t scan_interval=jsvObjectGetIntegerChild(options, "interval");
if (scan_interval>=4&& scan_interval<=16384) m_scan_param.interval=scan_interval;
if (m_scan_param.interval<m_scan_param.window) m_scan_param.interval=m_scan_param.window;
} And when setting scanning to both 1mbps and coded and set interval to less than 2* window (like |
You did mention under "...very few combinations work , only..." that all 3 work, and I believe that's what BLE_GAP_PHYS_SUPPORTED does which is what we use for But maybe that should be Good idea about specify window and interval, I'll add that - I think it needs a MSEC_TO_UNITS around it? |
yes, was just quick hack to have something there as any number is good no matter the unit. also was thinking why we have everything BLE related in milliseconds when the (((TIME) * 1000) / (625)) conversion makes it inexact and there is extra multiplication and division bloating the code but yes people are probably used to miliseconds :-)
Yes but that actually always gives me error. As it is now I get error for |
Yes, and it makes more sense if we support other platforms - the inaccuracy is a bit annoying though I know. Just tested and it doesn't work for me either, so just pushing a change now |
Just to follow up with coded phy vs connectable (and scannable). By default connectable+coded phy does not work with current build. Found out it is because of NRF_SDH_BLE_GAP_EVENT_LENGTH being 3 in Another issue is about connectable+scannable - that I found out is invalid combination for coded phy (or extended advertising) in BLE. So now I remember and know why there is no And BTW, there is nice info about it here https://devzone.nordicsemi.com/f/nordic-q-a/47073/general-questions-about-notifications-low-level-ble-packets-and-softdevice-phy-connection-interval-connection-event-length-att-mtu-and-dle What I get from all of this is that if we want to switch device to be connectable over coded phy (worthwhile even for Bangle 2 IMO, I hate when I leave my phone on a desk, go to kitchen and it gets disconnected from gadgetbridge) the best is probably also lowering MTU and restarting SoftDevice to have smaller memory requirements (i,e same as now) because maybe larger MTU over coded phy is not that great idea anyway. So something like we already have for other cases when softdevice restart is needed. And when switching back to normal mode we may have to restart again and increase MTU (and possibly also decrease NRF_SDH_BLE_GAP_EVENT_LENGTH - which should be also tunable at runtime) And as the scannable mode is not supported with coded phy+connectable we would probably also need to support extended advertising with larger size to fit everything in without scan response packet. That can be 'hacked' to keep same size by actually joining the m_adv_data and m_scan_rsp_data to be one single bigger buffer instead of static uint8_t m_adv_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
static uint8_t m_scan_rsp_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; // 31 and reuse that area more dynamically so even with 1mbps with extended advertising one could make device non scannable and have larger advertising packet instead of scan response. So far I only tested connectable+coded phy with larger memory requirements, all other stuff is just ideas for now. I know I probably won't have time for this for next 14 days so just updating this with the info I know. |
I am using xaomi thermometer with custom firmware https://github.com/pvvx/ATC_MiThermometer that is able to advertise over coded phy. I can find it in nrfconnect on my phone but I could never find it with Espruino on 52840 (with S140 6.0.0).
Now I tried with 6.1.1 (and 6.1.0) and just by updating softdevice it works with same espruino binary - suddenly the thermometer can be found!
with 6.0.0
with 6.1.1
I checked S140 6.1.0 release notes and it actually starts with
the "new features" section also mentions
a single call to sd_ble_gap_scan_start() or sd_ble_gap_connect() (DRGN-8668).
by the SoftDevice (DRGN-9802)
There is quite a lot of bugfixes and there is also migration document with code describing how to scan on both PHYs at once (basically double the interval) I am attaching both here
s140_nrf52_6.1.0_migration-document.pdf
s140_nrf52_6.1.0_release-notes.pdf
I also noticed one mentioned change which may be related to the 4096 block writing bug to internal flash, looks like maybe they reduced it too much :-)
So basically I am suggesting to eventually move to 6.1.0 or 6.1.1 to support coded phy/advertising extensions better. The only issue I see that need fixing with 6.1.x is reducing flash write block size from 4096 to 2048 as per that comment.
The text was updated successfully, but these errors were encountered: