Query whether device is broadcasting

Learn MoreFAQsTutorials

2 posts / 0 new
Last post
moiify
Offline
Last seen:11 hours 13 min ago
Joined:2020-03-12 07:26
Query whether device is broadcasting

i am using DA14585 chip to run in both master and slave mode, it makes confused that sometimes the chip is not broadcasting (when it is not be connected,in most time),so i should use some API to query whether device is broadcasting periodically. thank you!

Device:
PM_Dialog
Offline
Last seen:2 hours 17 min ago
Staff
Joined:2018-02-08 11:03
Hi moiify

Hi moiify

Since you are using a DA14585, in order to perform role switching, you can set the role in GAP_ROLE_ALL and advertise or scan (you cannot do both at the same time). However, you can advertise and set a timer, upon timer expiration, ou should stop advertising and as soon as it stops you can start scanning and either wait for the scan to complete (if you are scanning in GAP_GEN_DISCOVERY or set an additional timer and cancel the scanning procedure) so as soon as the scanning completes start the advertising again. Please check the steps below in order to perform it in ble_app_peripheral example of the SDK:

- Change in the user_config.h file the .role member of the user_gapm_conf to GAP_ROLE_ALL.

——创建一个user_scan_start()函数为了the device to start scanning:

void user_scan_start(void) { struct gapm_start_scan_cmd* cmd = KE_MSG_ALLOC(GAPM_START_SCAN_CMD, TASK_GAPM, TASK_APP, gapm_start_scan_cmd); cmd->op.code = GAPM_SCAN_ACTIVE; cmd->op.addr_src = GAPM_STATIC_ADDR; cmd->interval = 16384; cmd->window = 16384; cmd->mode = GAP_GEN_DISCOVERY; cmd->filt_policy = SCAN_ALLOW_ADV_ALL; cmd->filter_duplic = SCAN_FILT_DUPLIC_EN; // Send the message ke_msg_send(cmd); // We are now connectable ke_state_set(TASK_APP, APP_CONNECTABLE); }

- In the user_app_adv_start() function there is a timer that starts up in order to stop the advertising after about 30 seconds, so we are going to use that in order to stop the advertising.

- So in the callback of the timer adv_data_update_timer_cb() instead of updating of the advertising string,invoke the app_easy_gap_advertise_stop() function.

- In the user_app_adv_undirect_complete() function invoke the user_scan_start() function, so that when the device stops advertising to start scanning.

- In order to stop scanning i won’t use an additional timer in order to cancel the command, but i will use the timeout of the scanning itself.

- In order to start advertising as soon as the scanning ends create a function user_on_scanning_completed() and from that function invoke the user_app_adv_start();

Please try the steps above and let me know if it is working.