How GATT server can distinguish between connecting devices
How GATT server can distinguish between connecting devices
There is a GATT server. Different GATT clients connect to it at different times. Is there a way to find out the name of the client's device or otherwise distinguish them?
Re: How GATT server can distinguish between connecting devices
In my project, two clients are connected to the same server at the same time (thanks for esp32 that allows this). One of the clients sends values to the server, and the server must send notifications to the other client. The task is for the server to know who is who of its clients and send notifications to the right one.
Now I decided it this way: I created a special writable characteristic on the server and the client that needs notifications writes some value to this characteristic, for example, self ble address. The server, in time of processing an event for writing a characteristic, notices which of the clients sent a request to write to this special characteristic, writes down the id of that connection and sends notifications over this particular connection.
If there is a way to make it easier, tell me.
Now I decided it this way: I created a special writable characteristic on the server and the client that needs notifications writes some value to this characteristic, for example, self ble address. The server, in time of processing an event for writing a characteristic, notices which of the clients sent a request to write to this special characteristic, writes down the id of that connection and sends notifications over this particular connection.
If there is a way to make it easier, tell me.
Re: How GATT server can distinguish between connecting devices
I dont know what you exactly trying to do, but from description i can think about such design:
- server,
- client that needs notifications, register for notifications,
- client that only writes to server, does not register for notifications
- server,
- client that needs notifications, register for notifications,
- client that only writes to server, does not register for notifications
Re: How GATT server can distinguish between connecting devices
Yes, it looks very logical. I didn’t do that, because I’m not sure about how libraries work, and I have nowhere to ask. Will the server be sure to send a notification to the client that requested notifications, or will it send notifications to all clients? The characteristic has only a descriptor for sending a notification, how does the server remember which of the clients should be sent a notification, and which should not? Where is this information stored?
Re: How GATT server can distinguish between connecting devices
Notifications is like broadcast and forget. the only thing what server cares about is: "is there anyone that wish to listen to my notifications?". Thats why you have CCC descriptor. Notification is like UDP broadcast.User4356 wrote: The characteristic has only a descriptor for sending a notification, how does the server remember which of the clients should be sent a notification, and which should not?
The logic is in client code, which may or may not want to listen for notifications from some server and from some characteristic.
Re: How GATT server can distinguish between connecting devices
Does this mean that the server sends notifications to everyone at once, broadcast? Or does the server store the ids of connections of devices that want to listen to the notification and sends the data personally to each client?
Re: How GATT server can distinguish between connecting devices
I ask you twice for a reason. The esp32 API function for sending notifications has a connection id parameter:
What is it for there, if the server sends notifications broadcast? Maybe this is some other notification, via already established communication channels? Then how to make a broadcast notification? Or are you just telling not a true?
Code: Select all
esp_ble_gatts_send_indicate(gatts_if, conn_id, attr_handle, value_len, value, need_confirm);
Re: How GATT server can distinguish between connecting devices
Youre right, i was not 100% accurate in my answer.
What i was in mind is fact that even if notification is send to connected device, the device will ignore that notification as long as you dont call in your code:
https://docs.espressif.com/projects/esp ... t8uint16_t
In other hand in good code you should keep tracking CCC descriptor value for each connected device and send notification only to device that is requesting for notifications when write 0x0200 to that descriptor. It may be important when you want to send notifications with high rate or just don not make noise in the air.
So in server app you have:
- array of CCC descriptor values paired with handle
- loop(if handle wrote to CCC) send notification
What i was in mind is fact that even if notification is send to connected device, the device will ignore that notification as long as you dont call in your code:
Code: Select all
esp_ble_gattc_register_for_notify
In other hand in good code you should keep tracking CCC descriptor value for each connected device and send notification only to device that is requesting for notifications when write 0x0200 to that descriptor. It may be important when you want to send notifications with high rate or just don not make noise in the air.
So in server app you have:
- array of CCC descriptor values paired with handle
- loop(if handle wrote to CCC) send notification
Re: How GATT server can distinguish between connecting devices
Thank you for reply.
As I understand it, the table of characteristics is one for the entire device. And after writing to the CCC descriptor by one client, the server will not be able to determine which client did it. At the time of writing, server can get the id of the connection, but this is approximately what I do in my code. Did I understand you correctly?
Also, if client joined to server and disconnected, How server can send notification?
As I understand it, the table of characteristics is one for the entire device. And after writing to the CCC descriptor by one client, the server will not be able to determine which client did it. At the time of writing, server can get the id of the connection, but this is approximately what I do in my code. Did I understand you correctly?
Also, if client joined to server and disconnected, How server can send notification?
Re: How GATT server can distinguish between connecting devices
1) table of characteristics is one for the entire device (usually)
2) each characteristic that supports notifications/indications should have CCC descriptor (some peripherals does not have it)
3) bluetooth specs says that every client should be able to register for notify independent, if server supports multi-connection
4) on connect you get connID/handle, which can be then used in read/write/notify/indicate operations to distinguish which client it is, the same handle you can use to track which client write to CCC and wants notifications
5) after disconnecting connID/handle is no longer valid, and sending notification to that device will return error from low level driver
This is only part of logic and all is a bit more complicated.
In arduino BLE library it is simplified IIRC and library does not track CCC, just sending notifications if any connected device write 0x0200 to CCC. It is because, like i mentioned earlier, client device will ignore notifications if does not want to receive any.
All depends what you wants to achieve. If you want to produce bluetooth device compliant with specification, which is required to use bluetooth sign on device and box you should read specs.
2) each characteristic that supports notifications/indications should have CCC descriptor (some peripherals does not have it)
3) bluetooth specs says that every client should be able to register for notify independent, if server supports multi-connection
4) on connect you get connID/handle, which can be then used in read/write/notify/indicate operations to distinguish which client it is, the same handle you can use to track which client write to CCC and wants notifications
5) after disconnecting connID/handle is no longer valid, and sending notification to that device will return error from low level driver
This is only part of logic and all is a bit more complicated.
In arduino BLE library it is simplified IIRC and library does not track CCC, just sending notifications if any connected device write 0x0200 to CCC. It is because, like i mentioned earlier, client device will ignore notifications if does not want to receive any.
All depends what you wants to achieve. If you want to produce bluetooth device compliant with specification, which is required to use bluetooth sign on device and box you should read specs.
Who is online
Users browsing this forum: Gaston1980, Google [Bot], Majestic-12 [Bot] and 257 guests