Bluetooth connection

I have a Serial Bluetooth dongle i’m attempting to pair with (from the Particle Boron)

I have the Scan code done, but I seem to be getting nonsense MAC addresses (unknown vendor) and missing the bluetooth devices (who are announcing)

Example code:

void scanResultCallback(const BleScanResult *scanResult, void *context) {
    String name = scanResult->advertisingData.deviceName();
    if (name.length() == 0) {
        name = "Unknown";
    }
    
    for (int vindex = 0; vindex < sizeof(knownVendors) / sizeof(vendor_t); vindex++) {
        if (scanResult->address[0] == knownVendors[vindex].first
            && scanResult->address[1] == knownVendors[vindex].second
            && scanResult->address[2] == knownVendors[vindex].third) {
            Log.info("BLE: rssid=%d address=%02X:%02X:%02X:%02X:%02X:%02X (Known OBDII!) %s",
                scanResult->rssi, scanResult->address[0], scanResult->address[1],
                scanResult->address[2], scanResult->address[3], scanResult->address[4],
                scanResult->address[5], name.c_str());
            
            if (bestAdapter == NULL || scanResult->rssi > bestAdapter->rssi) {
                // Show whatever device has the strongest signal
                bestAdapter = (BleScanResult*)malloc(sizeof(BleScanResult));
                memcpy(bestAdapter, (BleScanResult*)scanResult, sizeof(BleScanResult));
            }
        } else {
            Log.info("BLE: rssid=%d address=%02X:%02X:%02X:%02X:%02X:%02X (Unknown Device) %s",
                scanResult->rssi, scanResult->address[0], scanResult->address[1],
                scanResult->address[2], scanResult->address[3], scanResult->address[4],
                scanResult->address[5], name.c_str());
        }
    }
}

void bl_scan() {
    Log.info("BLE: Starting Scan...");
    BLE.scan(&scanResultCallback, NULL);
    
    if (bestAdapter == NULL) {
        RGB.color(255, 0, 0);
    } else {
        RGB.color(0, 255, 0);
    }
}

Result:

0005977934 [app] INFO: BLE: rssid=-77 address=DF:4F:18:D3:33:D6 (Unknown Device) Unknown
0005986136 [app] INFO: BLE: Starting Scan...
0005987964 [app] INFO: BLE: rssid=-74 address=DF:4F:18:D3:33:D6 (Unknown Device) Unknown
0005997090 [app] INFO: BLE: Starting Scan...
0006008044 [app] INFO: BLE: Starting Scan...
0006018997 [app] INFO: BLE: Starting Scan...

Groan. All of the particle documentation examples show the wrong endian for the mac addresses.

address=DF:4F:18:D3:33:D6 is what the docs show bytes 0,1,2,3,4,5
address=D6:33:D3:18:4F:DF is what the device actually is, bytes 5,4,3,2,1,0

So the only device the Particle sees is a Tile… which is Bluetooth 4.0 Low Energy. So the particle can only interface with other Bluetooth Low Energy devices and can’t scan for or pair with Non-LE devices. (the documentation also doesn’t say this… just that it’s Bluetooth 5.0)

Unless there is some “non-BLE” api that isn’t documented?

The peer getCharacteristicByUUID calls are also improperly documented. They return a bool, and want a pointer for the pulled Characteristic.

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

… and the BLE advertisingData isn’t populated when examined via a scanResult callback.

void scanResultCallback(const BleScanResult *scanResult, void *context) {
    
    uint8_t buf[BLE_MAX_ADV_DATA_LEN];
    size_t len;
    
    String name = scanResult->advertisingData.deviceName();
    
    Log.info("BLE: Found rssid=%d address=%02X:%02X:%02X:%02X:%02X:%02X. %s Probing...",
        scanResult->rssi, scanResult->address[5], scanResult->address[4],
        scanResult->address[3], scanResult->address[2], scanResult->address[1],
        scanResult->address[0], name.c_str());
    
    BleUuid* services;
    size_t serviceCount;
    scanResult->advertisingData.serviceUUID(services, serviceCount);

    Log.info("Located %d services", serviceCount);
    
    for (size_t i = 0; i < serviceCount; i++) {
        Log.info("BLE: Advertising %s", services[i]);
        if (services[i] == BleUuid("000018f0-0000-1000-8000-00805f9b34f")) {
            Log.info("OBD2: Identified '%s' as a supported VGate iCarPro OBD2 adapter!",
                name.c_str());
        } else {
            // Unsupported, unknown peer.
            continue;
        }
        if (bestAdapter == NULL || scanResult->rssi > bestAdapter->rssi) {
            // Show whatever device has the strongest signal
            bestAdapter = (BleScanResult*)malloc(sizeof(BleScanResult));
            memcpy(bestAdapter, (BleScanResult*)scanResult, sizeof(BleScanResult));
        }
    }
}
0000213502 [app] INFO: BLE: Found rssid=-50 address=0D:04:E6:C3:1D:C6.  Probing...
0000213504 [app] INFO: Located 0 services

I’ve confirmed this device has at least 1 advertised service via LightBlue on android. The name from advertisingData is also blank.

Sorry for the long thread talking to myself… a lot of stuff on the Particle around BLE central seems broken / incomplete. :expressionless:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.