Difference in class BleScanResult IOS v2.2 to IOS v3

Gooday

I have noticed that my project only compiles successfully up to IOS v2.2. closer investigation show my beacon scan function seems to be no longer compatible. I would like to know why its not compatible with IOS 3.00 and higher

ble scan function below and the error seems to be referenced to

.advertisingData  and .address

where .advertisingData give an error

error: invalid use of member function ‘const particle::BleAdvertisingData& particle::BleScanResult::advertisingData() const’ (did you forget the ‘()’ ?)
496 | String Beacon_name = results[ii].advertisingData.deviceName();//check if the results have an name

and .address gives an error of

error: invalid types ‘[int]’ for array subscript
500 | scanResults[ii].address[5],scanResults[ii].address[4],scanResults[ii].address[3],
| ^
e:/aacrs/02_12/markvisser/git_clone/argon_boron_beacon_alarm/argon_boron_alarm_final_new_blynk/src/argon_boron_alarm_final.ino:500:83: error: invalid types ‘[int]’ for array subscript
500 | scanResults[ii].address[5],scanResults[ii].address[4],scanResults[ii].address[3],
| ^
e:/aacrs/02_12/markvisser/git_clone/argon_boron_beacon_alarm/argon_boron_alarm_final_new_blynk/src/argon_boron_alarm_final.ino:500:110: error: invalid types ‘[int]’ for array subscript
500 | scanResults[ii].address[5],scanResults[ii].address[4],scanResults[ii].address[3],
|
^
e:/aacrs/02_12/markvisser/git_clone/argon_boron_beacon_alarm/argon_boron_alarm_final_new_blynk/src/argon_boron_alarm_final.ino:501:56: error: invalid types ‘[int]’ for array subscript
501 | scanResults[ii].address[2],scanResults[ii].address[1],scanResults[ii].address[0]);
| ^
e:/aacrs/02_12/markvisser/git_clone/argon_boron_beacon_alarm/argon_boron_alarm_final_new_blynk/src/argon_boron_alarm_final.ino:501:83: error: invalid types ‘[int]’ for array subscript
501 | scanResults[ii].address[2],scanResults[ii].address[1],scanResults[ii].address[0]);
| ^
e:/aacrs/02_12/markvisser/git_clone/argon_boron_beacon_alarm/argon_boron_alarm_final_new_blynk/src/argon_boron_alarm_final.ino:501:110: error: invalid types ‘[int]’ for array subscript
501 | scanResults[ii].address[2],scanResults[ii].address[1],scanResults[ii].address[0]);

my BLE scan function


void scanBleBeacons(){
  BLE.setScanTimeout(50);
  int count = BLE.scan(scanResults, SCAN_RESULT_MAX);
  for (int ii = 0; ii < count; ii++) {
    size_t len = scanResults[ii].advertisingData.get(buf, BLE_MAX_ADV_DATA_LEN);//used to get an entire block of 31 bytes
    String Beacon_name = results[ii].advertisingData.deviceName();//check if the results have an name
    memcpy(buf_copy, buf, sizeof(buf));//make a copy
    //build  a string out of the MAC char array so we can compare to incoming
    sprintf (emMacCharToString, "em_MAC_%02x:%02x:%02x:%02x:%02x:%02x",
                                scanResults[ii].address[5],scanResults[ii].address[4],scanResults[ii].address[3],
                                scanResults[ii].address[2],scanResults[ii].address[1],scanResults[ii].address[0]);
.   
.
.
}// end of scanBleBeacons

any assistance would be greatly appreciated

Unfortunately you will need to change your code for Device OS 3.0.

The BleScanResult used to have directly accessible member variables, but in Device OS 3.0 access methods are required. Thus instead of using scanResults[ii].address[5] you use scanResults[ii].address()[5].

1 Like

This may well be in connection with the breaking changes referred to in this post

For security and consistency reasons advertisingData is not a field anymore but rather a method and hence requires the additional () when called.


snap, Rick was faster.

1 Like

Thanks Gents, worked like a charm first time round.

amended code below for reference


void scanBleBeacons(){
  BLE.setScanTimeout(50);
  int count = BLE.scan(scanResults, SCAN_RESULT_MAX);
  for (int ii = 0; ii < count; ii++) {
    size_t len = scanResults[ii].advertisingData().get(buf, BLE_MAX_ADV_DATA_LEN);//used to get an entire block of 31 bytes
    String Beacon_name = results[ii].advertisingData().deviceName();//check if the results have an name
    memcpy(buf_copy, buf, sizeof(buf));//make a copy
    //build  a string out of the MAC char array so we can compare to incoming
    sprintf (emMacCharToString, "em_MAC_%02x:%02x:%02x:%02x:%02x:%02x",
                                scanResults[ii].address()[5],scanResults[ii].address()[4],scanResults[ii].address()[3],
                                scanResults[ii].address()[2],scanResults[ii].address()[1],scanResults[ii].address()[0]);
    //make sure its a eddystone TLM beacon
.
.
.}//end of function