Coder Social home page Coder Social logo

bluez-dbus's People

Contributors

hypfvieh avatar s5uishida avatar tincore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluez-dbus's Issues

GATT flags are returned as a String rather than an array of Strings

Currently the getFlags() method of BluetoothGattDescriptor and BluetoothGattCharacteristic returns a String. I would expect the translation from DBus API to Java in this case to be String[] given it returns an array of strings.


Is this a bug or does the end user need to do a contains() to determine which flags are present?

Small Example to expose and consume a service...

Hi
Thank you for this Library. I try to understand how it works but I'm struggling a bit since it has no examples and I'm not exactly an BT expert.
Can you please provide an example on how to expose an consume simple Service, for instance a Temp service? That would be great.
Thank you Markus

Can I write a descriptor to enable notification?

Now we use bluez-dbus on raspberry to communicate with smartlock. we have two types of smart locks.
Follow the same steps below, one type can receive the notification.but the other type cannot receive it all the time.

  1. deviceManager.registerPropertyHandler(new AbstractPropertiesChangedHandler() {
    // read notification
    }
  2. startDiscovery
  3. bluetoothDevice.connect
  4. bluetoothDevice.getGattServiceByUuid
  5. notifyCharacteristic = bluetoothGattService.getGattCharacteristicByUuid("");
    writeCharacteristic = bluetoothGattService.getGattCharacteristicByUuid("");
  6. // notifyCharacteristic.getGattDescriptorByUuid("..").writeValue(new byte[] {0x01, 0x00}, null); // handle 000c
    // writeValue: error occured. org.bluez.Error.NotPermitted
    notifyCharacteristic.startNotify()
  7. writeCharacteristic.writeValue(...)

However, there is no problem using gattool directly.

gatttool -b E6:F9:65:B9:0B:98 -t random -I --listen

connect
char-desc 0001
...
handle: 0x000c, uuid: 00002902-0000-1000-8000-00805f9b34fb
...
char-write-req 000c 0100
// char-write-req: there is no NotPermitted error, the write is successful, and you can receive the notification immediately

How can I write a descriptor to enable notification? Or, in addition to startnotify, what else do I have to do to get the notification?

Thanks.

setTyped

I think I found a little issue with setTyped in AbstractBluetoothObject
/**
* Helper to set a value on a DBus property.
*
* @param _field DBus property key
* @param _value value to set
*/
protected void setTyped(String _field, Object _value) {
try {
Properties remoteObject = dbusConnection.getRemoteObject("org.bluez", dbusPath, Properties.class);
// remoteObject.Set(Adapter1.class.getName(), _field, _value);
remoteObject.Set(getInterfaceClass().getName(), _field, _value);
} catch (DBusException _ex) {
logger.trace("Error while setting data for DBUS (Field: {}, Value: {}).", _field, _value, _ex);
}
}

I think the remotObject.Set should use the getInterfaceClass().getName()

Hope this helps
Cheers
Michel Vos

When running on jdk8 and Raspbian, failed load library.

Your library very helpful, thank you.

I will run the application on Raspberry Pi Zero W (Raspbian Jessei.)
The sample code compile is success . (Maven created runnable jar file.) But, When run the jar, An fatal error occurs on load native library.

My quation is "can the library running on below environment?".

  • Environment
    • JDK OpenJDK 8
    • OS Raspbian Jessie lite

reference my sample code

Fatal error

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (os_linux_zero.cpp:254), pid=1531, tid=3060204640
#  fatal error: caught unhandled signal 4
#
# JRE version: OpenJDK Runtime Environment (8.0_40-b04) (build 1.8.0_40-internal-b04)
# Java VM: OpenJDK Zero VM (25.40-b08 interpreted mode linux-arm )
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/pi/bluez-dbus-sample/target/hs_err_pid1531.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted

If you needs hs_err_pid.log, I upload that.

Best Regards.

Scan filter "RSSI" causing DBusExecutionException

I haven't tested this extensively but whenever I include an "RSSI" discovery filter in a Map and call DeviceManager.setScanFilter() or BluetoothAdapter.setDiscoveryFilter() I get a DBusExecutionException: org.freedesktop.dbus.exceptions.DBusExecutionException: Invalid arguments in method call

I have tried executing Adapter1.GetDiscoveryFilters() which return "RSSI" in the returned String[] so i'm not sure why this isn't working as expected...

If I exclude the "RSSI" filter everything works as expected with other filter types (UUID, Transport etc...).

Ability to remove property and signal handlers from the com.github.hypfvieh.bluetooth.DeviceManager

I have a case when the need for subscriptions for different properties comes and goes.

As a workaround, I can have a generic subscription, which will delegate to specific handlers, relieving one from the need to register handlers in the DeviceManager. But having only handlers with a lifecycle tied to the objects representing devices seems more natural.

As far as I can see, underlying org.freedesktop.dbus.connections.impl.DBusConnection already has corresponding methods.

Deserialization error when getting manufacturer data

First of all, thanks for this library, it's proving extremely helpful to the project I'm working on right now!

I've got a Kotlin app running in a Docker container (running some flavor of Debian) hosted in balenaOS (an IoT device Linux OS intended for running Docker containers), so there are some layers of complexity here. That said, I can start a LE scan and see devices/advertisements, but I'm getting a DBusExecutionException when trying to read manufacturer data from an advertisement:

org.freedesktop.dbus.exceptions.DBusExecutionException: Wrong return type (failed to de-serialize correct types: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.reflect.ParameterizedType )
        at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:169)
        at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:226)
        at com.sun.proxy.$Proxy22.Get(Unknown Source)
        at com.github.hypfvieh.bluetooth.wrapper.AbstractBluetoothObject.getTyped(AbstractBluetoothObject.java:92)
        at com.github.hypfvieh.bluetooth.wrapper.BluetoothDevice.getManufacturerData(BluetoothDevice.java:280)
        ...

