This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Event when BLE notification has been enabled/disabled



Hi :)

How do I get an event when a BLE notification has been enabled or disabled by the central? I guess the configuration and I will be able to read that. But an event on configuration changes would be neat to power hardware on/off correspondingly.

I am using SimpleBLEPeripeiral as my baseline and would like to know when CHAR4 is enabled or disabled.

Thanks :)

  • I have found a way to do it myself :)

    In the function 'simpleProfile_WriteAttrCB' we have the 'case GATT_CLIENT_CHAR_CFG_UUID', which is called when a GATT_CLIENT_CHAR_CFG_UUID is changed. In this I have added code to disable/enable my hardware based on notification configuration, i.e., enabled or disabled: 

          case GATT_CLIENT_CHAR_CFG_UUID:
            status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                     offset, GATT_CLIENT_CFG_NOTIFY );

            

            // check for configuration changes on SIMPLEPROFILE_CHAR4_UUID
            // (pAttr - 1) points to previous element in the attribute table having (0xFFF4) that can be used for testing
            if ((pAttr - 1)->type.uuid == simpleProfilechar4UUID) {
              // check if one or more connections has this notification enabled
              bool enabled = false;
              for (int i = 0; i < GATT_MAX_NUM_CONN; ++i) {
                if (simpleProfileChar4Config[i].value == 1/*enabled*/) {
                  enabled = true;
                }
                if (enabled) {
                  // enable service
                } else {
                  // disable service
                }
              }
            }
            break;
    Cheers! :)