spacecheese / bluez_peripheral

A library for building BLE peripherals using GATT and bluez
MIT License
38 stars 8 forks source link

dbus_next.errors.InvalidIntrospectionError #33

Closed AlanAlex-AR closed 8 months ago

AlanAlex-AR commented 1 year ago

Hi! I`m trying to run your sample HeartRateService from a Raspberrypi 4 Model B that uses UART as a primary bus for the bluetooth and got the same error as this link: https://github.com/spacecheese/bluez_peripheral/issues/11

Using the "hciconfig -a" commando it shows the following: hcio: Type: Primary Bus: UART BD Address: DC:A6:32:68 :FA: 17 ACL MTU: 1021:8 SCO MTC: 64:1 UP RUNNING PSCAN RX bytes:1681 acl:0 sco:0 events:113 errors:0 TX bytes:5071 acl:0 sco:0 commands: 113 errors:0 Features: 0xbf 0xfe 0xcf 0xfe 0Xdb 0xff 0x7b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH SNIFF Link mode: SLAVE ACCEPT Name: 'raspberrypi' Class: 0x7c0000 Service Classes: Rendering, Capturing, Object Transfer, Audio, Te Device Class: Miscellaneous, HCI Version: 5.0 (0x9) Revision: 0x17e LMP Version: 5,0 (0x9) Subversion: 0x6119 Manufacturer: Cypress Semiconductor (305)

spacecheese commented 1 year ago

Hello, Are you able to run? (you might also need sudo) dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hcio org.freedesktop.DBus.Introspectable.Introspect

This error looked pretty strange to me- the exception seems to suggest issue with either bluez or dbus_next since I don't control anything about the xml used in introspection as far as I'm aware.

AlanAlex-AR commented 1 year ago

Yes, I ran the following code:

sudo dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hcio org.freedesktop.DBus.Introspectable.Introspect

and got the following response:

method return time=1687548732.050432 sender=: 1.79 -> destination=: 1.89 serial=182 reply_serial=2
      string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> 
<node> 
</node>
"
spacecheese commented 1 year ago

This is very strange. I get the same output if I try this with an object path that doesn't exist (probably this exception could be more helpful) but I don't understand why the code would be trying to access this path if it doesn't exist. It seems a bit odd that your adapter is called hcio as I've only ever seen these be numbered.

Could you let me know what sudo dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.freedesktop.DBus.Introspectable.Introspect does? Alternatively if you have a desktop the d-feet package this has a pretty handy gui.

AlanAlex-AR commented 1 year ago

The sudo dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.freedesktop.DBus.Introspectable.Introspect shows the following results:

dbus [5570]: arguments to dbus_message_new_method_call() were incorrect, assertion " _dbus_check_is_valid_path (path)" failed in file ../../dbus/dbus-message.c line 1366.
This is normally a bug in some application using the D-Bus library.
    D-Bus not built with -rdynamic so unable to print a backtrace
Aborted
spacecheese commented 1 year ago

What dbus version (dbus-daemon --version) and bluez version (bluetoothd --version) are installed?

AlanAlex-AR commented 1 year ago

The dbus version is the D-Bus Message Bus Deamon 1.12.24 and the bluetoothd version is the 5.55

spacecheese commented 1 year ago

Thanks for all the information. I should have access to a Pi4 in a few weeks to look further into this.

spacecheese commented 12 months ago

I've not been able to reproduce this on my Pi4 running the latest Pi OS Lite. I assume there must be some setting that I need to change but this error is very strange so I'm not sure what this would be.

It's unlikely to be the cause but I was wondering if you had changed locale/ localization settings? The adapter appearing as hcio instead of hci0 seems very suspicious.

jcapona commented 8 months ago

hi @spacecheese ; I'm experiencing the same issue in a RPi 4, running RPi OS (bullseye); here's the output to the set of commands you requested:

$ hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: DC:A6:32:68:BC:34  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN
        RX bytes:1709 acl:0 sco:0 events:117 errors:0
        TX bytes:3509 acl:0 sco:0 commands:117 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'Further'
        Class: 0x6c0000
        Service Classes: Rendering, Capturing, Audio, Telephony
        Device Class: Miscellaneous,
        HCI Version: 5.0 (0x9)  Revision: 0x17e
        LMP Version: 5.0 (0x9)  Subversion: 0x6119
        Manufacturer: Cypress Semiconductor (305)
$ dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hcio org.freedesktop.DBus.Introspectable.Introspect
method return time=1699536643.538029 sender=:1.25 -> destination=:1.45 serial=114 reply_serial=2
   string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
</node>
"
$ sudo dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.freedesktop.DBus.Introspectable.Introspect
method return time=1699536656.799795 sender=:1.25 -> destination=:1.46 serial=115 reply_serial=2
   string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node><interface name="org.freedesktop.DBus.Introspectable"><method name="Introspect"><arg name="xml" type="s" direction="out"/>
</method></interface><interface name="org.bluez.AgentManager1"><method name="RegisterAgent"><arg name="agent" type="o" direction="in"/>
<arg name="capability" type="s" direction="in"/>
</method><method name="UnregisterAgent"><arg name="agent" type="o" direction="in"/>
</method><method name="RequestDefaultAgent"><arg name="agent" type="o" direction="in"/>
</method></interface><interface name="org.bluez.ProfileManager1"><method name="RegisterProfile"><arg name="profile" type="o" direction="in"/>
<arg name="UUID" type="s" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method><method name="UnregisterProfile"><arg name="profile" type="o" direction="in"/>
</method></interface><interface name="org.bluez.HealthManager1"><method name="CreateApplication"><arg name="config" type="a{sv}" direction="in"/>
<arg name="application" type="o" direction="out"/>
</method><method name="DestroyApplication"><arg name="application" type="o" direction="in"/>
</method></interface><node name="hci0"/><node name="test"/></node>"
$ dbus-daemon --version
D-Bus Message Bus Daemon 1.12.28
Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ bluetoothd --version
5.55
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

$ uname -a
Linux pi-top 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

any ideas?

jcapona commented 8 months ago

@spacecheese I created https://github.com/spacecheese/bluez_peripheral/pull/41 to handle this issue.

In my case, when running Adapter.get_all multiple nodes were available (hci0 and test for some reason) and the second one caused bus.introspect to fail. My solution handles the error and returns only valid adapters from the function, raising an error if none are found.

spacecheese commented 8 months ago

@spacecheese I created #41 to handle this issue.

In my case, when running Adapter.get_all multiple nodes were available (hci0 and test for some reason) and the second one caused bus.introspect to fail. My solution handles the error and returns only valid adapters from the function, raising an error if none are found.

Thanks for the fix. This is pretty strange, I'm guessing that running dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/test org.freedesktop.DBus.Introspectable.Introspect gives some kind of error? I think there must be at least one issue in bluez here. Do you know where the test adapter came from in your case?

jcapona commented 8 months ago

The command produces this output:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/test org.freedesktop.DBus.Introspectable.Introspect
method return time=1699543050.441955 sender=:1.73 -> destination=:1.72 serial=18 reply_serial=2
   string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node><interface name="org.freedesktop.DBus.Introspectable"><method name="Introspect"><arg name="xml" type="s" direction="out"/>
</method></interface><interface name="org.bluez.SimAccessTest1"><method name="OngoingCall"><arg name="ongoing" type="b" direction="in"/>
</method><method name="MaxMessageSize"><arg name="size" type="u" direction="in"/>
</method><method name="DisconnectImmediate"></method><method name="CardStatus"><arg name="status" type="" direction="in"/>
</method></interface></node>"

I'm not sure about the test adapter; I've been playing around with a few libraries so far to create a GATT server, so maybe a leftover?