weliem / bluez_inc

A C library for Bluez (BLE) that hides all DBus communication. It doesn't get easier than this. This library can also be used in C++.
MIT License
84 stars 19 forks source link

cannot register new advertisement #8

Closed Sia1997 closed 1 year ago

Sia1997 commented 1 year ago

Hi, Thank you for your work on this library, it helps me a lot.

However, when I try to run peripheral so that I could establish a ble connection, I always got an error like "DEBUG [Adapter] failed to register advertisement (error 36: GDBus.Error:org.bluez.Error.NotPermitted: Maximum advertisements reached)" caused by binc_adapter_start_advertising. What may cause this error?

2023-05-08 10:34:34:484 DEBUG [Adapter] finding adapters 2023-05-08 10:34:34:492 DEBUG [Adapter] fuc:binc_adapter_find_all line:699 2023-05-08 10:34:34:495 DEBUG [Adapter] adapter->discoverable 1 2023-05-08 10:34:34:496 DEBUG [Adapter] found device /org/bluez/hci0/dev_F4_87_C5_72_C8_12 'HUAWEI MatePad' 2023-05-08 10:34:34:496 DEBUG [Adapter] found 1 adapter 2023-05-08 10:34:34:497 DEBUG [Main] using default_adapter '/org/bluez/hci0' Setup remote central connection state callback

2023-05-08 10:34:34:499 DEBUG [Application] successfully published application 2023-05-08 10:34:34:501 DEBUG [Application] successfully published local service 00001809-0000-1000-8000-00805f9b34fb 2023-05-08 10:34:34:502 DEBUG [Application] successfully published local characteristic 00002a1c-0000-1000-8000-00805f9b34fb 2023-05-08 10:34:34:503 DEBUG [Application] successfully published local descriptor 00002901-0000-1000-8000-00805f9b34fb 2023-05-08 10:34:34:503 DEBUG [Application] set value <68656c6c6f20746865726500> to <00002901-0000-1000-8000-00805f9b34fb>

2023-05-08 10:34:34:510 DEBUG [Adapter] failed to register advertisement (error 36: GDBus.Error:org.bluez.Error.NotPermitted: Maximum advertisements reached) 2023-05-08 10:34:34:515 DEBUG [Application] adding /org/bluez/bincapplication/service0 2023-05-08 10:34:34:515 DEBUG [Application] adding /org/bluez/bincapplication/service0/char0 2023-05-08 10:34:34:516 DEBUG [Application] adding /org/bluez/bincapplication/service0/char0/desc0 2023-05-08 10:34:34:525 DEBUG [Adapter] successfully registered application

Could you have a look over this?

Thanks!

weliem commented 1 year ago

I think this happens because the advertisements are not being unregistered. Registering and unregistering happens in start/stop advertising.

So for every time you call binc_adapter_start_advertising , you need to call binc_adapter_stop_advertising.

Sia1997 commented 1 year ago

Thank you for your reply!

I have tried the solution you mentioned, however when I call binc_adapter_stop_advertising, it says [Adapter] failed to unregister advertisement (error 36: GDBus.Error:org.bluez.Error.DoesNotExist: Does Not Exist).

could you provide any interface to obtain the existing advertisement?

weliem commented 1 year ago

It looks like you are calling 'stop_advertising' when you didn't do a 'start_advertising'. Nonetheless, this error is 'innocent' and you should not see your original problem anymore, right?

Sia1997 commented 1 year ago

After tracing the error, it turned out to be the problem of hard-ware. Thanks for your help!

weliem commented 1 year ago

Ok, thanks for letting us know