Skip to content
Advertisement

How do i get the debug/return strings out of bluethootctl

How can i retrieve those two lines:

Changing discoverable off succeeded [CHG] Controller 64:6E:69:F4:9E:72 Discoverable: no

Basically grabbing the output or other possible error outputs and discarding the rest of the garbage

enter image description here

I’m attempting to do a fork of a very simple bluethooth dmenu bash script, and I am being somewhat successful at it, but since I’ve considered releasing it to the public, it has to have error handling and be a generally rounded script, etc…

What im trying to now do is when i echo “power off” | bluethothctl i want to get the messages it sends internally like: Changing discoverable off succeeded, org.bluez.something is blocked, etc…

I’ve tried while read -r debug, putting it to a $( ) and then debugging it with notify or echo but i always get either the outside garbage(like Agent registered, [IFROGZ] discoverable off, etc..)

Is there a way i can grab those delicious internal message’s bluetoothctl sends internally to a variable without boogaloo tactics(like outputting everything to a file and then reading it)

I think what i said above is the only thing you hopefully solve this question for me but just because previously i’ve been downvoted for not showing code here’s a part of it

JavaScript

whats weird is that i use the same tactic for getting the show elements but it doesnt work for those specific “debugging messages”

Advertisement

Answer

I am not sure that bluetoothctl was intended to be used in this way. BlueZ has a documented API that uses DBus bindings available for most languages at:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/

This can be done from the bash command line below:

JavaScript

This can also be done with language bindings. For example using pydbus in Python:

JavaScript

If you want to catch the changes then you need to connect into the event loop. For example:

JavaScript

Which gives the output:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement