app_easy_gap_advertise_stop

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
5 posts / 0 new
Last post
ohmi
Offline
Last seen:1 year 9 months ago
Joined:2019-03-28 08:21
app_easy_gap_advertise_stop

Hello support team,

I'm trying to understand how the SDK works.

Using example ble_app_barebone.

I'm trying to have the device running in 2 states :

state 0 : advertising
state 1 : doing nothing

to achieve this I've modified the above project in that way :
in function adv_data_update_timer_cb() -- timer callback : I'm switching state based on an internal counter
When counter reaches the expected value, I change state and ask for adv stop:

myStatus是一个全局变量

uint8_t myStatus __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY uint8_t nb __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY static void adv_data_update_timer_cb() { nb++; if (nb==2) { myStatus=1; // evite la relance app_easy_gap_advertise_stop(); } else if (nb>=4) { myStatus=0; nb=0; } // If mnd_data_index has MSB set, manufacturer data is stored in scan response uint8_t *mnf_data_storage = (mnf_data_index & 0x80) ? stored_scan_rsp_data : stored_adv_data; // Update manufacturer data mnf_data_update(); // Update the selected fields of the advertising data (manufacturer data) memcpy(mnf_data_storage + (mnf_data_index & 0x7F), &mnf_data, sizeof(struct mnf_specific_data_ad_structure)); // Update advertising data on the fly app_easy_gap_update_adv_data(stored_adv_data, stored_adv_data_len, stored_scan_rsp_data, stored_scan_rsp_data_len); // Restart timer for the next advertising update app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb); }

than in user_app_adv_start I do not call app_easy_gap_undirected_advertise_start when myStatus == 1

void user_app_adv_start(void) { //arch_printf("user_app_adv_start"); /*SB*/ // Schedule the next advertising data update app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb); /*SB*/ if (myStatus==1) { return; } struct gapm_start_advertise_cmd* cmd; cmd = app_easy_gap_undirected_advertise_get_active(); // Add manufacturer data to initial advertising or scan response data, if there is enough space app_add_ad_struct(cmd, &mnf_data, sizeof(struct mnf_specific_data_ad_structure), 1); app_easy_gap_undirected_advertise_start(); }

The result is not what I expected as it finishes in NMI_HandlerC.

Could you help me understanding what I did wrong

谢谢

Device:
PM_Dialog
Offline
Last seen:11 hours 26 min ago
Staff
Joined:2018-02-08 11:03
Hi ohmi,

Hi ohmi,

When you stop advertising, the user_app_adv_undirect_complete() callback function is triggered. If you check the source code of this function, the user_app_adv_start() will be triggered, so the device will start again advertising. Please run your code in debug mode and you will see that “status” is equal to GAP_ERR_CANCELED (= 0x44). So, when the user_app_adv_start will be triggered again, the myStatus variable is equal to 1 and the “return” will be executed. The result of this is that the code gets stuck, the watchdog times out and you get an NMI. If you remove the if (myStatus==1) { return;}, after stop advertising, the user_app_adv_start() will be excecuted correctly and the device will restart advertising. There is an example in the SDK named ble_app_sleepmode example, in which the device starts advertising, after a predefined amount of time stop advertising, goes into extended sleep mode and when you press a switch button the device wakes up and restarts advertising. If you are newbie with our products and with our SDK I would suggest you to have a look at the following documents which will help you to understand our APIs and the SDK’s architecture.

Please, read the Pillar 5 (Sleep Mode) section of UM-B-080 document. Also, I would strongly recommend you to have a look at our tutorials and our software examples from our support webpage.

//www.xmece.com/亚博电竞菠菜products/connectivity/bluetooth-low-energy/smartbond-da14585-and-da14586

谢谢, PM_Dialog

ohmi
Offline
Last seen:1 year 9 months ago
Joined:2019-03-28 08:21
Yes I'm newbie with both your

Yes I'm newbie with both your products and SDK.
I was trying to understand the SDK via UM-B-080/079, but it is hard to step in.
So thanks for the link to the tuto, I'll go through them.

PM_Dialog
Offline
Last seen:11 hours 26 min ago
Staff
Joined:2018-02-08 11:03
Hi ohmi,

Hi ohmi,

I would recommend you to read the UM-B-080/079, run and debug all the SDK’s example an then read the tutorials. If you have any other question or issue, please create another forum thread. Thank you for accepting my answer.

谢谢, PM_Dialog

ohmi
Offline
Last seen:1 year 9 months ago
Joined:2019-03-28 08:21
Hi Support,

Hi Support,

I went through the examples, but I found tutorial was more helpful (especially the one discussing sleep modes).
我设法have the expected behavior send advertisement during a short period of time, than have the device sleeping for a while before restarting the advertisement.

谢谢for your guidance.