cancel
Showing results for 
Search instead for 
Did you mean: 

BlueNRG Nucleo Shield Change Advertising Interval

Posted on May 24, 2015 at 03:48

I am making a device that most of the time will be dormant. I want it to advertise as little as possible until an event I am interested in occurs. When that occurs I want it to advertise for a few seconds and then go back into advertising once in a while.

I based my code on the chat example. I have it working to send the advertising information that I want using the Manufacturer Specific Data in the advertising packet.

Initially I set my interval to 5000 (about 5 seconds). I can see it advertising. One problem here is that the advertising is not consistent. Sometimes it advertises after 3 seconds sometimes it takes 20 seconds. That is another problem though.

The main problem is that when the event I am looking for (I use a button press to test) I issue the following commands:

    aci_gap_set_non_discoverable();

    Clock_Wait(100);

    aci_gap_set_discoverable(ADV_NONCONN_IND, 160, 160, PUBLIC_ADDR, NO_WHITE_LIST_USE,0, NULL, 0, NULL, 0, 0);

    Clock_Wait(1000);

    aci_gap_set_non_discoverable();

    Clock_Wait(100);

    aci_gap_set_discoverable(ADV_NONCONN_IND, 5000, 5000, PUBLIC_ADDR, NO_WHITE_LIST_USE,0, NULL, 0, NULL, 0, 0);

When I do this it stops advertising completely. You can see that I am basically issuing the command to stop advertising, then start again using a much smaller interval, then stop again and then finally to go back to 5000 interval.

This doesn't work. Once I issue the aci_gap_set_non_discoverable(); command then no matter what I do after that it never advertises again.

What do I do?

Is there a better way to do this?

I am using the bluenrg_gap_aci.c API that the chat application uses. As far as I can tell it waits until it sends the command before it moves on.

Is there something I need to do to wait for a response from the BlueNRG? I hear about events, but don't know how to watch for them because I don't think the chat example does. It just issues commands and moves on.

Please help.

#bluenrg-advertising-interval
1 REPLY 1
Posted on May 28, 2015 at 17:07

I figured this out.

Turns out the order you do things in is very important.

I created a new function to start the advertising. I then call that before updating the advertising information.

Before I was updating the advertising information and then trying to stop / start the advertising state.

Inside the new start advertising function I also did the whole procedure instead of just stop / start.

Here is the Start_Advertising function that works:

void Start_Advertising(uint16_t advInterv)

{  

  const char local_name[] = {10,AD_TYPE_COMPLETE_LOCAL_NAME,'M','y',' ','D','e','v','i','c','e'};

  

  /* disable scan response */

  hci_le_set_scan_resp_data(0,NULL);

  

  aci_gap_set_non_discoverable();

  

  PRINTF(''General Discoverable Mode '');

  aci_gap_set_discoverable(ADV_NONCONN_IND, advInterv, advInterv, PUBLIC_ADDR, NO_WHITE_LIST_USE,0, NULL, 0, NULL, 0, 0);

  aci_gap_update_adv_data(sizeof(local_name), local_name);

}

I seem to be able to call that with whatever interval I want and it stops / starts the advertising properly as long as I don't try to update the advertising data before I do it.