Exemplo n.º 1
0
 def peripheralManager_didReceiveReadRequest_(  # noqa: N802
         self, peripheral_manager: CBPeripheralManager,
         request: CBATTRequest):
     # This should probably be a callback to be handled by the user, to be
     # implemented or given to the BleakServer
     logger.debug(
         "Received read request from {} for characteristic {}".format(
             request.central().identifier().UUIDString(),
             request.characteristic().UUID().UUIDString()))
     request.setValue_(
         self.read_request_func(
             request.characteristic().UUID().UUIDString()))
     peripheral_manager.respondToRequest_withResult_(
         request, CBATTError.Success.value)
Exemplo n.º 2
0
    def peripheralManager_didReceiveWriteRequests_(  # noqa: N802
            self, peripheral_manager: CBPeripheralManager,
            requests: List[CBATTRequest]):
        # Again, this should likely be moved to a callback
        logger.debug("Receving write requests...")
        for request in requests:
            central: CBCentral = request.central()
            char: CBCharacteristic = request.characteristic()
            value: bytearray = request.value()
            logger.debug("Write request from {} to {} with value {}".format(
                central.identifier().UUIDString(),
                char.UUID().UUIDString(), value))
            self.write_request_func(char.UUID().UUIDString(), value)

        peripheral_manager.respondToRequest_withResult_(
            requests[0], CBATTError.Success.value)