Tiny Core Linux

Tiny Core Extensions => TCE Talk => Topic started by: bukashka on September 04, 2016, 10:35:43 AM

Title: Bluetooth problem
Post by: bukashka on September 04, 2016, 10:35:43 AM
Hi all! I have problem with pairing with HC-06 BT module. In bluez.tcz info I have find this:
                Howto pair:
                $ echo "0000" | simple-agent hci0 00:1B:66:00:31:88 [0000 for a bt headset]
but when I try to run this script I have message:
ImportError: libgiropositary-1.0.so.1: cannot open shared object file: No such file or directory.
May be somebody knows what my problem is? Is there most simple way to pair with BT module and communicate through virtual serial port? Thanks for any help!
Title: Re: Bluetooth problem
Post by: Juanito on September 04, 2016, 09:29:38 PM
It looks like you need to load the gobject-introspection extension.

Note that you can also use the blueman gui.
Title: Re: Bluetooth problem
Post by: bukashka on September 04, 2016, 10:51:47 PM
After loading gobject-introspection extension I have new Import Error: /usr/local/lib/libgmodule-2.0.0.so.0: undefined symbol: g_rec_mutex_lock
pygobject was installed. Is any idea?
BTW, as I can see, blueman was removed from 5.x TCE. Now I use exactly 5.2 environment..
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 12:19:12 AM
Assuming you have dbus-python and pygobject (and their deps) loaded..

..and the dbus and bluetooth daemons started, it should work.

However, it would perhaps be easier to update to tc-7.2.
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 01:36:56 AM
Juanito, thanks a lot for your help. dbus is loaded, but when I try to start bluez (sudo /usr/local/etc/init.d/bluez start) I get the message:
no /usr/local/bin/dbus-daemon found; none killed
rm: can't remove '/var/run/dbus/pid': No such file or directory

Although /usr/local/bin/dbus-daemon exists.. What happens?

Update to 7.2 is last chance for me, but preferable stay on 5.2
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 01:44:09 AM
no /usr/local/bin/dbus-daemon found; none killed
rm: can't remove '/var/run/dbus/pid': No such file or directory

This usually happens the first time you start the bluetooth daemon - basically a (not very elegant) script tests if the dbus daemon is running and, if not (you get the error messages), starts it

You can check if both daemons are running using:
Code: [Select]
$ ps aux | grep dbus
$ ps aux | grep blue
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 02:39:20 AM
Both ps return result (as I understand I have dbus and blue processes loaded). Although sudo /usr/local/etc/init.d bluez status return "bluetoothd is not running."
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 03:03:04 AM
BTW, when I try to scan BT modules I get the right result. TCL enumerate all avialable BT devices. But pairing with simple-agent not success. Because I need to communicate with BT device through serial (rfcomm), Is there another way to pair?

after sudo rfcomm bind /dev/rfcomm0 11:22:33:44:55:66 device not connected.
after this technique on ubuntu system ask me for PIN code of my device. After I wrote right pin device connect. In TCL I have not request for PIN and my suggest is why I can't connect with BT device (HC-06 module).

Very appreciate for any suggestion!!
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 03:04:07 AM
I just tested on x86 tc-7.2:

Code: [Select]
$ tce-load -i bluez dbus-python pygobject

$ sudo /usr/local/etc/init.d/bluez start
no /usr/local/bin/dbus-daemon found; none killed
rm: can't remove '/var/run/dbus/pid': No such file or directory

$ sudo /usr/local/etc/init.d/bluez status
bluetoothd is running

$ hcitool scan [find address of bluetooth device]
Scanning ...
        00:1B:66:00:31:88       Sennheiser PXC310BT

[put headphones into pairing mode - flash blue and red to confirm pairing mode]
$ echo "0000" | simple-agent hci0 00:1B:66:00:31:88 [to pair]
Release
New device (/org/bluez/6362/hci0/dev_00_1B_66_00_31_88)
[headphones flash blue only to confirm paired]
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 03:12:07 AM
I'm not sure what version of bluez ubuntu uses, but there is a significant difference in the commands used with bluez-4 (x86 tc-7.2) and bluez-5 (x86_64 tc-7.2).

The example I used below works (with bluez-4) because the PIN for headphones is always "0000". Where the device has a different PIN that is generated when a pairing request is received, the command sequence is probably different.

