Search code examples
pythonbluetooth-lowenergygatt

Python BLE GATT Server personalised characteristic read


I have implemented a GATT server with a characteristic that supports read and write based on the code from https://github.com/Douglas6/cputemp .

I was wondering if there is a way to "identify" the connected device in order to supply personalised answers while reading the same characteristic from different clients.

i.e. bluetooth client bl_1 reads "1" while bluetooth client bl_2 reads "2" from the same characteristic.

Is the connected device id accessible from the GATT server functions?


Solution

  • ReadValue and WriteValue have an options parameter that contains the connected device path, and this will identify it.

      def WriteValue(self, value, options):
    
        if ("device" in options):
          print(options['device'])