BLE Device Name Always Null

boron
bluetooth
Tags: #<Tag:0x00007fe22be1ef78> #<Tag:0x00007fe22be1ec08>

#1

Hey everyone, I’m doing some scanning with the example code here: (https://github.com/particle-iot/device-os/blob/c9e118d4e7a1b18574bdb0de16fb60458009ac4a/user/tests/app/ble/scanner/application.cpp).

I’d like to be able to pick up the device names of found peripherals, but all are null. I don’t believe this to be true as the nRF Connect app shows differently. Have people had success getting device names from detected peripherals?


#2

Hi @SoupiestZebra,

By only scanning the nearby devices without connecting to it to read the device name characteristic, the scanner would not know the device name, unless the device name is contained in the device’s advertising data. You probably have used the nRF Connect app to connect your devices previously, so that the app cached the device name by reading the device name characteristic and show it for you next time it found the device.

Best regards,
Guohui


#3

Not to bring this back from the grave - but I don’t think this is an adequate answer. When I run functionally equivalent code on an ESP32 doing a simple BLE environment scan it is able to return the name without having to connect (at least I don’t believe that is happening). Is anybody able to get a value from advertisingData.deviceName()?


#4

It was definitely an issue on their end. I can get deviceName() now. Fixed around 1.4.0 I think.


#5

Weird. I’m on 1.4.4 on the Argon I’m testing with and it’s still blank. The devices I’m looking at definitely have names and address.toString() is identifying them correctly, but nothing in advertisingData.deviceName().


#6

The following works fine for me. I’m on a Boron but I don’t think that should make a huge difference? If it’s not working for you, maybe it’s device-side? Some devices will pop their device name at different registers. Maybe try using a BLE scanner app to find the specific register and then ask for it specifically in your firmware?

        BLE.setScanTimeout(100);
        BleScanResult scanResults[SCAN_RESULT_MAX];
        int count = BLE.scan(scanResults, SCAN_RESULT_MAX);
        
        uint8_t buf[BLE_MAX_ADV_DATA_LEN];
        size_t len;
    
        for (int i = 0; i < count; i++) {
    
            String name = scanResults[i].scanResponse.deviceName();
            int rssi_0 = scanResults[i].rssi;
            // Do additional stuff

        }


#7

scanResponse works! Thank you!


#8

Yeah dawg happy coding!