You'll probably need some serious google foo to find the correct command sequence, so I'd recommend using the blueman gui if at all possible.

Of course if you like a challenge...
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 03:28:56 AM
see screenshot attached showing blueman being used to direct audio output to bluetooth headphones.

This and what you are trying to achieve would be really non-obvious without a gui  :(
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 03:31:55 AM
My device always have pin "1234" so this sequence is acceptable. But as I wrote, simple-agent hci0 cause Import Error.

BTW, Is it normal to have not running bluetoothd daemon and correct result of hcitool scan (in my example)?
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 03:38:39 AM
"hcitool scan" will not work if the bluetooth daemon is not running.

Note that it would be better to use "ps aux | grep blue" to test if the daemon is running or not.

I haven't got x86 tc-5.2 to test, but referring to the error "/usr/local/lib/libgmodule-2.0.0.so.0: undefined symbol: g_rec_mutex_lock", did you see it again or did loading all required extensions cure this?
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 03:49:05 AM
Would modifying this file help:
Code: [Select]
$ cat /usr/local/etc/bluetooth/rfcomm.conf
#
# RFCOMM configuration file.
#

#rfcomm0 {
#       # Automatically bind the device at startup
#       bind no;
#
#       # Bluetooth address of the device
#       device 11:22:33:44:55:66;
#
#       # RFCOMM channel for the connection
#       channel 1;
#
#       # Description of the connection
#       comment "Example Bluetooth device";
#}
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 04:13:30 AM
I still have Import Error even after install extension: dbus-python, pygobject and gobject-introspection

When I manually edit rfcomm.conf and after:
sudo rfcomm bind /dev/rfcomm0 hci0 11:22:33:44:55:66 1 (Indeed real mac)
sudo rfcomm connect /dev/rfcomm0 11:22:33:44:55:66 1
I get: Can't connect RFCOMM socket: Connection refused
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 04:38:23 AM
I guess you get the connection refused error because you've been unable to pair.

The import error would seem to be some kind of incompatibility between dbus-python/pygobject and glib2 in the tc-5.x repo.
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 05:13:22 AM
I just burnt an x86 tc-5.4 cd and booted from it.

I can pair with the same bluetooth headphones without any error.

Did you use "tce-load -w bluez dbus-python pygobject" orginially to ensure you got all of the deps (there are quite a few of them)?

(I ask this because you were missing gobject-introspection, which would have been downloaded by the command above)
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 06:00:10 AM
My tce dir contains all needed modules: dbus-python, pygobject, gobject-introspection, bluez and all its deps. My onboot.lst contains dbus-python, pygobject, gobject-introspection, bluez (in same order). Is there not the same as tce-load -w bluez dbus-python pygobject?

Juanito, are you using blueman or just bluez or there is no difference in 5.4?
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 06:28:08 AM
In tc-5.4  I only used bluez (blueman is not present in the tc 5.x repo).

Since I booted from a cd, I had to download the extensions from scratch and after using the following:
Code: [Select]
$ tce-load -w bluez dbus-python pygobject
$ tce-load -i bluez dbus-python pygobject

..to download and load the extensions I was able to pair without the error message you get.

As mentioned previously, the fact that you did not have gobject-introspection loaded might also mean that you do not have one of the other deps loaded since the two commands above load gobject-introspection automatically.

BTW, your onboot.lst does not need to contain gobject-introspection since it is a dep of pygobject
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 07:58:23 AM
Juanito, now I comment most extensions in onboot.lst and manually repeat 2 tce-load from your last example. Wheln I try to run "tce-load -i bluez dbus-python pygobject" I get the message: bluez.tcz not found! So I need "tce-load -w bluez" and only after that "tce-load -i bluez dbus-python pygobject" work fine. It seems strange for me.

BTW, is "sudo rfcomm bind /dev/rfcomm0 11:22:33:44:55:66" right command for pairing in TCL? When I do this on ubuntu and after start my app that open rfcomm0 serial port I can exchange with my device. When I repeat the same in TCL I can't. After continous pause I get:
Can't connect RFCOMM socket: Operation now in progress
Thank you for your patience!
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 09:52:02 AM
No, I don't think that is the correct command for pairing with bluez-4.x, but I don't know for sure - I suspect ubuntu uses bluez-5.x
Title: Re: Bluetooth problem
Post by: bukashka on September 05, 2016, 10:30:52 AM
I am sorry for stupid question) but what the difference between
"tce-load -w bluez dbus-python pygobject
tce-load -i bluez dbus-python pygobject"
and
"tce-load -wi bluez dbus-python pygobject"?

