(self, uuid, callback=None, indication=False,
                  wait_for_response=True)
Enable notifications or indications for a characteristic and register a
        callback function to be called whenever a new value arrives.

        uuid -- UUID as a string of the characteristic to subscribe.
        callback -- function to be called when a notification/indication is
                    received on this characteristic.
        indication -- use indications (where each notificaiton is ACKd). This is
                      more reliable, but slower.
        wait_for_response -- wait for response after subscription.
Enable notifications or indications for a characteristic and register a
        callback function to be called whenever a new value arrives.
Enable notifications or indications for a characteristic and register a callback function to be called whenever a new value arrives .
def subscribe(self, uuid, callback=None, indication=False,
                  wait_for_response=True):

        """
        Enable notifications or indications for a characteristic and register a
        callback function to be called whenever a new value arrives.

        uuid -- UUID as a string of the characteristic to subscribe.
        callback -- function to be called when a notification/indication is
                    received on this characteristic.
        indication -- use indications (where each notificaiton is ACKd). This is
                      more reliable, but slower.
        wait_for_response -- wait for response after subscription.

        """

        value_handle, characteristic_config_handle = (
            self._notification_handles(uuid)
        )

        properties = bytearray([
            0x2 if indication else 0x1,
            0x0
        ])

        with self._lock:
            if callback is not None:
                self._callbacks[value_handle].add(callback)

            if self._subscribed_handlers.get(value_handle, None) != properties:
                self.char_write_handle(
                    characteristic_config_handle,
                    properties,
                    wait_for_response=wait_for_response
                )
                log.info("Subscribed to uuid=%s", uuid)
                self._subscribed_handlers[value_handle] = properties
                self._subscribed_uuids[uuid] = indication
            else:
                log.debug("Already subscribed to uuid=%s", uuid)
def subscribe ( self , uuid , callback = None , indication = False , wait_for_response = True ) : value_handle , characteristic_config_handle = ( self . _notification_handles ( uuid ) ) properties = bytearray ( [ 0x2 if indication else 0x1 , 0x0 ] ) with self . _lock : if callback is not None : self . _callbacks [ value_handle ] . add ( callback ) if self . _subscribed_handlers . get ( value_handle , None ) != properties : self . char_write_handle ( characteristic_config_handle , properties , wait_for_response = wait_for_response ) log . info ( "Subscribed to uuid=%s" , uuid ) self . _subscribed_handlers [ value_handle ] = properties self . _subscribed_uuids [ uuid ] = indication else : log . debug ( "Already subscribed to uuid=%s" , uuid )