-
Notifications
You must be signed in to change notification settings - Fork 71
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
BLE advertising simplification #1122
Conversation
@kareltucek I've just tested this PR, and it removes the extra bottom entry that was exposed by the left half: Can I merge this PR, or is there anything else that I should test? |
Please wait till Benedek says that everything is ready. You should test the case of switching to a device via "switchHost name" when the host is not connected (e.g., dongle is violet) and all peripheral connection slots are taken (e.g., there are already three blue/green dongles) - feel free to reduce the peripheral connection count for testing, and independently for production too (it has its cons as well as pros). |
12452bf
to
e7eabdd
Compare
When testing this branch, the UHK 80 BLE device no longer appears on my phone in the available devices list. |
e7eabdd
to
5800ef3
Compare
Now, I can pair my UHK 80 to my Android phone, and the connection is established. However, the USB host connection remains, and instead of automatically switching, I have to explicitly switch to the BLE host connection. @kareltucek Assuming it's due to the firmware logic, can you look into this? |
@mondalaci I can't reproduce this. Does this happen wih a "new bluetooth device", or a host-connections-list-present device? In the latter case, is your switchover checked? |
I could reproduce the issue again, then switched to master, and the issue was still there, so this branch is probably not the culprit. This happens (or I'd rather say not happens, that is, the automatic switchover) directly after pairing a "new bluetooth device"). I didn't save the host connections. Does this log help?
|
Well, the log looks like UHK knows your "My Phone" already. In that case it behaves according to the switchover checkbox. |
You're right, my oversight! This PR looks good to me, and I'd merge it. Any objections? |
Yes. |
return connectedHids; | ||
} | ||
|
||
uint8_t BtAdvertise_Type() { |
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.
This doesn't look like something that should have been removed.
- You are always trying to advertise, leading to errors when the peripheral connection count is reached. My code in turn tries to remedy the situation by increasingle aggressive strategies, including disconnecting current connections. The code was written so that uhk works even with
CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT=1
. With this settings and this code uhk will not work at all over bluetooth (dongle or hid). - Switchover scenario might need to be taken care of when the limit is reached.
How exactly does the current "simplified" advertising work on right half with respect to dongles? It broadcasts itself as a HID device, and dongles see this and try to connect despite there not being any advertisement for NUS?
I assume I should restore the necessary functionality? Will look into it tomorrow...
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.
- Only the content of the advertising is changed, the call sites of these methods control when advertising is started or stopped, I didn't change the logic there.
- Although I didn't test the changes with a dongle, I did check the scanning logic, and there I saw no filtering based on service UUIDs, only an address based filtering, that's why I was brave enough to remove it. My original idea of directed advertising when intending to connect to a dongle didn't work - according to mondalaci's feedback - so you are very welcome to take a look at this yourself, or to revert the changes for the right half and continue using HID / NUS advertising content.
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.
- Only the content of the advertising is changed, the call sites of these methods control when advertising is started or stopped, I didn't change the logic there.
The trouble is the BtAdvertise_Type() also decides whether or not to advertise at all. Anyways no worries, I will fix that shortly.
- I did check the scanning logic, and there I saw no filtering based on service UUIDs, only an address based filtering, that's why I was brave enough to remove it.
I see. I like the change, but this really needs to be mentioned in a comment somewhere ;-). (Will add that.)
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.
Actually, the compatibility is single directional.
When one ble HID is already connected we want to advertise NUS only - as we can't handle multiple ble HIDs at the same time. Unless you or @mondalaci have a better idea how to handle the situation that is.
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.
@kareltucek If it's possible to reuse the single available BLE HID connection upon connecting a new BLE HID device, ongoing BLE HID advertising would be preferred.
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.
Argh, sorry, wanted to "add a single comment".
device/src/bt_advertise.c
Outdated
err = bt_le_adv_start(&adv_param, adHid, ARRAY_SIZE(adHid), sdHid, ARRAY_SIZE(sdHid)); | ||
|
||
} else if (DEVICE_IS_UHK80_LEFT) { | ||
adv_param = *BT_LE_ADV_CONN_DIR_LOW_DUTY(&HostConnection(ConnectionId_NusClientRight)->bleAddress); |
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.
Btw., here should be &Peers[PeerIdRight].addr
- this couldn't have worked (@mondalaci i.e., I believe the left half does never work over nus with this branch).
What's worse is that the code doesn't work when given correct addresses (they start to scan and advertise, but never actually connect). I take the above as an evidence that it wasn't ever tested.
-> I will restore it to the original NUS advertisement, but leave the subsystem in place with a comment. Feel free to try to fix it @benedekkupper .
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.
Sorry for all the mess I made. I guess the missing line is advParam.options |= BT_LE_ADV_OPT_DIR_ADDR_RPA;
before calling the bt_le_adv_start
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.
Unfortunately still doesn't work. Left advertises, right scans, but they never connect.
Also tried this, based on comments in the code:
advParam = *BT_LE_ADV_CONN_ONE_TIME;
advParam.peer = advConfig.addr;
This results in error 60 (timeout).
(Pushing a minor refactor to make the code a bit more bearable.)
Nevermind, I have added new right.conf
@mondalaci when testing this branch, please note that macro |
#define ADVERTISEMENT(TYPE) ((adv_config_t) { .advType = TYPE }) | ||
#define ADVERTISEMENT_DIRECT_NUS(ADDR) ((adv_config_t) { .advType = ADVERTISE_DIRECTED_NUS, .addr = ADDR }) | ||
|
||
adv_config_t BtAdvertise_Config() { |
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.
(An additional reason to leave this in place is that it documents the scenarios that can happen, and makes logs more explicit - nevermind what advertisement params the backend actually ends up using.)
(The issue is that once we switch to nus only advertisement, the host still renames the hid connection based on it.)
You could put this to ble_hid.conf, since only the right side is a BLE HID device. |
left uses directed advertising, right advertises HID only