and also is there important the order in "tce-load -w bluez dbus-python pygobject"? Is it the same as "tce-load -w dbus-python pygobject bluez"?
Title: Re: Bluetooth problem
Post by: Misalf on September 05, 2016, 05:05:14 PM
The order of the extension names doesn't matter.
However,
if you do  tce-load -w ... , it will just download.
If you do  tce-load -i ... , it will just install (if already downloaded).
If you do  tce-load -iw ... , it will download + install, if NOT already downloaded but WON'T install if already downloaded.
The latter one is actually counter intuitive, in my opinion. As much as I would like, I wasn't able to provide a patch for this so far, neither do I know if this is intentional nor where it is actually controlled.
Title: Re: Bluetooth problem
Post by: Juanito on September 05, 2016, 09:58:05 PM
I use the tce-load command like that because I can never remember if it's -wi or -wil that adds the extension to onboot.lst.

Note also that, in general, the order of extensions in the tce-load command does not matter. This being said, there are a few extensions whose start-up script depends on commands present in other extensions.

Did you check if ubuntu uses bluez-5.x?
Title: Re: Bluetooth problem
Post by: Juanito on September 06, 2016, 01:17:23 AM
BTW, I went back to the TinyCore-5.4 cd and rebooted to check which extensions get loaded.

Here's the list:
Code: [Select]
$ tce-load -i bluez dbus-python pygobject
sbc.tcz: OK
bluetooth-3.8.13-tinycore.tcz: OK
udev-lib.tcz: OK
libusb.tcz: OK
libffi.tcz: OK
glib2.tcz: OK
expat2.tcz: OK
dbus.tcz: OK
dbus-glib.tcz: OK
bluez.tcz: OK
readline.tcz: OK
ncurses-common.tcz: OK
ncurses.tcz: OK
gdbm.tcz: OK
tcl.tcz: OK
libXss.tcz: OK
fontconfig.tcz: OK
libXft.tcz: OK
tk.tcz: OK
openssl-1.0.0.tcz: OK
bzip2-lib.tcz: OK
sqlite3.tcz: OK
python.tcz: OK
dbus-python.tcz: OK
libpciaccess.tcz: OK
libdrm.tcz: OK
libXxf86vm.tcz: OK
libXfixes.tcz: OK
libXdamage.tcz: OK
libGL.tcz: OK
pixman.tcz: OK
cairo.tcz: OK
pycairo.tcz: OK
gobject-introspection.tcz: OK
pygobject.tcz: OK

I might be good to double-check that you have all of those extensions loaded.
Title: Re: Bluetooth problem
Post by: bukashka on September 06, 2016, 03:44:25 AM
Thank you for comments about tce-load rules. Now it is clear for me)
Juanito, I use old ubuntu (10) so version of bluez is 4.60
Now I will try to check my output of "tce-load -i bluez dbus-python pygobject"
Title: Re: Bluetooth problem
Post by: bukashka on September 06, 2016, 06:08:55 AM
There is my output
Code: [Select]
sbc.tcz: OK
bluetooth-3.8.13-tinycore.tcz: OK
udev-lib.tcz: OK
libusb.tcz: OK
libffi.tcz: OK
glib2.tcz: OK
expat2.tcz: OK
dbus.tcz: OK
dbus-glib.tcz: OK
bluez.tcz: OK
readline.tcz: OK
ncurses-common.tcz: OK
ncurses.tcz: OK
gdbm.tcz: OK
tcl.tcz: OK
libXss.tcz: OK
/usr/share/fonts: caching, new cache contents: 1 fonts, 0 dirs
/usr/lib/X11/fonts: caching, new cache contents: 0 fonts, 2 dirs
/usr/lib/X11/fonts/75dpi: caching, new cache contents: 48 fonts, 0 dirs
/usr/lib/X11/fonts/misc: caching, new cache contents: 48 fonts, 0 dirs
/usr/local/share/fonts: skipping, no such directory
/usr/local/lib/X11/fonts: skipping, no such directory
/.local/share/fonts: skipping, no such directory
/usr/share/fonts: caching, new cache contents: 1 fonts, 0 dirs
/usr/lib/X11/fonts: caching, new cache contents: 0 fonts, 2 dirs
/usr/local/share/fonts: skipping, no such directory
/usr/local/lib/X11/fonts: skipping, no such directory
/.local/share/fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/.cache/fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded
fontconfig.tcz: OK
libXft.tcz: OK
tk.tcz: OK
openssl-1.0.0.tcz: OK
bzip2-lib.tcz: OK
sqlite3.tcz: OK
python.tcz: OK
dbus-python.tcz: OK
libpciaccess.tcz: OK
libdrm.tcz: OK
libXxf86vm.tcz: OK
libXfixes.tcz: OK
libXdamage.tcz: OK
libGL.tcz: OK
pixman.tcz: OK
cairo.tcz: OK
pycairo.tcz: OK
gobject-introspection.tcz: OK
pygobject.tcz: OK

