Author Topic: RFduinoBLE_onAdvertisement not called every time the radio advertises  (Read 1346 times)

tcollinsworth

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
The documentation says
- RFduinoBLE_onAdvertisement()
This function allows you to run a piece of code everytime the radio advertises

I'm printing to serial out and toggling an LED and I'm only seeing it called when I call RFduinoBLE.begin and RFduinoBLE.end. It doesn't get called but at begin and end even though the Interval is set to various values.


tolson

  • Global Moderator
  • *****
  • Posts: 812
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: RFduinoBLE_onAdvertisement not called every time the radio advertises
« Reply #1 on: February 12, 2016, 03:11:24 PM »
The community can't help you if you don't supply example code showing the issue. The community can only guess what you coded that may or may not be attributable to what you are experiencing.

tcollinsworth

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: RFduinoBLE_onAdvertisement not called every time the radio advertises
« Reply #2 on: February 13, 2016, 10:05:03 AM »
Below is a modified AdvertismentContinuous example script that came with the RFduino library. The onAdvertisement(bool start) method is only called after RFduinoBLE.begin() and not again until RFduinoBLE.begin()  is called again. The led never blinks and the counts never increase. If I change it to call RFduinoBLE.begin() and end() in the loop, then the start counts increase, but the end counts don't. Since the example clearly should blink the stock example clearly should blink the LED and it wasn't stopping and starting the BLE, then we can only assume from the documentation that onAdvertisement should be called based on the BLE advertising interval as the radio starts and stops. Clearly that isn't happening. Either I'm missing something or the library is broken. I have tried multiple RFduino's and they all react the same. I just received some Simblee's and I'll try those to see if they react the same.

Output:

Code: [Select]
init
advStartCnt=1,advEndCnt=0
advStartCnt=1,advEndCnt=0
. . .

Code: [Select]
#include <RFduinoBLE.h>

int led = 3;

volatile uint8_t advStartCnt = 0;
volatile uint8_t advEndCnt = 0;

void setup() {
  pinMode(led, OUTPUT);

  RFduinoBLE.advertisementData = "data";
  RFduinoBLE.advertisementInterval = 1000;

  Serial.begin(9600);
  Serial.println("init");
   
  RFduinoBLE.begin();
}

void loop() {
  RFduino_ULPDelay(10000);
  Serial.print("advStartCnt=");
  Serial.print(advStartCnt);
  Serial.print(",advEndCnt=");
  Serial.println(advEndCnt);
}

void RFduinoBLE_onAdvertisement(bool start)
{
  if (start) {
    digitalWrite(led, HIGH);
    ++advStartCnt;
  } else {
    digitalWrite(led, LOW);
    ++advEndCnt;
  }
}

Code: [Select]
init
advStartCnt=0,advEndCnt=0
advStartCnt=1,advEndCnt=0
advStartCnt=2,advEndCnt=0
. . .


Code: [Select]
#include <RFduinoBLE.h>

int led = 3;

volatile uint8_t advStartCnt = 0;
volatile uint8_t advEndCnt = 0;

void setup() {
  pinMode(led, OUTPUT);

  RFduinoBLE.advertisementData = "data";
  RFduinoBLE.advertisementInterval = 1000;

  Serial.begin(9600);
  Serial.println("init");
}

void loop() {
  RFduino_ULPDelay(10000);
  Serial.print("advStartCnt=");
  Serial.print(advStartCnt);
  Serial.print(",advEndCnt=");
  Serial.println(advEndCnt);
  RFduinoBLE.end();
  RFduinoBLE.begin();
}

void RFduinoBLE_onAdvertisement(bool start)
{
  if (start) {
    digitalWrite(led, HIGH);
    ++advStartCnt;
  } else {
    digitalWrite(led, LOW);
    ++advEndCnt;
  }
}

tcollinsworth

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: RFduinoBLE_onAdvertisement not called every time the radio advertises
« Reply #3 on: February 13, 2016, 10:32:21 AM »
The onAdvertisement(bool start) is called with a false when a connection occurs.

It would be far more useful for the onAdvertisement() to be called before and/or after the periodic advertisements. I really wanted to do one or 'n' advertisements and shut down the radio for a long period to extend the battery.
The other obvious useful thing would have been to update data in the advertisement packets between advertisements. But that isn't practical since it isn't being called before and/or after each advertisement.
Is there any easy way to accomplish either of those?

The onAdvertisement() isn't providing usefulness that I can't get with begin(), onConnect(), and onDisconnect().

It's called after begin with true, but we know that is going to happen.
It's called with false during connection, but onConnect is called, so we know that too.
It's called after onDisconnect() with true, but we also know that it's going to start advertising unless the onDisconnect was because we called end().

So basically onAdvertisement() isn't called when it actually starts or stops transmitting an advertisement, it's called after begin(), connect(), and disconnect(). Doesn't seem very useful to us!!!

Please update the documentation to be a little more clear. Is Simblee the same? This cost me way too much time to figure out that I can't use it either of the ways I was expecting from the name and documentation.  >:(

tolson

  • Global Moderator
  • *****
  • Posts: 812
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: RFduinoBLE_onAdvertisement not called every time the radio advertises
« Reply #4 on: February 13, 2016, 05:02:48 PM »
I see what you are saying now. Yep, from their examples they say it is called when they start advertisement and when they stop advertisement. As in changing the mode. Not each time it actually transmits an advertisement packet. And, yes if someone connects  or disconnects that also causes the onAdvertisement callback to be called. I see how it is confusing because the documentation implies each time it advertises which could mean each time they send an advertisement packet; which they clearly are not doing. Hmm!
As there advertisements examples get more complicated they show how they are advertising for x amount of time and change things. So I guess that is what they expect you to do. For example you know you set the advertisement interval to 1000ms so if you want to advertise for 10 times then change the data, you sleep or delay or otherwise keep track of time for 10 seconds then .end, change things, and restart.

Like you say, when someone connects and disconnects the onAdvertisement would be triggered as well, so depending on counting transmissions expectiations things can get complicationed.

Maybe the RFduino Team will chime in on clarification.

 

anything