I am looking for a best solution to this scenario as in title:
I read in some posts (eg. this post) that can use multiple ble service instances
also in this post mentioned multiple GATT server instances can be used.
My concern mainly focus on that different centrals will have different data stream and status values, so these instances can not share same copy of values or status.
Also i checked the ble services implementation in SDK14, does not see much related to multi-instances ready. The multi-peripheral example does not give much detail on how multiple
instances of services should be handled.
So the questions are:
what are the best way to go, multiple service instances or multiple GATT servers?
are there any examples for guide purpose?
I believe you are mixing terms and layers. Firstly there are Master And Slave roles on the lowest Logical Link layer. They are asymmetric and always peer to peer (as everything in Bluetooth) so you need o have right mix to establish the connection and you need to have right number of "slots" if you want to establish multiple links form single HW/SW stack (device). In BLE this is usually paired with the highest layer called Generic Access Profile (GAP) which simply says what roles each device plays and when. Master is called Central on GAP while Slave is called Peripheral. Anyway all this is (and I do agree it might be confusing at the beginning) logically independent with what is happening "in between" meaning on top of LL and bellow APP. That is called (G)ATT (ATTribute Protocol and Generic ATTribute protocol - technically two layers but no one is really picky about the boarder line because in 99% of cases it's GATT you see from the top), it has also asymmetric roles (called Server and Client) and you again need to have matching roles to make the data exchange happen but it's independent on LL (which runs bellow) and you can have both Client or Server on top of each Central and Peripheral. And you can have even both on top of any link established! (now it starts to be complex but that's the world around us;)
So finally to your question which doesn't make sense technically:
I don't quite understand what you want to do, but by spec you can only have one server on a Bluetooth device:
There shall be only one instance of a server on each Bluetooth device; this implies that the attribute handles shall be identical for all supported bearers.
See Vol. 3, Part F, Section 2 in the Bluetooth core v5.0.
Sry for the late reply as i am working on other threads before turning back to this one.
Basically i have, say, 5 central devices that connect to the same peripheral device. each device has exactly same functions, but data exchanged with the peripheral device are different. One choice i have is to defined 5 services for each of them, or another one is have 1 service for them all.
Having 5 services defined does not seem to be elegant or scalable solution. However having 1 for all will need to have multiple instance of characteristic/attribute values.
I saw your answer in this post said can have multiple instance of services defined. I would like to try this solution but in that case, i am not sure how multiple attribute instances are handled.
When you say they have the same functions, but data exchanged is different, could you elaborate a bit? Will you only have one central device connected at the time?
I find this macro has been listed in SDK14:
#define NRF_SDH_BLE_OBSERVERS ( _name,
But i am not sure if nordic services library already adopt this.