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

Custom Service Structure

I need to create a service on the nRF52832 that can send large amounts of a few different data types to the central device. For instance

  • ADC1 sampling (~256 bytes/s)
  • ADC2 sampling (~256 bytes/s)
  • IMU orientation (32 bytes/s)

And I also need to be able to receive commands from the central. This would be things like:

  • Start/ Stop sampling
  • Update device name
  • Enter Test Mode
  • Device shutdown

Should I create 1 service, and a separate characteristic for each data that I need to send? What's the best way to handle the incoming commands?

Parents
  • Depend on what is your major criteria;) Is it speed hence minimal overhead during GATT service discovery right after connection is established or you don't care about that (e.g. because your use case is rather "all the time connected" or "devices will be always bonded and GATT Server stack will be static hence Client will use cache all the time") and you rather prefer having it "nice"? I guess answering this question will give you also immediately answer to your original one;)

  • No, once you use SD API call to create Characteristic with Notification or Indication GATT method capability the stack will take care to create CCCD handle automatically for you. All you need to do is store handles' references returned in p_handles structure supplied to sd_ble_gatts_characteristic_add call for future use because there you have both your Characteristic Value handle and CCCD handle (so once there is Write event you can check to which one, look into data and interpret them correctly).

Reply
  • No, once you use SD API call to create Characteristic with Notification or Indication GATT method capability the stack will take care to create CCCD handle automatically for you. All you need to do is store handles' references returned in p_handles structure supplied to sd_ble_gatts_characteristic_add call for future use because there you have both your Characteristic Value handle and CCCD handle (so once there is Write event you can check to which one, look into data and interpret them correctly).

Children
No Data
Related