It seems identical except messages about font cache
Title: Re: Bluetooth problem
Post by: Juanito on September 06, 2016, 06:30:18 AM
I deleted the font cache part  :)

I'm not sure what I can suggest to try next - I don't have a bluetooth serial device to test with, which limits my options.

If your device PIN is set to 1234 permanently, It's a little suprising that "echo "1234" | simple-agent hci0 11:22:33:44:55:66" doesn't work, but maybe this command only works with "dumb" devices like headphones.
Title: Re: Bluetooth problem
Post by: bukashka on September 06, 2016, 08:43:04 AM
Juanito, and what did you think about sequence for setup virtual serial port for BT? As I understand pairing (with simple-agent) is the first step in that, or not? And what the next step? If my ubuntu have bluez-4.6 and serial work with
"sudo rfcomm bind /dev/rfcomm0 11:22:33:44:55:66"
Is this step right for TCL too?
Title: Re: Bluetooth problem
Post by: Juanito on September 06, 2016, 10:29:02 AM
Taking the example of bluetooth headphones, first you have to pair and then set them as an audio sink - you cannot set them as sink without pairing first.

The above being said, I don't have any experience of bluetooth serial ports, so why not try what works on ubuntu and see what happens?
Title: Re: Bluetooth problem
Post by: bukashka on September 07, 2016, 05:58:03 AM
Now I find out a solution for Import Error. When I gzip my own core.gz I'd add some libraries (libgobject etc) needed for my app. As I understand, this libraries conflicts with pygobjects. Now I start my app in native core.gz and all is OK. bluetoothd is running and simple-agent work fine.

But, unfortunately, I still can't work with BT serial device. If compare with ubuntu where all work OK, I've noticed a difference.
In ubuntu after "sudo rfcomm bind /dev/rfcomm0 11:22:33:44:55:66" I get the PIN request. After input correct pin, I start my app and connect with my device. In TCL I haven't to get request for PIN. Instead of this I get message "Connection refused" after pause. Maybe somebody knows correct syntax for setup BT serial (rfcomm) with implicit PIN enter or name of missed extension for PIN request?
Title: Re: Bluetooth problem
Post by: Juanito on September 07, 2016, 06:24:41 AM
When you say "simple-agent work fine", do you mean that this works:
Code: [Select]
$ echo "1234" | simple-agent hci0 11:22:33:44:55:66
..if so, it means that you have sucessfully paired with your device...
Title: Re: Bluetooth problem
Post by: bukashka on September 07, 2016, 06:44:38 AM
Yes, this command finish succesfully. But, as I understand, it is only pairing. Because If I try to rfcomm next I get the message that device already in use and /dev/rfcomm0 not created. May be result of "simple-agent..." is virtual serial port with name not rfcomm0? BTW, If I run pairing command without "echo 1234" in beginning, I get PIN request and after I wrote right PIN command finish succesfully. What relationship between pairing and BT serial setup?
Title: Re: Bluetooth problem
Post by: Juanito on September 07, 2016, 07:05:26 AM
I don't know, but does "rfcomm -a" show anything after pairing?

Another option would be to check the various ubuntu bluetooth config files under /etc to look for clues.