discoverAllCharacteristics - does not have class type

Hello! I have been doing some research and testing with BLE on the Argon and I have ran into a compile error that I cannot track down. Below is the portion of my code that I am having trouble with…the two lines commented out:

if (svcCount > 0 && foundServiceUuid == “10AB”){
peer = BLE.connect(scanResults[ii].address, true);
BLE.stopScanning();

        }

        if (peer.connected()) {
            Log.trace("LightBlue device is connected");
            Vector<BleCharacteristic> ble_peer_all_chars = peer.discoverAllCharacteristics();
            if (ble_peer_all_chars.size()) {
                Log.trace("Found %u Services", ble_peer_all_chars.size());
                for (int i = 0; i < ble_peer_all_chars.size(); i++){
                    //String CharacteristicUUID = ble_peer_all_chars[i].UUID.toString().c_str());
                    //Log.trace("Service : %s", (const char*)CharacteristicUUID);
                }
            }
        } else {
            Log.trace("LightBlue device NOT connected");
        }

This is the compile error:
/Users/markingle/Downloads/IoTCode/Argon_BLE_Example/src/Argon_BLE_Example.ino:165:47: error: ‘ble_peer_all_services.spark::Vector<T, AllocatorT>::operator[]<particle::BleService, spark::DefaultAllocator>(i).particle::BleService::UUID’ does not have class type
String servicesUUID = ble_peer_all_services[i].UUID.toString().c_str());

The compile error is one that I am familiar with but I cannot track down the problem…I have even reviewed the spark_wire lib.

With two problematic lines commented out so that the code will compile my BLE.scan is successful with 5 devices being found and connecting to the peripheral with the service ID (10AB) I am interesting in:

0000115111 [app] TRACE: BLE.scan found 5 devices
0000115112 [app] TRACE: MAC: DA:A3:DA:39:32:6F | RSSI: -37Bm Services: 1
0000115114 [app] TRACE: LighBlue Virtual Device
0000115115 [app] TRACE: Found 1 services
0000115116 [app] TRACE: Service 0, UUID: 10AB
0000115134 [wiring.ble] TRACE: New peripheral is connected.
0000115136 [wiring.ble] TRACE: Start discovering services.
0000116261 [wiring.ble] TRACE: Start discovering characteristics.
0000122830 [app] TRACE: LightBlue device is connected
0000122832 [app] TRACE: Found 10 Services
0000122832 [app] TRACE: MAC: 23:80:B0:EC:B9:7F | RSSI: -59Bm Services: 0
0000122834 [app] TRACE:
0000122834 [app] TRACE: Found 0 services
0000122835 [app] TRACE: LightBlue device is connected
0000122837 [app] TRACE: Found 10 Services
0000122837 [app] TRACE: MAC: 45:31:98:EF:49:4D | RSSI: -72Bm Services: 0
0000122839 [app] TRACE:
0000122839 [app] TRACE: Found 0 services
0000122840 [app] TRACE: LightBlue device is connected
0000122841 [app] TRACE: Found 10 Services
0000122842 [app] TRACE: MAC: A1:2C:DA:00:F7:74 | RSSI: -69Bm Services: 0
0000122844 [app] TRACE:
0000122845 [app] TRACE: Found 0 services
0000122845 [app] TRACE: LightBlue device is connected
0000122847 [app] TRACE: Found 10 Services
0000122847 [app] TRACE: MAC: DD:6C:93:33:4A:77 | RSSI: -91Bm Services: 0
0000122849 [app] TRACE:
0000122849 [app] TRACE: Found 0 services
0000122850 [app] TRACE: LightBlue device is connected
0000122851 [app] TRACE: Found 10 Services
0000122852 [app] TRACE: Looking for characteristic

After reviewing the lib I found that the discoverAllServices AND discoverAllCharacteristics are already being called but there is no documentation on how to address any objects that have been created. The evidence that they are called is in the log trace…

0000115134 [wiring.ble] TRACE: New peripheral is connected.
0000115136 [wiring.ble] TRACE: Start discovering services.
0000116261 [wiring.ble] TRACE: Start discovering characteristics.

Does anyone have any recommendations on what to troubleshoot or examples that would clear this up? Thanks in advance for any help!

UUID is a method, not a member variable, so you need to use UUID().

1 Like

UUID is a function that returns a BleUUID object (probably a reference, the documentation isn’t clear)

https://docs.particle.io/reference/device-os/firmware/argon/#uuid-

Maybe do something like this (warning, just an untested swipe at it)

BleUUID bid = ble_peer_all_chars[i].UUID();
if (bid.type() == BleUuidType::SHORT) { // 16-bit
  Log.trace("Service : %04x", *((uint16_t*)bid.rawBytes());
}
else if (bid.type() == BleUuidType::LONG) { // 128-bit
  Log.trace("Service : %08x-%04x-%04x-%04x-%x04%x08",
    *((uint32_t*)(bid.rawBytes()+12),
    *((uint16_t*)(bid.rawBytes()+10),
    *((uint16_t*)(bid.rawBytes()+8),
    *((uint16_t*)(bid.rawBytes()+6),
    *((uint16_t*)(bid.rawBytes()+4),
    *((uint32_t*)(bid.rawBytes()) );
}
else { // unknown type
  Log.error("BleUuidType is unknown!");
}

Edit: Assuming the 128 bits are packed little-endian, this should be closer to displaying the correct format now.

Thanks @rickkas7!!! I cannot believe I overlooked that obvious error…I just knew the problem was in the lib…lol. I appreciate the help!

@MarkIngle - would you mind sharing your full code for this? Seems quite close to what I’d also like to do (scan for devices advertising, connect to one, understand services and ultimately get some sensor data).

I’ve been battling to find a suitable, simple enough example to cover this.

Thanks,

Neal.

@neal_tommy I dont mind sharing…its cobbled together from different sources. But its pretty big…do you have a github account? I can set you up as a collaborator. If not I we can figure something out…let me know

@MarkIngle - my github account is neal-tommy82.
Very happy with cobbled together code… this is the way I work, trying snippets of goodness from multiple sources, and stitching it together!

Thanks. N

@neal_tommy I just made the code public…its a WIP but let me know what questions you have.