app_easy_gap_advertise_stop

5 posts / 0 new
Last post
ohmi
Offline
Last seen: 1 day 17 hours 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 is a global variable

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

Thanks

 

 

Device: 
PM_Dialog
Online
Last seen: 1 min 31 sec 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.

https://www.dialog-semiconductor.com/products/connectivity/bluetooth-low-energy/smartbond-da14585-and-da14586

Thanks, PM_Dialog

ohmi
Offline
Last seen: 1 day 17 hours 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
Online
Last seen: 1 min 31 sec 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.

Thanks, PM_Dialog

ohmi
Offline
Last seen: 1 day 17 hours 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).
I managed to have the expected behavior send advertisement during a short period of time, than have the device sleeping for a while before restarting the advertisement.

Thanks for your guidance.