Any idea what might be going on or where I can start to debug?

how to response to ATT `Handle Value Notification`

Hi,

Could you please show me how to response to Handle Value Notification in this library?

This was extracted in btmon log.

ACL Data RX: Handle 3 flags 0x02 dlen 9
ATT: Handle Value Notification (0x1b) len 4
Handle: 0x000f
Data: 01ab

Thanks

GATTService address wrong ?

Very interesting library, by far the best I have found so far, in term of code quality, dependency management, and clarity...

A little question though, I have a working gatttool command like this, running on a Raspberry Pi 4:

gatttool --device=C4:AC:05:42:73:A4 -t random --char-write-req -a 0x1f -n a001037F

... which set the brightness of a smart lamp to 100%. Note the "-a 0x1f", which corresponds to "char value handle" in gattool "characteristics"

handle: 0x001e, char properties: 0x28, char value handle: **0x001f**, uuid: **44092842-0567-11e6-b862-0002a5d5c51b**

I try to make the same using bluez-dbus in java. My implementation seems correct, but with dbus-monitor I can see the following logs :

method call time=1600276508.729104 sender=:1.184 -> destination=org.bluez serial=210 path=/org/bluez/hci0/dev_C4_AC_05_42_73_A4/service001d/**char001e**; interface=org.bluez.GattCharacteristic1; member=WriteValue
   array of bytes [
      0a 01 03 7f
   ]
   array [
   ]
method return time=1600276508.776261 sender=:1.5 -> destination=:1.184 serial=6589 reply_serial=210

It looks I have rather to use the value of "char value handle", in my case 0x001f.

Do you know if this is a bad usage of the library, an error on the device, or what ?

Here is a little excerpt of the code, if you need more you can look here: https://github.com/sebpiller/luke-roberts-lamp-f

            BluetoothDevice lampF = manager.getDevices(true)
                .stream()
                .filter(e -> Objects.equals(e.getAddress(), config.getMac()))
                .findFirst()
                .get();
....
        String uuid = config.getCustomControlService().getUuid();
        BluetoothGattService customControlService = Objects.requireNonNull(lampF.getGattServiceByUuid(uuid));
        LOG.info("found GATT custom control service {} at UUID {}", customControlService, uuid);
....
        String externalApiUuid = config.getCustomControlService().getUserExternalApiEndpoint().getUuid();
        externalApi = Objects.requireNonNull(customControlService.getGattCharacteristicByUuid(externalApiUuid));

...
private void sendCommandToExternalApi(LukeRoberts.LampF.Command command, Byte... parameters) {
    reconnectedIfNeeded();

    try {
        externalApi.writeValue(/*reversed*/ command.toByteArray(parameters), Collections.emptyMap());
    } catch (DBusException e) {
        throw new IllegalStateException("unable to change brightness: " + e, e);
    }
}

Thanks for your time !

Direct connection to the device by BT device address

Is there any way to create a direct connection to a device with known BD address, without the need to run the discovery? From what I can see, the only way right now to get a BluetoothDevice object is from the DeviceManager is by running the discovery. If I already know the addresses of devices I need to connect to, running the discovery first seems like a unnecessary step.

Pairing failes with DBusExecutionException: Authentication Canceled

I try to pair a device, but this fails with the following Exception. How can I pass authentication data or is this related to a problem with dbus?

org.freedesktop.dbus.exceptions.DBusExecutionException: Authentication Canceled
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.freedesktop.dbus.errors.Error.getException(Error.java:157)
at org.freedesktop.dbus.errors.Error.throwException(Error.java:187)
at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:164)
at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:228)
at com.sun.proxy.$Proxy61.Pair(Unknown Source)
at com.github.hypfvieh.bluetooth.wrapper.BluetoothDevice.pair(BluetoothDevice.java:507)

Is bluez-dbus compatible with 5.50 instead of BlueZ 5.48?

README.md says that it was tested with BlueZ 5.48, but compared to the documentation of the interface of BlueZ, the interface class of bluez-dbus seems to correspond to 5.50 instead of 5.48.

P.S.

In dbus-java, the plan to replace JNI independent jnr-unixsocket is great!

Question Mesh API support

Hi! Can anybody tell something about support Mesh API? How long it make or when it will be available? Thank's

New minor release with recent fixes

Would it be possible to publish a new minor release of the library incorporating the recent bug fixes? We have a couple of PRs open which are waiting on these fixes before being merged.

Apologies for bugging you on this and if it's not currently possible I fully understand.

Thanks.

Feature Request: LE Advertisement

Sorry if I'm a bother, I'm still getting my feet under me in this project.

Let's say I bring up the LEAdvertisingManager1, like so

LEAdvertisingManager1 advertisingManager = DbusHelper.getRemoteObject(dbusConnection, "/org/bluez", LEAdvertisingManager1.class);

Now, assuming I've created a subclass of LEAdvertisement1 and exported it into an unrelated DBus path,

advertisingManager.RegisterAdvertisement(adv, new HashMap<String, byte[]>());

seems to me like it'd be sufficient to hook everything up. Instead, I get
Exception in thread "main" org.freedesktop.dbus.exceptions.DBusExecutionException: Failed to construct D-Bus type: Exporting non-exportable type: class java.lang.Object

Seems like either the marshaller is acting up again, or I don't understand something fundamental about how this works. Either way, I'd like to move towards working advertisements if we can.

How to use this library for Bluetooth intermediate communication

How to use this library for Bluetooth intermediate communication

