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

Best way to send data from many sensors

Hi,

For an application I have a nRF51 at my disposal and I need to transfer about 3'000Bytes. I found in the documentation that the nRF51 can use the S130 SoftDevice which support BLE 4.2. The data I have to transfer come from 1 to 50 sensors and are divided in 2 categories with 3 respective 6 parameters each as follow:

Sensor No1

  • Data type A
  • --Parameter A1
  • --Parameter A2
  • --Parameter A3
  • Data type B
  • --Parameter B1
  • --Parameter B2
  • --Parameter B3
  • --Parameter B4
  • --Parameter B5
  • --Parameter B6

Sensor No2

  • Data type A
  • --Parameter A1
  • --Parameter A2
  • --Parameter A3
  • Data type B
  • --Parameter B1
  • --Parameter B2
  • --Parameter B3
  • --Parameter B4
  • --Parameter B5
  • --Parameter B6

Sensor NoX

  • Data type A
  • --Parameter A1
  • --Parameter A2
  • --Parameter A3
  • Data type B
  • --Parameter B1
  • --Parameter B2
  • --Parameter B3
  • --Parameter B4
  • --Parameter B5
  • --Parameter B6

I thought that a way to transfer these results would be to use 2 customized services (a service for type A and a service for type B) with 3 respective 6 characteristics (A1-A3 and B1-B6) each. Each characteristic should have up to 50 values. The number of values in each characteristic would indicate the number of sensors.

Has someone a better / a more suitable solution for this use case?

Thanks in advance for you ideas.

  • B) your understanding of GATT Characteristics seems to be wrong. There is "Value" handle attached to each Char and that is used for Write/Read methods (= data are "stored" there). However on top of the same "Value" handle you can support Notify or Indicate methods which are kind of "separate" (one time) data transfers not interfering with data in actual "Value" buffer. Or at least this is my understanding and also implementation in Nordic Stack (but please validate this experimentally). All methods must be "allowed" on given Characteristic explicitly but you can combine it so one single Char you can allow Notifications as well as Write methods and let the data flow bi-directionally (and you can allow even more things of course). The only limitation seems to be that methods cannot be combined within one connection interval (so it's kind of half-duplex).

  • C) In Nordic SD API there are GATT calls how to send data out through Notify method but note that Notifications (and Indications) by nature cannot be larger then ATT_MTU size! (again this is my understanding, maybe good to double check with other sources on this forum and internet). The usual solution is to implement custom fragmentation/reassembly protocol on top of GATT (bellow your APP data) which then allows you to transport theoretically unlimited sizes of data strings.

  • E) The size limits I mention are linked to ASN.1 BER-TLV notation (length encoding to be specific) but that's completely independent on BLE so you can forget about it if you don't plan to use it;)

  • Sorry, one more to Notifications and CCCD: once you allow Notification as method for given Characteristic then GATT Server (= the stack under the API aka Soft Device in Nordic case) automatically creates CCCD handle for you. You just need to remember its handle number so then if write arrives to it you know what is it (and can check data which might mean that Client wants to activate Notifications or anything else). You can try to blindly use API and just catch if there is some error return from SD (like "invalid operation (because Notifications are not enabled)") but that doesn't look like proper way of doing SW development;)

Related