def bind(self, service):
     """Binds the characteristic to the given Service."""
     bound_characteristic = super().bind(service)
     # If we're given a remote service then we're the client and need to buffer in.
     if service.remote:
         bound_characteristic.set_cccd(notify=True)
         return _bleio.CharacteristicBuffer(bound_characteristic,
                                            timeout=self._timeout,
                                            buffer_size=self._buffer_size)
     return BoundWriteStream(bound_characteristic)
 def bind(self, service):
     """Binds the characteristic to the given Service."""
     bound_characteristic = super().bind(service)
     # If the service is remote need to write out.
     if service.remote:
         return BoundWriteStream(bound_characteristic)
     # We're the server so buffer incoming writes.
     return _bleio.CharacteristicBuffer(bound_characteristic,
                                        timeout=self._timeout,
                                        buffer_size=self._buffer_size)
예제 #3
0
    write_perm = _bleio.Attribute.OPEN
    return _bleio.Characteristic.add_to_service(
        service,
        uuid,
        initial_value = token,
        max_length = len(token),
        fixed_length = True,
        properties = properties,
        read_perm = read_perm,
        write_perm = write_perm
    )

# Bind our UUID to a characteristic, which is how we communicate with other
# devices using this particular GATT.
characteristic = bind_to_service(bt_service, bluetrace_uuid, get_random_token(160))
characteristic_buffer = _bleio.CharacteristicBuffer(characteristic, buffer_size=160)

loops = 0

def run_server(adapter, loops, characteristic_buffer):
    adapter.start_advertising(
        advertising_data,
        scan_response = scan_response,
        connectable = True,
        anonymous = True,
        timeout = advertising_timeout_s,
        interval = 0.1,
    )
    adapter_address = adapter.address
    print("Waiting for connection...")
    did_print_wc = False