I have little contact with this area at ordinary times. I need this content in my recent work. I don't see any communication related code in the code. Could you please give me some advice? Thank you very much.

bluez-dbus with dbus-java 3.3.2

The last release of bluez-dbus (0.1.4) uses dbus-java with version 3.3.0. Is it possible to update the dbus-java to the 3.3.2 version? Are there any incompatibility?

Order of notifications is not always correct at high speed

Hi,

I have a weird issue I don't understand. I am working with a Pulse Oximeter and an Activity Tracker that stream data at high speed to my application. Most of the times the order of notifications is correct but sometimes the packets are in the wrong order. So it seems packets are not guaranteed to arrive in the order they were sent by the devices. This never happens on iOS or Android...

When I see this issue happening my propertyChanged handler gets called 2x in less than 1ms. If there is more than 1ms between the calls everything seems fine and the order is correct.

Any idea where the issue could be? Is it Bluez itself? Or de Java DBus library? Or any idea how to debug this?

Here is my code for handling notifications:

    private AbstractPropertiesChangedHandler characteristicUpdatesHandler = new AbstractPropertiesChangedHandler() {
        @Override
        public void handle(Properties.PropertiesChanged propertiesChanged) {
            // Check if it is for this device
            String deviceAddressString = deviceAddress.replace(":","_");
            if(!propertiesChanged.getPath().contains(deviceAddressString)) return;

            if (propertiesChanged.getInterfaceName().equals("org.bluez.GattCharacteristic1")) {
                String path = propertiesChanged.getPath();

                propertiesChanged.getPropertiesChanged().forEach((s, value) -> {
                    // See what the update is about
                    if (s.equalsIgnoreCase("Notifying")) {
                        boolean isNotifying = (Boolean) value.getValue();
                        hbDevice.onNotifySet(getCharacteristicFromPath(path), isNotifying );
                    } else if (s.equalsIgnoreCase("Value")) {
                        if (value.getType() instanceof DBusListType) {
                            if (value.getValue() instanceof byte[]) {
                                byte[] byteVal = (byte[]) value.getValue();
                                byte[] valueCopy = byteVal.clone();
                                HBCharacteristic hbCharacteristic = getCharacteristicFromPath(path);
                                hbCharacteristic.setValue(valueCopy);
                                hbDevice.onCharacteristicChanged(valueCopy, hbCharacteristic);
                            }
                        }
                    }
                });
            }
        }
    };

bluez-dbus works with dbus-java-parent-3.2.0?

Hello.

Recently I knew the release of dbus-java-parent-3.2.0, which replaced libmatthew with jnr-unixsocket. It's great!

By the way, may bluez-dbus work with it? I think that I should try it myself, but if you have already tried it, please let me know that it works or not.

Thank you very much for your efforts.

I can not get some of the GattServices and GattCharacteristics UUIDs well.

I am using it with Raspberry Pi 3B (Raspbian Buster Lite OS ver 2019-06-20).
This OS has BlueZ 5.50 as standard.

When I obtained GattServices and GattCharacteristics from TI SensorTag CC2650, I could not get the following UUIDs for battery level.

Service:        0000180f-0000-1000-8000-00805f9b34fb
Characteristic: 00002a19-0000-1000-8000-00805f9b34fb

The result of the following Java code is

	device.refreshGattServices();

	for (BluetoothGattService service : device.getGattServices()) {
		if (LOG.isDebugEnabled()) {
			LOG.debug("[{}] {} service - {}", device.getAdapter().getDeviceName(), device.getAddress(), service.getUuid());
		}
		service.refreshGattCharacteristics();
		for (BluetoothGattCharacteristic characteristic : service.getGattCharacteristics()) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("[{}] {} characteristic - {}", device.getAdapter().getDeviceName(), device.getAddress(), characteristic.getUuid());
			}
		}
	}

The output was as follows, and the UUIDs related to the battery level were not found.

[hci0] B0:B4:48:B9:92:86 service - 00001801-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 service - 0000180a-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a23-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a24-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a25-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a26-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a27-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a28-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a29-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a2a-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 00002a50-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 service - f000aa00-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa01-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa02-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa03-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000aa20-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa21-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa22-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa23-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000aa40-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa41-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa42-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa44-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000aa80-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa81-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa82-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa83-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000aa70-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa71-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa72-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa73-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - 0000ffe0-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 characteristic - 0000ffe1-0000-1000-8000-00805f9b34fb 
[hci0] B0:B4:48:B9:92:86 service - f000aa64-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa65-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000aa66-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000ac00-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ac01-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ac02-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ac03-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000ccc0-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ccc1-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ccc2-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ccc3-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 service - f000ffc0-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ffc1-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ffc2-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ffc3-0451-4000-b000-000000000000 
[hci0] B0:B4:48:B9:92:86 characteristic - f000ffc4-0451-4000-b000-000000000000 

On the other hand, using BlueZ's gatttool command, UUIDs related to the battery level were obtained, as shown by the arrow below.

