Search code examples
pythonbluetoothraspberry-piice

Fail to build Bluetooth Connection with IceBT plugin from ZeroC's Ice


I am currently working at building an Ice Session between two Raspberry Pi 4Bs with Ice and Python. I already got the underlying connection / pairing via bluetooth working, but now I am struggling to connect the Ice server and client. The two devices are already connected, when I am trying to start the Ice service (it doesn't work when they aren't neither). The problem is, that the client always times out while trying to connect (after something like a minute or so). I am sure I have entered the right proxy-string, as when I change it up, I get a different error.

I am trying to replicate the printer example from ZeroC's website, only with bluetooth, so this would be the barebones of my code:

Server:

   adapter_name = "Printer"

    ice_init_data = Ice.InitializationData()
    ice_init_data.properties = Ice.createProperties()
    ice_init_data.properties.setProperty("Ice.Plugin.IceBT", "IceBT:createIceBT")
    ice_init_data.properties.setProperty(adapter_name + ".Endpoints", f"bt -u {CONST_UUID}")
   
    with Ice.initialize(ice_init_data) as communicator:

        adapter = communicator.createObjectAdapter(adapter_name)

        adapter_identity = communicator.stringToIdentity("Printer")
        adapter.add(PrinterI(), adapter_identity)
        adapter.activate()

        communicator.waitForShutdown()

Client:

ice_init_data = Ice.InitializationData()
ice_init_data.properties = Ice.createProperties()
ice_init_data.properties.setProperty("Ice.Plugin.IceBT", "IceBT:createIceBT") #activate BT

with Ice.initialize(sys.argv, ice_init_data) as communicator:
    base = communicator.stringToProxy(f"Printer:bt -a \"{device_address}\" -u {uuid}")
    printer = Demo.PrinterPrx.uncheckedCast(base)
    printer.printString("Hello World!")


If anyone could give me a hint as to what I am doing wrong I would really appreciate it :) ZeroC does have two examples of using IceBT, however looking at them did not reall help :/

Thank you for your help in advance :)

Severin


Solution

  • The problem was, as I was conducting the pairing programmatically too, I made an error there. I forgot to mark the newly paired device as trusted, which resulted in this timeout-error. Works now, when the client is a trusted device.