Closed krisnaresi89 closed 1 year ago
It looks like the DBus call 'GetManagedObjects' is failing and therefore no adapters are found. No idea why it is failing. Try to put a breakpoint to inspect all parameters...
Thanks for the reply. I have modified binc_adapter_find_all
function like this:
GPtrArray *binc_adapters = g_ptr_array_new();
GError *error = NULL;
log_debug(TAG, "finding adapters");
GVariant *result = g_dbus_connection_call_sync(dbusConnection,
BLUEZ_DBUS,
"/",
INTERFACE_OBJECT_MANAGER,
"GetManagedObjects",
NULL,
G_VARIANT_TYPE("(a{oa{sa{sv}}})"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (error != NULL) {
log_error(TAG, "Error GetManagedObjects: %s", error->message);
g_error_free(error);
}
The debug log is as follow:
2022-04-28 17:43:12:989 DEBUG [Adapter] finding adapters
2022-04-28 17:43:12:992 ERROR [Adapter] Error GetManagedObjects: The connection is closed
2022-04-28 17:43:12:992 ERROR [Adapter] Unable to get result for GetManagedObjects
2022-04-28 17:43:12:992 DEBUG [Adapter] found 0 adapter
So there is something wrong with the DBus connection. I delete g_dbus_connection_close_sync(mDbusConnection, NULL, NULL);
line on close function and add g_dbus_connection_set_exit_on_close(mDbusConnection, FALSE);
line on init function, now I can see adapter being found, but the result is segmentation fault after set value to descriptor:
2022-04-28 17:43:15:241 DEBUG [Adapter] finding adapters
2022-04-28 17:43:15:248 DEBUG [Adapter] found 1 adapter
[D][52708] Adapter: /org/bluez/hci0 (ble-handler.cpp line 225)
2022-04-28 17:43:15:264 DEBUG [Advertisement] registering advertisement failed: An object is already exported for the interface org.bluez.LEAdvertisement1 at /org/bluez/bincadvertisement
2022-04-28 17:43:15:298 DEBUG [Application] successfully published application
2022-04-28 17:43:15:299 DEBUG [Application] successfully published local service 12345678-1234-5678-1234-56789abcdef0
2022-04-28 17:43:15:299 DEBUG [Application] success[ 52.778303] audit: type=1701 audit(1651167795.312:3): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=516 comm="main" exe="/usr/bin/main" sig=11 res=1
fully published local characteristic 12345678-1234-5678-1234-56789abcdef1
2022-04-28 17:43:15:299 DEBUG [Application] successfully published local characteristic 12345678-1234-5678-1234-56789abcdef2
2022-04-28 17:43:15:299 DEBUG [Application] successfully published local characteristic 12345678-1234-5678-1234-56789abcdef3
2022-04-28 17:43:15:300 DEBUG [Application] successfully published local descriptor 12345678-1234-5678-1234-56789abcdef4
2022-04-28 17:43:15:300 DEBUG [Application] set value <5050505050505050> to <12345678-1234-5678-1234-56789abcdef4>
Segmentation fault
Any ideas? Thanks.
What exactly does it crash on?
Just an update. Finally manage to resolve the problem. The problem is because when I call binc_adapter_stop_advertising
, my application didn't wait for binc_internal_stop_advertising_cb
callback, and already unregister and free everything at that point. Somehow this callback is re-called after re-init and make my application crash. So, I just need to add delay, and now everything works nicely.
To summarize everything:
g_dbus_connection_close_sync
on close function and add g_dbus_connection_set_exit_on_close
on init functionbinc_adapter_stop_advertising
. On my side, the delay is around 1 second, it could be lessen, but haven't tried it yet.Just wondering if there is any caveat on first point. Any thoughts are welcome.
Great that you resolved all issues! I need will think about making some calls like start/stop advertising synchronous instead if asynchronous. Or maybe support both.... Most Bluez operations must be asynchronous but maybe there can be some exceptions.
Regarding the first issue of closing the DBus connection, I wonder if closing it at all is necessary in your case. I think it would hardly affect battery consumption...
Anyway, thanks for the summary!
On Fri, 18 Aug 2023, 06:25 krisnaresi, @.***> wrote:
Just an update. Finally manage to resolve the problem. The problem is because when I call binc_adapter_stop_advertising, my application didn't wait for binc_internal_stop_advertising_cb callback, and already unregister and free everything at that point. Somehow this callback is re-called after re-init and make my application crash. So, I just need to add delay, and now everything works nicely.
To summarize everything:
- Need to remove g_dbus_connection_close_sync on close function and add g_dbus_connection_set_exit_on_close on init function
- Need to put delay after calling binc_adapter_stop_advertising. On my side, the delay is around 1 second, it could be lessen, but haven't tried it yet.
Just wondering if there is any caveat on first point. Any thoughts are welcome.
— Reply to this email directly, view it on GitHub https://github.com/weliem/bluez_inc/issues/10#issuecomment-1683335420, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACT7HZYCSDMZWARFOMD46MTXV3VDFANCNFSM6AAAAAA3POZD6E . You are receiving this because you commented.Message ID: @.***>
Thanks for the feedback. That's make sense, so I'll proceed with keep DBus connection opened the whole time.
Synchronous would be great in my opinion, as I don't really see the benefit of using asynchronous unless we have a very tight timing when closing. If you can implement both and documented it somewhere, then it would be great. For now, I'll close the issues. Thank you for your assistance.
Hi there,
Thank you for sharing this library. I have create GATT server based on peripheral example, and it works great. I can do write/read/notify using nRF Connect.
Now, one of my requirement is to have power saving feature. In order to do that, I have to close GATT server when receiving power saving signal and re-init GATT server again later on. Here is how I init the GATT server
Debug log:
Init function will create thread for
g_main_loop_run
to live on:The thread will live until
mRunning
is set false on close command:Debug log:
Now, after I call close, and re-init again after some times, somehow it cannot find adapter. Here is the debug log when I tried to re-init again:
Any idea or some kind of pointer is appreciated. Thank you for your time and assistance.