Implement BleAdvertisingDataType

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.

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);

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.

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));
1 Like

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?

Have you tried updating the global variable?

Stupid question. How would I do that exactly?

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.

@ielec Guohui is responsible for BLE development, he may help.

1 Like

Hi @BecauseScience,

The TX power you set in the advertising data should be the same as the actual TX power the device currently applying. The BLE.txPower(int8_t* txPower) API will return the actual TX power for you. And then you can call the advData.append(BleAdvertisingDataType::TX_POWER_LEVEL, ...) to insert it to the BLE advertising data object and call BLE.setAdvertisingData() to update the advertising data.

Best regards,
Guohui

1 Like