weliem / blessed-bluez

BLE library using Java and Bluez
MIT License
76 stars 23 forks source link

Using blessed-bluez on Windows #22

Closed heckzer closed 1 year ago

heckzer commented 1 year ago

Hi all,

Thank you for sharing your library!

I would like to use it on Windows. If I have understood correctly then it should support running on Windows with the TCP stack(?)

Current master compiles well on Windows 11.02.2023, tested with openjdk 11.0.12 2021-07-20 and 17.0.6 2023-01-17.

When I execute the resulting jar, I get the exception shown below.

16:49:40.858 [main] INFO  BluetoothHandler - initializing BluetoothCentral
16:49:41.001 [main] TRACE org.freedesktop.dbus.MethodTuple - new MethodTuple(Ping, )
16:49:41.015 [main] TRACE org.freedesktop.dbus.Marshalling - Converted Java type: class java.lang.String to D-Bus Type: s
16:49:41.015 [main] TRACE org.freedesktop.dbus.MethodTuple - new MethodTuple(GetMachineId, )
16:49:41.017 [main] TRACE org.freedesktop.dbus.MethodTuple - new MethodTuple(Introspect, )
16:49:41.026 [main] TRACE o.f.dbus.connections.BusAddress - Parsing bus address: unix:path=/var/run/dbus/system_bus_socket
16:49:41.028 [main] TRACE o.f.dbus.connections.BusAddress - Transport type: UNIX
16:49:41.028 [main] TRACE o.f.dbus.connections.BusAddress - Transport options: {path=/var/run/dbus/system_bus_socket}
16:49:41.034 [main] DEBUG o.f.d.c.transports.TransportFactory - Connecting to UNIX: {path=/var/run/dbus/system_bus_socket}
Exception in thread "main" java.lang.UnsatisfiedLinkError: Procedure not found.

        at jnr.ffi.provider.jffi.AsmRuntime.newUnsatisifiedLinkError(AsmRuntime.java:48)
        at jnr.unixsocket.Native$LibC$jnr$ffi$0.socket(Unknown Source)
        at jnr.unixsocket.Native.socket(Native.java:92)
        at jnr.unixsocket.UnixSocketChannel.<init>(UnixSocketChannel.java:101)
        at jnr.unixsocket.UnixSocketChannel.open(UnixSocketChannel.java:65)
        at org.freedesktop.dbus.connections.transports.UnixSocketTransport.connect(UnixSocketTransport.java:58)
        at org.freedesktop.dbus.connections.transports.TransportFactory.createTransport(TransportFactory.java:44)
        at org.freedesktop.dbus.connections.AbstractConnection.<init>(AbstractConnection.java:149)
        at org.freedesktop.dbus.connections.impl.DBusConnection.<init>(DBusConnection.java:338)
        at org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:144)
        at org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:195)
        at org.freedesktop.dbus.connections.impl.DBusConnection.newConnection(DBusConnection.java:174)
        at com.welie.blessed.BluezAdapterProvider.<init>(BluezAdapterProvider.java:23)
        at com.welie.blessed.BluetoothCentralManager.<init>(BluetoothCentralManager.java:211)
        at testapp.BluetoothHandler.<init>(BluetoothHandler.java:252)
        at testapp.Main.main(Main.java:5)

It looks like ´System.getenv("DBUS_SYSTEM_BUS_ADDRESS")´ returns NULL, and unix-dbus is the fallback.

I have tried to set the system variable with tcp parameters (´tcp:host=localhost,bind=localhost,listen=1515,port=1515´).

This results in different code execution and indeed uses the TCP stack instead of unix dbus.

The exception is gone but the BLE client seems to be stuck in a loop, no further log messages.

What would you suggest?

heckzer commented 1 year ago

I have switched to Linux on ARM64. It works great, thank you👍

EzzPress commented 11 months ago

Hi, is this lib supports Windows?

weliem commented 11 months ago

I never tried but it would surprise me if it worked...