root@raspberrypi:~# gatttool -b B0:B4:48:B9:92:86 -i hci0 -I 
[B0:B4:48:B9:92:86][LE]> connect
Attempting to connect to B0:B4:48:B9:92:86
Connection successful
[B0:B4:48:B9:92:86][LE]> primary
attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0008, end grp handle: 0x0008 uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0009, end grp handle: 0x001b uuid: 0000180a-0000-1000-8000-00805f9b34fb
attr handle: 0x001c, end grp handle: 0x0021 uuid: 0000180f-0000-1000-8000-00805f9b34fb <==
attr handle: 0x0022, end grp handle: 0x0029 uuid: f000aa00-0451-4000-b000-000000000000
attr handle: 0x002a, end grp handle: 0x0031 uuid: f000aa20-0451-4000-b000-000000000000
attr handle: 0x0032, end grp handle: 0x0039 uuid: f000aa40-0451-4000-b000-000000000000
attr handle: 0x003a, end grp handle: 0x0041 uuid: f000aa80-0451-4000-b000-000000000000
attr handle: 0x0042, end grp handle: 0x0049 uuid: f000aa70-0451-4000-b000-000000000000
attr handle: 0x004a, end grp handle: 0x004e uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
attr handle: 0x004f, end grp handle: 0x0053 uuid: f000aa64-0451-4000-b000-000000000000
attr handle: 0x0054, end grp handle: 0x005a uuid: f000ac00-0451-4000-b000-000000000000
attr handle: 0x005b, end grp handle: 0x0062 uuid: f000ccc0-0451-4000-b000-000000000000
attr handle: 0x0063, end grp handle: 0xffff uuid: f000ffc0-0451-4000-b000-000000000000
[B0:B4:48:B9:92:86][LE]> characteristics 
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, char properties: 0x02, char value handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb
handle: 0x000a, char properties: 0x02, char value handle: 0x000b, uuid: 00002a23-0000-1000-8000-00805f9b34fb
handle: 0x000c, char properties: 0x02, char value handle: 0x000d, uuid: 00002a24-0000-1000-8000-00805f9b34fb
handle: 0x000e, char properties: 0x02, char value handle: 0x000f, uuid: 00002a25-0000-1000-8000-00805f9b34fb
handle: 0x0010, char properties: 0x02, char value handle: 0x0011, uuid: 00002a26-0000-1000-8000-00805f9b34fb
handle: 0x0012, char properties: 0x02, char value handle: 0x0013, uuid: 00002a27-0000-1000-8000-00805f9b34fb
handle: 0x0014, char properties: 0x02, char value handle: 0x0015, uuid: 00002a28-0000-1000-8000-00805f9b34fb
handle: 0x0016, char properties: 0x02, char value handle: 0x0017, uuid: 00002a29-0000-1000-8000-00805f9b34fb
handle: 0x0018, char properties: 0x02, char value handle: 0x0019, uuid: 00002a2a-0000-1000-8000-00805f9b34fb
handle: 0x001a, char properties: 0x02, char value handle: 0x001b, uuid: 00002a50-0000-1000-8000-00805f9b34fb
handle: 0x001d, char properties: 0x12, char value handle: 0x001e, uuid: 00002a19-0000-1000-8000-00805f9b34fb <==
handle: 0x0023, char properties: 0x12, char value handle: 0x0024, uuid: f000aa01-0451-4000-b000-000000000000
handle: 0x0026, char properties: 0x0a, char value handle: 0x0027, uuid: f000aa02-0451-4000-b000-000000000000
handle: 0x0028, char properties: 0x0a, char value handle: 0x0029, uuid: f000aa03-0451-4000-b000-000000000000
handle: 0x002b, char properties: 0x12, char value handle: 0x002c, uuid: f000aa21-0451-4000-b000-000000000000
handle: 0x002e, char properties: 0x0a, char value handle: 0x002f, uuid: f000aa22-0451-4000-b000-000000000000
handle: 0x0030, char properties: 0x0a, char value handle: 0x0031, uuid: f000aa23-0451-4000-b000-000000000000
handle: 0x0033, char properties: 0x12, char value handle: 0x0034, uuid: f000aa41-0451-4000-b000-000000000000
handle: 0x0036, char properties: 0x0a, char value handle: 0x0037, uuid: f000aa42-0451-4000-b000-000000000000
handle: 0x0038, char properties: 0x0a, char value handle: 0x0039, uuid: f000aa44-0451-4000-b000-000000000000
handle: 0x003b, char properties: 0x12, char value handle: 0x003c, uuid: f000aa81-0451-4000-b000-000000000000
handle: 0x003e, char properties: 0x0a, char value handle: 0x003f, uuid: f000aa82-0451-4000-b000-000000000000
handle: 0x0040, char properties: 0x0a, char value handle: 0x0041, uuid: f000aa83-0451-4000-b000-000000000000
handle: 0x0043, char properties: 0x12, char value handle: 0x0044, uuid: f000aa71-0451-4000-b000-000000000000
handle: 0x0046, char properties: 0x0a, char value handle: 0x0047, uuid: f000aa72-0451-4000-b000-000000000000
handle: 0x0048, char properties: 0x0a, char value handle: 0x0049, uuid: f000aa73-0451-4000-b000-000000000000
handle: 0x004b, char properties: 0x10, char value handle: 0x004c, uuid: 0000ffe1-0000-1000-8000-00805f9b34fb
handle: 0x0050, char properties: 0x0a, char value handle: 0x0051, uuid: f000aa65-0451-4000-b000-000000000000
handle: 0x0052, char properties: 0x0a, char value handle: 0x0053, uuid: f000aa66-0451-4000-b000-000000000000
handle: 0x0055, char properties: 0x0a, char value handle: 0x0056, uuid: f000ac01-0451-4000-b000-000000000000
handle: 0x0057, char properties: 0x0a, char value handle: 0x0058, uuid: f000ac02-0451-4000-b000-000000000000
handle: 0x0059, char properties: 0x0a, char value handle: 0x005a, uuid: f000ac03-0451-4000-b000-000000000000
handle: 0x005c, char properties: 0x12, char value handle: 0x005d, uuid: f000ccc1-0451-4000-b000-000000000000
handle: 0x005f, char properties: 0x08, char value handle: 0x0060, uuid: f000ccc2-0451-4000-b000-000000000000
handle: 0x0061, char properties: 0x08, char value handle: 0x0062, uuid: f000ccc3-0451-4000-b000-000000000000
handle: 0x0064, char properties: 0x1c, char value handle: 0x0065, uuid: f000ffc1-0451-4000-b000-000000000000
handle: 0x0068, char properties: 0x1c, char value handle: 0x0069, uuid: f000ffc2-0451-4000-b000-000000000000
handle: 0x006c, char properties: 0x0c, char value handle: 0x006d, uuid: f000ffc3-0451-4000-b000-000000000000
handle: 0x006f, char properties: 0x12, char value handle: 0x0070, uuid: f000ffc4-0451-4000-b000-000000000000
[B0:B4:48:B9:92:86][LE]> 

