Implement BleAdvertisingDataType

argon
Tags: #<Tag:0x00007fe22b217900>

#1

I am attempting to create a peripheral device with the Argon which is compliant with Apple’s guidelines. One of the requirements is Tx Power Level. In the Argon reference, it shows TX_POWER_LEVEL under the BleAdvertisingDataType section. To my limited understanding, I think it be be implemented the following way, but doesn’t seem to work:

advData.append(BleAdvertisingDataType::TX_POWER_LEVEL);

Any help would be appreciated.


#2

This is a not very helpful error description.

In what way does it not work?
Do you get a compile error?
If so, which?
How much other data have you got in your advertising data?
Can you show all/more of your code?

The reference for advData.append() would suggest you’d need more parameters
https://docs.particle.io/reference/device-os/firmware/argon/#append-

size_t append(BleAdvertisingDataType type, const uint8_t* buf, size_t len, bool force = false);

#3

My bad. Here is the compile error I get.

bleperipheral.ino:40:58: no matching function for call to 'particle::BleAdvertisingData::append(particle::BleAdvertisingDataType)'

As far as the additional parameters go, I’m not sure what to put there. It’s either not clear or I’m just not an experienced enough programmer.


#4

The Particle docs can’t really be more specific as the type (of which there are many) will dictate what kind of buffer your data will require.

IIRC, for TX_POWER_LEVEL this would be an int16_t, so you could try this

int16_t pwrLevel = 0; // global variable
...
  advData.append(BleAdvertisingDataType::TX_POWER_LEVEL, (uint8_t*)&pwrLevel, sizeof(pwrLevel));

#5

Thank you! Like I said, I’m new to particle, so I’m not sure I would have figured that out. However, that solved my compiling issue. I can now see that global variable. That being said, do you know how I can update that with the actual value?


#6

Have you tried updating the global variable?


#7

Stupid question. How would I do that exactly?


#8

First we’d need to establish if this value is actually updated in the advertised data when the variable changes.
Since it’s a global variable you can do that from any function (e.g. loop()) like this

void loop() {
  pwrLevel -= -5;
  delay(1000);
}

this would decrease the advertised value by 5 every second.

How to acquire the actual transmission power from the system I don’t know either :wink:
That’s something I’d think @eugene0501 would be able to comment on.