programatically change advertising rate

21 posts / 0 new
Last post
motred
Offline
Last seen:5 years 6 months ago
Expert
加入:2014-01-20 21:48
programatically change advertising rate

I would like to change the advertising interval based on data from a sensor connected to the DA14580. I plan to do this by changing lines 209 and 210 in app.c to a global variable that can be updated by another function.

So I would have something like this in app.c:
void app_adv_start(void)
{
...
cmd->intv_min = current_app_adv_int_min; // was APP_ADV_INT_MIN
cmd->intv_max = current_app_adv_int_max; // was APP_ADV_INT_MAX
....
}

Will this work? Is this the best way of accomplishing this?

Thanks for any help you can give.

gl_dialog (not verified)
Dear Motred,

Dear Motred,

You're right when saying that both lines 209 & 210 in app.c must be changed in case you need to change the advertising interval.
所以你menti的函数oned is fine.
Note that current_app_adv_int_min & current_app_adv_int_max must be the same.

best regards,

Guillaume.

oren
Offline
Last seen:1 year 7 months ago
Expert
加入:2014-06-28 22:03
Hi Guillaume,

Hi Guillaume,
Do you know what happens if you set intv_min and intv_max to be different from each other?
From my tests, when intv_min < intv_max the advertising interval is intv_max.

Do you know if there are any side effects to do that? If intv_min is ignored, what is it good for?
(I am just interested out of curiosity).

Thanks,
Oren

hrg
Offline
Last seen:2 years 4 months ago
Guru
加入:2014-08-05 13:37
#define APP_ADV_INT_MIN

#define APP_ADV_INT_MIN 1100
#define APP_ADV_INT_MAX 1100
1100 means ?? unit??

JE_Dialog
Offline
Last seen:3 weeks 1 day ago
Staff
加入:2013-12-05 14:02
Hi hrg, I believe the units

Hi hrg, I believe the units are 1/100ths of seconds.

BR

JE_Dialog

MHv_Dialog
Offline
Last seen:1 month 3 weeks ago
Staff
加入:2013-12-06 15:10
Hi,

Hi,

You should multiply the number 1100 with 0.625 to get the number of miliseconds between events. So 1100 => 688ms.

hrg
Offline
Last seen:2 years 4 months ago
Guru
加入:2014-08-05 13:37
Hi JE_Dialog

Hi JE_Dialog

are yu sure ? because it is advertising interval so 1100*(1/100) = 11 seconds !! ?? or is it 1100 * 0.625 =687.s msec ? because while checking in power profiling the time between two advertising event is approx 680 msec !!

MHv_Dialog
Offline
Last seen:1 month 3 weeks ago
Staff
加入:2013-12-06 15:10
Hi Hrg,

Hi Hrg,

See my answer above.

Other than the setting, the stack will have to add a random number to the advertising to avoid that two separate devices collide in the air continuosly. So the advertising will fluctuate some +/-10ms

JE_Dialog
Offline
Last seen:3 weeks 1 day ago
Staff
加入:2013-12-05 14:02
Hello hrg, yes, you are right

Hello hrg, yes, you are right : i was looking at our Beacon SW by mistake where we have a different calculation.

Line 81 and 83 in main.c apply a multiper of 0.625 so the 680mS is the correct value.

#define APP_ADV_INT_MIN 0x20 // *0.625ms (+ pseudo random advDelay from 0 to 10ms)

BR JE_Dialog

MHv_Dialog
Offline
Last seen:1 month 3 weeks ago
Staff
加入:2013-12-06 15:10
Hi,

Hi,

Just adding to this. You will have to stop, then restart advertising to actually change the intervals.

alex
Offline
Last seen:2 years 5 months ago
加入:2014-08-20 03:39
Hi JE,

Hi JE,

In #8, you mentioned the (BLE) stack will add random number(0~10ms) above APP_ADV_INT_MAX, while in our tests, we did not see this random adding to the interval:
- when we power up 3 DA modules(with same firmware) simutaneously, we could hardly scan all 3 modules(sometimes we can only scan 1, sometimes 2).
- while if we power up 3 DA modules one by one, we can scan all 3 modules everytime.
- if we burn firmware with different APP_ADV_INT_MAX value to each module, and power up the 3 modules simutaneously, we also can scan all 3 modules everytime.

Pls help to check and advise..

Thanks.
Alex

MT_dialog
Offline
Last seen:1 month 4 weeks ago
Staff
加入:2015-06-08 11:34
Hi alex,

Hi alex,