If there is an error in the Java code using bluez-dbus, it would be very helpful for me if you could point it out.
Thank you very much.

Unable to get Metadata PropertiesChanged of org.mpris.MediaPlayer2.Player

I try to get Metadata PropertiesChanged data of firefox media player, I can see it's information in command output of dbus-monitor.

signal time=1679021922.354447 sender=:1.81 -> destination=(null destination) serial=605 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/mpris/MediaPlayer2/firefox"
               )
               dict entry(
                  string "xesam:title"
                  variant                      string "Romance"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string "La Voix Des Anges"
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string "Dominica"
                     ]
               )
            ]
      )
   ]
   array [
   ]


signal time=1679039076.133555 sender=:1.81 -> destination=(null destination) serial=720 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "PlaybackStatus"
         variant             string "Paused"
      )
   ]
   array [
   ]

But I can't get this Metadata information in dbus-java.

I added System.out.println (_s.getPropertiesChanged()); here in SimpleBluez.java, but I only see the PlaybackStatus information in the output when playing music in firefox, no Metadata information.

Environments

  • OS: Fedora 37 x86_64
  • dbus-java: 3.3.2
  • bluez-dbus: 0.1.4
  • (The following packages are all installed from fedora official repository)
  • JDK: 17.0.6.0.10
  • bluez: 5.66
  • Firefox: 110.0
  • dbus: 1.14.6

Pairing using PIN code?

Hi, great library, thanks for all the work you put in. I am using it now for my first BLE project on a Linux machine. The peripheral I am trying to connect with is a bloodpressure meter that requires PIN-based pairing.

I managed to discover the device and connect to it and discover the services. But now I need to deal with the PIN-pairing.

I understand I need to create an Agent1 object and register it as the default agent with the AgentManager1. But since the library doesn't have nice Java classes for Agent1 and AgentManager1 I trying to implement them myself. However, I am struggling to get it to work.

Here is what I did:

  1. Created a BluetoothAgent class
  2. In the BluetoothAgent class I call exportObject to create it on the Dbus. Call succeeds.
  3. Created a BluetoothAgentManager class
  4. Added a method to DeviceManager to get the default AgentManager. Call succeeds.
  5. I tried calling RegisterAgent and passing the BluetoothAgent.

However, registering the Agent fails. It says "RegisterAgent, method with signature 'os' does not exist".

Any tips on how to do it? If you want I can share my full code...

Create A BLE Server

Is there a way to create a BLE server on the raspberry pi with this plugin?

Possible Map marshalling/de-marshalling issue

Hello,

I'm running into an error while trying to setup advertisement and need help pinpointing if its an issue with my code, the bluez library, or dbus itself.

I have an Advertisment class that implements LEAdvertisement1 and Properties. My GetAll method is as follows

@Override
public Map<String, Variant<?>> GetAll(String interface_name) {
        props.put("Type", new Variant("peripheral"));
        props.put("LocalName", new Variant("FakeAd"));
        props.put("ServiceUUIDs", new Variant("9E110100-C035-45ED-B09C-20FA58217A2A".getBytes(Charset.forName("UTF-8"))));
        Map<UInt16, byte[]> manuData = new HashMap<>();
        manuData.put(new UInt16(0xffff), new byte[] {0x12, 0x34});
        props.put("ManufactureData", new Variant(manuData, new DBusMapType(UInt16.class, byte[].class)));
        return props;
}

When registering this advertisment through the advertisement manager it crashes with
org.freedesktop.dbus.exceptions.DBusExecutionException: Failed to parse advertisement

I also get the following from dbus monitor

ethod call time=1599335678.206813 sender=:1.30 -> destination=org.bluez serial=9 path=/org/bluez/hci0; interface=org.bluez.LEAdvertisingManager1; member=RegisterAdvertisement
   object path "/org/bluez/example/advertisement0"
   array [
   ]
method return time=1599335678.207889 sender=org.freedesktop.DBus -> destination=:1.9 serial=16 reply_serial=43
method return time=1599335678.208598 sender=org.freedesktop.DBus -> destination=:1.9 serial=17 reply_serial=44
   string ":1.30"
method return time=1599335678.208964 sender=org.freedesktop.DBus -> destination=:1.9 serial=18 reply_serial=45
method return time=1599335678.209662 sender=org.freedesktop.DBus -> destination=:1.9 serial=19 reply_serial=46
method return time=1599335678.210305 sender=org.freedesktop.DBus -> destination=:1.9 serial=20 reply_serial=47
method return time=1599335678.210693 sender=org.freedesktop.DBus -> destination=:1.9 serial=21 reply_serial=48
error time=1599335678.212123 sender=org.freedesktop.DBus -> destination=:1.9 error_name=org.freedesktop.DBus.Error.ServiceUnknown reply_serial=49
   string "The name :1.30 was not provided by any .service files"
error time=1599335678.226268 sender=:1.30 -> destination=:1.9 error_name=org.freedesktop.dbus.errors.UnknownMethod reply_serial=50
   string "The method `org.freedesktop.DBus.ObjectManager.GetManagedObjects' does not exist on this object."
