CCCD Handle not found

Posted on
  • Sorry, but I'm again a bit stuck with BLE, my issue is actually same/similar as this one, but that's 2 years old and perhaps for another device than Bangle.

    As posted here, I've been able to connect and transmit data from an Arduino-device (Nicla Sense ME), but the Arduino-program crashes with an ambigous message "Out of memory" when I want to transmit data from more sensors, this even if only approx. 50% of the memory is used. As this is for me very challenging to troubleshoot, I thought I'd instead use this Arduino-code, that is transmitting to a WebBLE dashboard. The web dashboard works fine.

    However, when trying to connect from Bangle, a connection is established, but I initially got CCCD Handle not found. The Arduino advertising code is using this BLEFloatCharacteristic temperatureCharacteristic("19b10000-2001­-537e-4f6c-d104768a1214", BLERead); where I've from BLEProperty.h found out that BLERead = 0x02. Thus I tried using the same on the Bangle side:

        ch.handle_cccd = 0x02;
        return ch.startNotifications();
    

    but I'm still not receiving any data. nRFConnect is very seldom able to connect to the Nicla-device, but the few times it has been, I've not seen anything related to this cccd-handle.

    To further troubleshoot, I've tried to replace BLERead with 0x00 on the Arduino-side and use same cccd-handle on Bangle, did not help, a connection is established but no data is flowing.

    I also dived in the WebBLE-dashboard JS-code to understand how that works, and on line 11 below (line 450 in the dashboard code) this same BLERead property is used. But as said, when I'm using the same concept in the Bangle-code, I'm not getting anywhere.
    I've also tried many other permutations, too many to list here, but either I get "CCCD handle not found" or no data.

        // Set up the characteristics
        for (const sensor of sensors) {
          msg('characteristic ' + sensor + "...");
          NiclaSenseME[sensor].characteristic = await service.getCharacteristic(NiclaSenseME[s­ensor].uuid);
          // Set up notification
          if (NiclaSenseME[sensor].properties.include­s("BLENotify")) {
            NiclaSenseME[sensor].characteristic.addE­ventListener('characteristicvaluechanged­', function (event) { handleIncoming(NiclaSenseME[sensor], event.target.value); });
            await NiclaSenseME[sensor].characteristic.star­tNotifications();
          }
          // Set up polling for read
          if (NiclaSenseME[sensor].properties.include­s("BLERead")) {
            NiclaSenseME[sensor].polling = setInterval(function () {
              NiclaSenseME[sensor].characteristic.read­Value().then(function (data) { handleIncoming(NiclaSenseME[sensor], data); })
            }
              , 500);
          }
    
  • Ok, success! Not that I know why it did not work in the first place, but by getting rid of the cccd-handle altogether, I'm now able to receive data from 6 sensors to Bangle + calculating altitude from the barometer.

    31.54c co2:554 IAQ:56 Hum:25 1001.64 pa Gas:34170 Alt:-0.17m

    For the benefit of others, here's what I did:

    On Bangle side:
    Nothing, i.e. no need to handle_cccd = ...,

    On Arduino side:

    Changed to:

    BLEShortCharacteristic temperatureCharacteristic(BLE_SENSE_UUID­("2001"), BLERead | BLENotify);
    
    

    from:

    BLEShortCharacteristic temperatureCharacteristic(BLE_SENSE_UUID­("2001"), BLERead);
    
    

    ...and put this in the loop function:

    void loop(){
      while (BLE.connected()){
    
        static auto printTime = millis();
    
        BHY2.update();
        nicla::leds.setColor(blue);
    
        if (millis() - printTime >= 1000) {
    
          printTime = millis();
    
          float temperatureValue = temperature.value();
          temperatureCharacteristic.writeValue(tem­peratureValue * 100);
          Serial.println(temperatureValue);
    
          uint32_t co2 = bsec.co2_eq();
          co2Characteristic.writeValue(co2);
    
          float airQuality = float(bsec.iaq());
          bsecCharacteristic.writeValue(airQuality­);
    
          float pressureValue = pressure.value();
          pressureCharacteristic.writeValue((press­ureValue - 800) * 100);
          Serial.println(pressureValue);
    
          float humidityValue = humidity.value();
          humidityCharacteristic.writeValue(humidi­tyValue);
          
          unsigned int g = gas.value();
          gasCharacteristic.writeValue(g);
        }
    
    
  • Great! I think the issue is that CCCD Handle not found basically means you're trying to subscribe for Notifications on something that doesn't provide notifications.

    So I guess the change to BLERead | BLENotify from BLERead is what helped in this case.

    If you didn't have that, you could set Bangle.js to just do a read every so often to get the latest data (rather than having it 'pushed')

  • Thx!

    If you didn't have that, you could set Bangle.js to just do a read every so often to get the latest data (rather than having it 'pushed')

    My "use case" (actually only proof of concept) is to run inference (using Tensorflow Lite) on the Nicla-device and push the results to Bangle, perhaps also pushing some sensor data. To save power on both devices, I'm thinking of starting the Bluetooth-connection every 5 minutes or so. This is something I haven't looked into yet how to do, using setInterval perhaps?
    Anyhow, so far this use case is more of a solution searching for a problem instead of a clear requirement, so not sure yet what I'm going to do, need to brainstorm a bit :-)

  • I'm thinking of starting the Bluetooth-connection every 5 minutes or so. This is something I haven't looked into yet how to do, using setInterval perhaps?

    Yes, that should work fine! Although once a BLE connection is in progress, if the connection interval is high enough the power usage is actually very low

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

CCCD Handle not found

Posted by Avatar for ThomasVikström @ThomasVikström

Actions