According to the bluetooth spec the advertising events occurs at regular intervals which are slightly modified with a random delay to aid in interference avoidance. Even without this mechanism, over time the different advertising intervals should drift and stop overlapping eachother (no matter how simutaneously your advertising starts for how long the other devices aren't discoverable by your scanner). Do you use different bd-addresses ? What is your software version ?

Thanks MT_dialog

alex
Offline
Last seen:2 years 5 months ago
加入:2014-08-20 03:39
Thank you MT..

Thank you MT..

Do you use different bd-addresses ?
- Yes, we are having different BDA for each module.
What is your software version ?
- The firmware developed based on SDK304.

Alex.

MT_dialog
Offline
Last seen:1 month 4 weeks ago
Staff
加入:2015-06-08 11:34
Hi alex,

Hi alex,

Can you please try to define the CFG_TRNG configuration, and check again if the advertising events overlaps ?

Thanks MT_dialog.

ciano
Offline
Last seen:4 days 5 hours ago
加入:2014-10-03 08:13
Hi Dialog

Hi Dialog
We have the same issue as #11, and we are using SDK 5.0.2.1

Info:
We are using "app_easy_gap_non_connectable_advertise_start_create_msg" which sets up cmd->intv_max and cmd->intv_min identically
cmd->intv_max = user_non_connectable_advertise_conf.intv;
cmd->intv_min = user_non_connectable_advertise_conf.intv;

True Random number Generator is enabled in "da1458x_config_advanced.h"
#define CFG_TRNG

Hope you have a solution, since this is a real issue for the application.

Best Regards,
Ciano Frost
Denmark

MT_dialog
Offline
Last seen:1 month 4 weeks ago
Staff
加入:2015-06-08 11:34
Hi ciano,

Hi ciano,

请确保下载的图片in the 580 has the CFG_TRNG defined, i tested your scenario with the SDK 5.0.2.1 in a modified template example advertising in non-connectable mode (different advertising strings, different bd_addresses and same advertising intervals ) and by connecting the two reset pins i issue a reset at the two boards at the same time. I can properly see the boards with a sniffer and with a normal android BLE app. The only way i could get one device and corrupted advertising data is when the CFG_TRNG is undefined. Please check the sniffer attachments when TRNG is defined and when its not.

Thanks MT_dialog

Attachment:
ciano
Offline
Last seen:4 days 5 hours ago
加入:2014-10-03 08:13
Hi Dialog

Hi Dialog

One thing I forgot to mention, is that I am using a timer to restart the advertisment every one second. I change the advertisment data every time. I set up the advertisement with user_non_connectable_advertise_conf.intv = 16000 which is 10seconds. So my effective interval is determined by my 1 second timer, where I stop and restart the advertisement.

Now my question is: Will there still be added a random 0-10 ms delay to the advertisement, when the bluetooth stack has its advertisment restarted every second?
If the random delay is not added in this case, then this could explain the collisions I experience of the advertisements in the air.

Looking forward for your answer.
Best Regards,
Ciano

MT_dialog
Offline
Last seen:1 month 4 weeks ago
Staff
加入:2015-06-08 11:34
Hi ciano,

Hi ciano,

So you are advertising 1 advertising packet every 1 second and this is defined by an elapsed timer that issues an advertise start. That explains what you are experincing, the first advertising message hasn't a delay applied to it. After the app_adv_start is issued the advertising string is transmited in the same time as the other DUT after that the next advertising event is re-scheduled with a random delay, so in the first message you send there is a collision between the two advertising messages. A work around of what you are experiencing is to decrease the advertising interval so that the second advertising string is transmitted within the 1 second interval and the random delay to insert the advertising interval so that the two advertising string doesnt collide.

You can count the advertising string that you have emmited and stop the advertising in the second emmited advertising string (which will be received correctly), you can catch the completetion of the advertising and and start the timer, when tha timer elapses start advertising again.

Here is a small snippet on how you can count your advertising events:

enum arch_main_loop_callback_ret count_adv_events(void)
{
uint8_t temp_last_ble_event;
temp_last_ble_event = arch_last_rwble_evt_get();
if (app_last_ble_event != temp_last_ble_event)
{
app_last_ble_event = temp_last_ble_event;
if (app_last_ble_event == BLE_EVT_END)
adv_count++;
if (adv_count == 2)
{
adv_count=0;
app_easy_gap_advertise_stop();
}
}
return GOTO_SLEEP;
}

Thanks MT_dialog

ciano
Offline
Last seen:4 days 5 hours ago
加入:2014-10-03 08:13
Thank you for the answer.

Thank you for the answer.

One more question:
As I understand, then the random delay which is added to the advertisement interval i in the range of 10 ms. Is it possible to increase this range to something like 500 or 1000ms?

Currently I have done this manually with an app timer setup from a fixed delay plus a random (TRNG) time from -500ms to 500ms ... This spreads the advertisement in time, and I do almost not see any collisions with many fobs.

Best Regards,
Ciano Frost
Denmark

MT_dialog
Offline
Last seen:1 month 4 weeks ago
Staff
加入:2015-06-08 11:34
Hi ciano,

Hi ciano,

The delay that is inserted in the advertising operation is located in the ROM code according to the BLE spec, you cant change that.

Thanks MT_dialog

ciano
Offline
Last seen:4 days 5 hours ago
加入:2014-10-03 08:13
Thank you very much for the

Thank you very much for the info.

I have no more questions for now.

Best Regards,
Ciano Frost
Denmark.

Topic locked