This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 s110 - How to determine if Notification and/or Indication for each characteristic is switched on or not by the central

Using S110 version 6.0.0, Sdk 5.2.0, GCC 4.8 (C++, but that don't matters here).

I want to know, if the central has switched Notification and/or Indication on or off for a specific characteristic.

As seen in the experimental nRF Uart example code, I could hear on BLE_GATTS_EVT_WRITE and then call ble_srv_is_notification_enabled() / ble_srv_is_indication_enabled(), like this:

void BleNts::onWrite(const ble_evt_t& bleEvt) {
    // TODO: Should I also check bleEvt.evt.gatts_evt.conn_handle==connHandle ?
    const ble_gatts_evt_write_t& evtWrite = bleEvt.evt.gatts_evt.params.write;
    auto handle = evtWrite.handle;
    if (evtWrite.handle == handles.cccd_handle and evtWrite.len == 2) {
        bool notificationEnabled = ble_srv_is_notification_enabled(const_cast<uint8_t*>(evtWrite.data));
        bool indicationEnabled = ble_srv_is_indication_enabled(const_cast<uint8_t*>(evtWrite.data));
        LOG_DEBUG("notification=%d indication=%d", notificationEnabled, indicationEnabled);
    }
}

But this fails e.g. for the following szenario:

  • Central has switched both Notification and Indication on
  • Central now swiched Notification off (while leaving Indication switched on)
  • in this case, the above code thinks that both Notification and Indication should switched off

I'd made a bit debug output inside of my void BleNts::onBleEvt(const ble_evt_t& bleEvt) and see the following (using nRF Mcp as Central side to switch notification/indication on/off):

// Starting with both notification and indication switched off
// Step 1: At first switching notification on
Ble event id=50h len=34, name=GATTS_EVT_WRITE, range=Gatt server event
  conn_handle=0
  Write: handle=15, op=1, offset=0, len=2, data=01 00
  Context: srvc_uuid=0001/2, char_uuid=0004/2, desc_uuid=2902/1, srvc_handle=12, value_handle=14, type=6
BleNts notification=1 indication=0

// Step 2: Now also switching indication on
Ble event id=50h len=34, name=GATTS_EVT_WRITE, range=Gatt server event
  conn_handle=0
  Write: handle=15, op=1, offset=0, len=2, data=02 00
  Context: srvc_uuid=0001/2, char_uuid=0004/2, desc_uuid=2902/1, srvc_handle=12, value_handle=14, type=6
BleNts notification=0 indication=1
// ... wrong result ...

// Step 3: Now switching notification off
Ble event id=50h len=34, name=GATTS_EVT_WRITE, range=Gatt server event
  conn_handle=0
  Write: handle=15, op=1, offset=0, len=2, data=00 00
  Context: srvc_uuid=0001/2, char_uuid=0004/2, desc_uuid=2902/1, srvc_handle=12, value_handle=14, type=6
BleNts notification=0 indication=0
// ... wrong result ...

// Step 4: Finally switching also indication off
Ble event id=50h len=34, name=GATTS_EVT_WRITE, range=Gatt server event
  conn_handle=0
  Write: handle=15, op=1, offset=0, len=2, data=00 00
  Context: srvc_uuid=0001/2, char_uuid=0004/2, desc_uuid=2902/1, srvc_handle=12, value_handle=14, type=6
BleNts notification=0 indication=0

Within my debug output, I see no difference between step 3 and step 4; both contains "data=00 00".

Seems that I better should ask something from inside the S110 instead of evaluate the received data, isn't it?

Any suggestion about that?

Parents Reply Children
No Data
Related