BLE scan and advertising issues
I am trying to make a simple BLE scan and advertising program which is supposed to advertise a set of changing data and scan for other devices. The advertising is completely non-connective and works as a dumb beacon, and so is the scanning.
The application is based on the HRS FreeRTOS example for the nucleo wb55, modified to remove the HRS-specific parts and with simple advertising and scanning added. After app_ble is done with all the initializing it goes on to create the advertising data and run aci_gap_set_discoverable with the correct settings (non-connectable, min advertising interval of 70 ms, maximum of 130, public address, no white-list) and add the advertising data using aci_gap_update_adv_data.
Then it runs aci_gap_start_observation_proc(0xA0, 0x60, 0x00, 0x00, 0x00, 0x00);, which should mean scan interval of 100 ms, scan window of 60 ms and no filters.
None of these commands return an error but seem to run just fine.
The scan packets are received through SVCCTL_App_Notification() and added to a FreeRTOS queue, and then handled by a separate thread.
The advertising data is currently not being updated in order to simplify the issue, but will be updated through filling a buffer with the new data and sending a flag to AdvUpdateProcess to send the new data to the BLE stack when possible.
Tested with only two devices running, either one or both seem to be unable to advertise. Sometimes one can find the other, sometimes neither can find the other one. The one that's advertising sometimes seems to be able to scan, as the function is called, but will not find the other device (i.e. the other device is not advertising) while the other device does find the first one.
Is there something I'm missing here? Does the stack not support both scanning and advertising at the "same time"? Do I have to make sure that the timing is configured in a specific manner?
Is there maybe a command to request the BLE stack status in order to debug?
When I had the advertising data update running there seemed to be some collision in the HCI layer due to the scan reports and advertising update happening simultaneously, but that seemingly disappeared when I stopped managing the data in the ISR directly.
Edit:
So I solved the issue somehow, I can't exactly recall what fixed it but I believe that reducing the amount of time spent in the event handler did something.
Now I have a tangentially related issue, and figured that editing it into this question may make sense.
There seems to be a timing issue where the devices can get out of sync and completely miss each other. Setting them to constantly scan (I have tried both long and short scan intervals) and periodically advertise, say with a minimum interval of 40 ms and maximum interval of 90 ms, does not seem to allow for enough time to return to scan after advertising.
Using an external device running a BLE packet sniffer I was able to see that a device (let's call it device A) advertised at a specific time but was not able to see the advertisement that another device (let's say B) transmitted 30 ms later.
This tells me that the BLE stack schedules the advertising and monitoring in a way that allows for dead time, where the device is neither advertising or monitoring. Is there any documentation or information concerning how the BLE controller handles this? If not, is there some other way to do what I want to do? I wanted to keep the devices dumb, so that they don't have to connect and communicate directly, but as it seems right now that may not be possible.