method return time=1599335678.277540 sender=:1.30 -> destination=:1.9 serial=11 reply_serial=51
   array [
      dict entry(
         string "LocalName"
         variant             string "FakeAd"
      )
      dict entry(
         string "Type"
         variant             string "peripheral"
      )
      dict entry(
         string "ServiceUUIDs"
         variant             array [
               variant                   string "9E110100-C035-45ED-B09C-20FA58217A2A"
            ]
      )
      dict entry(
         string "ManufacturerData"
         variant             array [
               dict entry(
                  uint16 65535
                  array of bytes [
                     12 34
                  ]
               )
            ]
      )
   ]

So, eventhough its crashing saying there was trouble parsing, everything seems to read out find in dbus monitor. I tested this issue a little fruther by removing the different elements from the props map and re-running the program and everything worked fine when I took out the manufacturerData. It successfully advertised the rest of the values and I was able to see the advertisement from my mobile devices.

Looking back at the dict entry that was in dbus monitor for ManufacturerData, it has the Variant as an array type with my dictionary in it, but I added this element as a dictionary only, thus I would think this should actually just be a dictionary type.

Am I wrong in that assumption? if not, is this issue being caused by something I wrote wrong, or an issue in the bluez lib or an issue in Dbus?

get RSSI fail

bluetoothDevice.getRssi()
Method threw 'org.freedesktop.dbus.exceptions.DBusExecutionException' exception.

image

Great effort!

Hi @hypfvieh,

just noticed your project. I use tinyb library, it is cool but hard to modify and support. Some features are missing from it as well. I'm wondering if you are going to add notification support in bluez-dbus, e.g. characteristic notifications and some other (like tinyb does)?

Thanks,
Vlad

I want getDBusConnection() I/F in DeviceManager class.

It is useful to have getDBusConnection() I/F in the DeviceManager class.

    public DBusConnection getDBusConnection() {
    	return dbusConnection;
    }

I pass the reference of the DBusConnection instance acquired above to the first argument of DbusHelper.getRemoteObject() and use it. Specifically, I use it to obtain a reference of Device1 instance.

If there are other good ways, I would be glad if you could tell me.

P.S.

I am running a sample application on Apache Felix 6.0.3 (OSGi), but it didn't work if the bundle that loads the JNI shared library and the bundle that uses it are separated, so I use these bundles in one bundle.

  • dbus-java 3.0.2
  • java-utils 1.0.5

In addition, I expect that such correspondence will become unnecessary if it is changed to jnr-unixsocket from now on.

Bluetooth scanning can scan for devices that are turned off

I found that when Bluetooth scans, it will scan devices that have already been turned off. Have you ever encountered this problem before? This device was previously connected by me

com.github.hypfvieh.bluetooth.DeviceManager#scanForBluetoothDevices(java.lang.String, int)

File descriptors in method returns

Hi, I am not sure if this is a bug with the library or a mistake on my part.
I am implementing a bluetooth A2DP Sink.
A call to MediaTransport1#Acquire is made and the call is successful, however, the reply gives a null pointer exception because no file descriptors were obtained.
I can see through the dbus-monitor command that a file descriptor and two ints are returned (as should happen).

Please let me know if this is an error on my part or a bug, thank you

example code:


public static void main(String[] args) {
	// obtain device manager, register media endpoints etc. I am 100% certain this code is correct, but it can be provided if needed for reproduction
	// deviceManager#registerPropertyHandler(new MediaPropertiesChangedHandler());
}

private class MediaPropertiesChangedHandler extends AbstractPropertiesChangedHandler {

    @Override
    public void handle(PropertiesChanged properties) {
        String path = properties.getPath();
        String interfaceName = properties.getInterfaceName();
            
        if (path.equals(transportPath) && interfaceName.equals("org.bluez.MediaTransport1")) {
            String state = (String) propertiesChanged.get("State").getValue();
            if (state != null && state.equalsIgnoreCase("pending")) {
				onStartStreaming();
			}
		}
    }
}

