Advertising and Scanning

7 posts / 0 new
Last post
ArminL
Offline
Last seen:4 years 3 weeks ago
Joined:2016-09-30 07:23
Advertising and Scanning

Hi Dialog,

my custom application should advertise and initiate a connection simultaneously, but only Advertising works.
Code snippet:
ble_gap_role_set(GAP_PERIPHERAL_ROLE | GAP_CENTRAL_ROLE);
...
ble_gap_adv_start(GAP_CONN_MODE_UNDIRECTED);
ble_gap_connect(&bd_addr, &cp);

What could be the problem?

Thanks
Armin

Device:
MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
Joined:2015-06-08 11:34
Hi ArminL,

Hi ArminL,

I am afraid that something like this is not possible, concurrent central/peripheral is valid only while connected (check the multilink demo), you wont be able to advertise and scan/connect at the same time.

Thanks MT_dialog

ArminL
Offline
Last seen:4 years 3 weeks ago
Joined:2016-09-30 07:23
Hi MT_dialog,

Hi MT_dialog,

ok, this is a problem, because the application should always be able to connect either to a central or peripheral.
So I have to invoke the advertise and scan procedures alternately, maybe with a timer.
Can you give me a clue, how this problem could be solved?

Thanks
Armin

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
Joined:2015-06-08 11:34
Hi ArminL,

Hi ArminL,

Yes, you should be able to do that, you can alter Scanning and Advertising on steady intervals via a Free RTOS timers, just set up your timer and in the callback or the timer stop advertising. After the advertising has completed (you get the advertising completion callback you can either start to scan or initiate a connection). Have in mind that the Scanning is procedure that is terminated automatically, so you dont have the timer for measuring the scanning procedure if you like, the scanning will automatically timeout in 8 seconds.

The procedure goes like this:

  • Set up a timer and a timer callback in your main application and start counting.
  • In the timer's callback you can notify the main application that the timer has elapsed and stop the advertising procedure from the main application, something like the below snippet: if (notif & SCAN_ADV_TIME_NOTIF) {ble_gap_adv_stop();}
  • The ble_gap_adv_stop() will trigger handle_evt_gap_adv_completed() in the BLE_EVT_GAP_ADV_COMPLETED case in the main task, so in that handler you can start the scanning or connection procedure.
  • As i ve mentioned you can either timeout the scan procedure either via timer or regarding the scan you can wait for the procedure to timeout.
  • At the corresponding completion handler you can start advertising again and start the timer for time out the advertising procedure.

Thanks MT_dialog

ArminL
Offline
Last seen:4 years 3 weeks ago
Joined:2016-09-30 07:23
Hi MT_dialog,

Hi MT_dialog,

I've implemented this procedure similar to your explanation.

In the case application is connected to a central (connection interval 30ms) and connection procedure is still active (with scan window 30ms), application sometimes seems to crash. The connection to the Central is discontinued and connection procedure stops.
What could be the problem?
Is it a problem if a connection event occurs during scan window?

Thanks
Armin

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
Joined:2015-06-08 11:34
Hi ArminL,

Hi ArminL,

So, you have the device in dual mode GAP_PERIPHERAL_ROLE | GAP_CENTRAL_ROLE and switching between scanning and advertising, and when you start a connection from your phone for example you see that sometimes the devices crashes ?

The device in order to be connected it requires two advertising messages, so if your phone receives the last adv message before the 68x starts the scanning its not going to crash, the phone will receive the advertising message and will start a connection procedure. The connection procure will go on until the 68x switches back to the advertising mode and then the connection will be complete. Then if you continue to scan or advertise and you are still connected the 68x device will try to schedule all the events. In order to debug what you are seeing you will have to attach the debugger and check where the device stalls. At least on my side, replicating your setup (correct me if i am wrong about the setup) i didn't see any issues with the default connection of an android phone around 48ms (the central defines the connection interval of a connection unless a connection parameter update is issued and again the central will decide if it will accept the parameters).

Thanks MT_dialog

ArminL
Offline
Last seen:4 years 3 weeks ago
Joined:2016-09-30 07:23
Hi MT_dialog,

Hi MT_dialog,

it's an iOS phone. While my application is connected to a phone (connection event every ~30ms), my application continues the scanning procedure to connect to a peripheral (scan window 30ms). In this situation, my application crashes sometimes.
我将检查我的应用的调试器tion stalls.

Thanks
Armin