Closed sroebert closed 1 year ago
Hello, Unfortunatly I'm not going to be able to look into this thoroughly for a couple of days. In the mean time could you post your modified version of the characteristic decorator.
No worries, I'll be debugging a bit more, hopefully figuring it out by myself.
This is the code I am using, I'm passing a random UUID (e.g. 51E4D20E-23A1-409E-BCBE-16FDAECF4BD4).
async def main():
parser = argparse.ArgumentParser()
parser.add_argument("--uuid", type=UUID, required=True)
parser.add_argument("--data", type=base64.b64decode, required=True)
parser.add_argument("--duration", type=int, required=True)
args = parser.parse_args()
service_uuid: UUID = args.uuid
data: bytes = args.data
duration: int = args.duration
@characteristic(service_uuid.hex)
def read_characteristic(
service, options: CharacteristicReadOptions # pylint: disable=unused-argument
) -> bytes:
return data
bus = await bluez_peripheral_util.get_message_bus()
service = Service(uuid=service_uuid.hex)
service.add_characteristic(read_characteristic)
await service.register(bus=bus)
adapter = await bluez_peripheral_util.Adapter.get_first(bus)
advertisement = Advertisement(
localName="SecureIdSim",
serviceUUIDs=[service_uuid.hex],
appearance=0x0010,
timeout=duration,
)
await advertisement.register(bus, adapter)
await asyncio.sleep(duration)
await service.unregister()
bus.disconnect()
It works perfectly fine (I tested reading the characteristic), using @characteristic("2A37")
.
Ok, it does seem to work if I use an instance of BTUUID
directly, instead of using the UUID
hex
property.
There seems to be a bug in the init of characteristic, it has if uuid is str
, instead of if type(uuid) is str
. If fixed it in #13
I am trying to create a characteristic with a 128 bit UUID, instead of 16 bit. If I use
"2A37"
from your example everything works correctly. When I change the characteristic to use a 128 bit UUID instead, I get the following error:dbus_next.errors.DBusError: Failed to create entry in database
Am I doing something wrong and is this suppose to work with this library? I know it should be possible as I am already using the same characteristic UUID on an iPhone and Android app.