public void onStartStreaming() {
	MediaTransport1 mediaTransport = DbusHelper.getRemoteObject(deviceManager#getDbusConnection(), transportPath, MediaTransport1.class);
	mediaTransport.Acquire(); // here an exception is thrown:
	// Exception in thread "DBus Worker Thread-1" java.lang.NullPointerException: Cannot invoke "java.util.List.get(int)" because "this.filedescriptors" is null
	// 	   at org.freedesktop.dbus.messages.Message.extractOne(Message.java:993)
	// 	   at org.freedesktop.dbus.messages.Message.extract(Message.java:1156)
	// 	   at org.freedesktop.dbus.messages.Message.extract(Message.java:1133)
	// 	   at org.freedesktop.dbus.messages.Message.getParameters(Message.java:1264)
	// 	   at org.freedesktop.dbus.DBusAsyncReply.checkReply(DBusAsyncReply.java:74)
	// 	   at org.freedesktop.dbus.DBusAsyncReply.hasReply(DBusAsyncReply.java:95)
	// 	   at onStartStreaming(line number corresponds to the Acquire call)
	// 	   at org.freedesktop.dbus.connections.AbstractConnection$3.run(AbstractConnection.java:911)
	// 	   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	// 	   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	// 	   at java.base/java.lang.Thread.run(Thread.java:832)

}`

How to scan the specified address device

I just want to scan the specified mac address device and get the service data.
I tried to modify the DiscoveryFilter class and add Pattern(String.class) , and modify the BluetoothAdapter and add supportedFilterOptions.put("Pattern", String.class);
I use it like this :

        Map<DiscoveryFilter, Object> filter = new HashMap<>();
        filter.put(DiscoveryFilter.Transport, DiscoveryTransport.LE);
        filter.put(DiscoveryFilter.Pattern, "58:2D:34:BE:3A:F1");

        ScanProcess scanProcess = new ScanProcess("hci0", new MyScanHandler(), filter);
        scanProcess.start();

but i get the below error :

Exception in thread "main" org.freedesktop.dbus.exceptions.DBusExecutionException: Invalid arguments in method call
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.freedesktop.dbus.errors.Error.getException(Error.java:157)
        at org.freedesktop.dbus.errors.Error.throwException(Error.java:187)
        at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:164)
        at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:228)
        at com.sun.proxy.$Proxy19.SetDiscoveryFilter(Unknown Source)
        at com.github.hypfvieh.bluetooth.wrapper.BluetoothAdapter.setDiscoveryFilter(BluetoothAdapter.java:364)
        at com.github.hypfvieh.bluetooth.DeviceManager.setScanFilter(DeviceManager.java:238)

is the dbus not supported Pattern or other reason ?

How to set bluetooth mtu

I want to set the mtu of Bluetooth and call the gattCharacteristic.AcquireWrite method, but an error is reported

code:
  Map<String, Variant<?>> ops = new HashMap<>();
  ops.put("mtu", new Variant<>(240));
  TwoTuple<FileDescriptor, UInt16> twoTuple = writeService.getRawGattCharacteristic().AcquireWrite(ops);

error:
java.lang.NullPointerException
	at org.freedesktop.dbus.messages.Message.extractOne(Message.java:982)
	at org.freedesktop.dbus.messages.Message.extract(Message.java:1145)
	at org.freedesktop.dbus.messages.Message.extract(Message.java:1122)
	at org.freedesktop.dbus.messages.Message.getParameters(Message.java:1253)
	at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:156)
	at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:216)
	at com.sun.proxy.$Proxy23.AcquireWrite(Unknown Source)
	at org.ScanMain.test(ScanMain.java:112)
	at org.ScanMain.main(ScanMain.java:41)

"could not load FFI provider jnr.ffi.provider.jffi.Provider" when using module-info.java

Hi,

first of all thank you for great lib.
It worked very well until I added module-info.java to my client code. Suddenly I got this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider
at [email protected]/jnr.ffi.provider.InvalidRuntime.newLoadError(InvalidRuntime.java:101)
at [email protected]/jnr.ffi.provider.InvalidRuntime.findType(InvalidRuntime.java:42)
at [email protected]/jnr.ffi.Struct$NumberField.(Struct.java:872)
at [email protected]/jnr.ffi.Struct$Unsigned16.(Struct.java:1240)
at [email protected]/jnr.unixsocket.SockAddrUnix$DefaultSockAddrUnix.(SockAddrUnix.java:209)
at [email protected]/jnr.unixsocket.SockAddrUnix.create(SockAddrUnix.java:174)
at [email protected]/jnr.unixsocket.UnixSocketAddress.(UnixSocketAddress.java:53)
at [email protected]/org.freedesktop.dbus.connections.transports.UnixSocketTransport.(UnixSocketTransport.java:32)
at [email protected]/org.freedesktop.dbus.connections.transports.TransportFactory.createTransport(TransportFactory.java:37)
at [email protected]/org.freedesktop.dbus.connections.AbstractConnection.(AbstractConnection.java:161)
at [email protected]/org.freedesktop.dbus.connections.impl.DBusConnection.(DBusConnection.java:334)
at [email protected]/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:149)
at [email protected]/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:169)
at [email protected]/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:219)
at [email protected]/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:184)
at [email protected]/com.github.hypfvieh.bluetooth.DeviceManager.createInstance(DeviceManager.java:74)
at ...
Caused by: java.lang.UnsatisfiedLinkError: could not get native definition for type POINTER, original error message follows: java.lang.UnsatisfiedLinkError: could not locate stub library in jar file. Tried [jni/x86_64-Linux/libjffi-1.2.so, /jni/x86_64-Linux/libjffi-1.2.so]
at [email protected]/com.kenai.jffi.internal.StubLoader.getStubLibraryStream(StubLoader.java:450)
at [email protected]/com.kenai.jffi.internal.StubLoader.loadFromJar(StubLoader.java:375)
at [email protected]/com.kenai.jffi.internal.StubLoader.load(StubLoader.java:278)
at [email protected]/com.kenai.jffi.internal.StubLoader.(StubLoader.java:487)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:427)
at [email protected]/com.kenai.jffi.Init.load(Init.java:68)
at [email protected]/com.kenai.jffi.Foreign$InstanceHolder.getInstanceHolder(Foreign.java:49)
at [email protected]/com.kenai.jffi.Foreign$InstanceHolder.(Foreign.java:45)
at [email protected]/com.kenai.jffi.Foreign.getInstance(Foreign.java:103)
at [email protected]/com.kenai.jffi.Type$Builtin.lookupTypeInfo(Type.java:242)
at [email protected]/com.kenai.jffi.Type$Builtin.getTypeInfo(Type.java:237)
at [email protected]/com.kenai.jffi.Type.resolveSize(Type.java:155)
at [email protected]/com.kenai.jffi.Type.size(Type.java:138)
at [email protected]/jnr.ffi.provider.jffi.NativeRuntime$TypeDelegate.size(NativeRuntime.java:178)
at [email protected]/jnr.ffi.provider.AbstractRuntime.(AbstractRuntime.java:48)
at [email protected]/jnr.ffi.provider.jffi.NativeRuntime.(NativeRuntime.java:57)
at [email protected]/jnr.ffi.provider.jffi.NativeRuntime.(NativeRuntime.java:41)
at [email protected]/jnr.ffi.provider.jffi.NativeRuntime$SingletonHolder.(NativeRuntime.java:53)
at [email protected]/jnr.ffi.provider.jffi.NativeRuntime.getInstance(NativeRuntime.java:49)
at [email protected]/jnr.ffi.provider.jffi.Provider.(Provider.java:29)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at [email protected]/jnr.ffi.provider.FFIProvider$SystemProviderSingletonHolder.getInstance(FFIProvider.java:68)
at [email protected]/jnr.ffi.provider.FFIProvider$SystemProviderSingletonHolder.(FFIProvider.java:57)
at [email protected]/jnr.ffi.provider.FFIProvider.getSystemProvider(FFIProvider.java:35)
at [email protected]/jnr.ffi.Runtime$SingletonHolder.(Runtime.java:82)
at [email protected]/jnr.ffi.Runtime.getSystemRuntime(Runtime.java:67)
at [email protected]/jnr.unixsocket.SockAddrUnix.(SockAddrUnix.java:46)
at [email protected]/jnr.unixsocket.SockAddrUnix$DefaultSockAddrUnix.(SockAddrUnix.java:208)
at [email protected]/jnr.unixsocket.SockAddrUnix.create(SockAddrUnix.java:174)
at [email protected]/jnr.unixsocket.UnixSocketAddress.(UnixSocketAddress.java:53)
at [email protected]/org.freedesktop.dbus.connections.transports.UnixSocketTransport.(UnixSocketTransport.java:32)
at ...

The method caused this error is :

DeviceManager.createInstance(false);

I tried to require everything related to this error in the module-info.java without success:

module org.example {
    requires dbus.java;
    requires dbus.java.nativefd;
    requires bluecove.linux.custom;
    requires bluez.dbus;
    requires jnr.ffi;
    requires jnr.x86asm;
    requires jnr.posix;
    requires jnr.enxio;
    requires jnr.unixsocket;
    requires jnr.constants;
    requires jnr.a64asm;
}

Thank you in advance.

How to pair a new device (phone) using bluez-dbus

Hi,

I am trying to put in place a java app that allows to pair and connect a smart phone to my linux computer. I have been able to scan, find the MAC address and, if already paired, connect. My troubles are with the pairing protocol.

When doing it using the terminal I have followed the following protocol:

hcitool scan  # to get the MAC address of your device
bluetoothctl
agent on
scan on  # wait for your device's address to show up here
scan off
trust MAC_ADDRESS
pair MAC_ADDRRESS
connect MAC_ADDRESS

which during pairing requires a confirmation. This confirmation is to check that pairing isdone between the corresponding devices, which share the same temporary code displayed on my phone. But when trying to pair the device using bluez-dbus, using this code, it fails:

                var deviceManager = DeviceManager.createInstance( false );
		var listDevices = deviceManager.getDevices();
		
		var phone = listDevices.stream().filter( d -> d.getName().equals( "Phone_Name" ) ).findFirst().orElse( null );
		if( phone == null ){
			System.out.println( "not found" );
		}else{
			System.out.println( "Pairing/Connecting ..." );
			if( !phone.isPaired() ) {
				phone.setTrusted( true );
				phone.pair();
			}
			phone.connect();
		}

		deviceManager.closeConnection();

Here I have no way to confirm that the device is receiving the correct pairing code.
Any clue?

Thanks

Adapter isDiscovering() behaviour

I am seeing some strange behaviour with the isDiscovering() call in BluetoothAdapter.

I am frequently getting the following error when calling stopDiscovery() despite the isDiscovering() function returning "true":

org.freedesktop.dbus.exceptions.DBusExecutionException: No discovery started

I guess this exception should also be caught in the BluetoothAdapter.stopDiscovery() function. I am also wondering whether initialising the internalDiscover variable to false would help this although I guess that assumption could lead to other problems...

Enforcing compile on unix is not necessary (works on windows)

Hi
Thanks for this project!

FYI: project compiles on windows, as there is compile time dependency on unix libraries.

More over, I just sucessfully connected to BLE device from windows by remote connection to dbus ;)

On linux (Raspberry Pi zero W in my case) just run as root:
socat TCP-LISTEN:5234,reuseaddr,fork UNIX-CLIENT:/var/run/dbus/system_bus_socket

And on windows you can use:
DeviceManager.createInstance("tcp:host=192.168.0.xxx,port=5234,family=ipv4");

DeviceManager.scanForBluetoothDevices replicates devices.

I'm not sure if this is desired behaviour, but calling scanForBluetoothDevices (or findBtDevicesByIntrospection directly) duplicates all the devices in the devices list.

Essentially, bluetoothDeviceByAdapterMac is never cleared.

Scan Response (Question)

Hello,

Thanks for the wonderful library. I've been using it to setup a PI as a peripheral and its working great.

I'm curious if your library (or Bluez in general) exposes any api's to add a scan response to advertisements. I would like to mimic an advertisement payload that exceeds the default 31 byte advertisement limits and the bluetooth spec allows this through a scan response.

I found the following references a good intro to Scan Responses
https://www.novelbits.io/bluetooth-low-energy-advertisements-part-1/
https://www.novelbits.io/bluetooth-low-energy-advertisements-part-2/

Package com.github.hypfvieh.system is missing

When I tried to compile bluez-dbus-master I was unable to since

package com.github.hypfvieh.system does not exist

import com.github.hypfvieh.system.NativeLibraryLoader;

bluez-dbus-master\src\main\java\com\github\hypfvieh\bluetooth\DeviceManager.java:[22,33] error: package com.github.hypfvieh.system does not exist

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.