Page 1 of 2

pBluetooth 4.0 alpha 7

Posted: Tue Oct 20, 2020 4:29 pm
by mistfire

Previously I created pBluetooth 3.x which is a Bluetooth device management tool based from abandoned project by @fr33land which works on Bluez4 only. Although it works however it was a very messy code

Right now I tried to build a new pBluetooth forked from a project of russian puppy developer which seems to be implemented of PuppyRus. It is all bluez5 with few and consistent dependencies as well as improved paired device management and GUI.

UPDATE
This is an alpha release of pBluetooth. It is forked from Puppyrus PuppyBT
https://github.com/Pro-pra/PuppyBT

Dependencies:
* bluez 5.x
* bluez-tools
* obexfs
* obexd/bluez-obexd
* yad
* Xdialog
* dbus
* bluealsa/bluez-alsa or pulseaudio

bluealsa/bluez-alsa dependencies:
* sbc
* libbluetooth

What currently works
* Toggle bluetooth ON/OFF
* Scanning (works best if hcitool was installed)
* Set Discoverability
* Renaming bluetooth device
* Unpairing paired devices
* Pairing devices
* Send Files via bluetooth
* Receive Files via bluetooth
* Bluetooth audio (playback via PulseAudio and BlueAlsa)
* Remote control
* Tethering (Works but obtaining IP address not yet implemented)
* Using paired bluetooth device features

Not yet tested
* Bluetooth audio (with sound input)
* Serial
* Obexfs mounting

NOTICE:
* For best results, do the following (Applicable for puppies which build before November 11, 2020 which supports bluez5)
* Use pulseaudio if bluealsa or bluez-alsa is not available on respective repos
* When newly paired devices does not connect automatically. Go to PAIRED DEVICES, Select the paired device on the list then click CONNECT

Edit /etc/rc.d/rc.sysinit and add these line at the part before connecting to network and starting services

Code: Select all

dbus-daemon --system

Edit /etc/rc.d/rc.shutdown and add these line at the part after disconnecting to network and stopping services

Code: Select all

killall dbus-daemon

D-Bus handling on boot and shutdown is now merged on Woof-CE testing branch (Nov 11, 2020). Puppy builds from Nov 11, 2020 onwards are no need to modify the rc.sysinit and rc.shutdown script.


Re: pBluetooth 4.0 (under development)

Posted: Thu Oct 22, 2020 5:07 pm
by mistfire
I successfully reinvented the GUI of pBluetooth. Managing the paired devices is now on GUI unlike from previous pBluetooth. Accessing its device feature works.

However I'm having a problem with bluetooth scanning. It works best with hcitool however it seems depreciated on upstream in favor of bluetoothctl. So the pbluetooth can use also bluetoothctl but the detection is unreliable because it always appears the paired devices on scan results instead of detected Bluetooth devices upon scanning.

Also pairing a Bluetooth device as of now was still broken.

Re: pBluetooth 4.0 alpha

Posted: Fri Oct 23, 2020 11:29 am
by mistfire
pBluetooth 4.0 alpha was released

I need help to make pairing bluetooth device works using either bluetoothctl or dbus-send api

Re: pBluetooth 4.0 alpha

Posted: Sat Oct 24, 2020 1:01 pm
by mistfire
Pairing bluetooth is the one of the biggest problem in Bluez

Before bluez5 you must need bluetooth-agent or bt-agent in order to pair Bluetooth devices. Since bluez5 those commands are seems to be dropped in favor of Bluetoothctl which makes easier however there is a problem

I tried to install bluez5 on Lxpupsc. Bluetoothctl works however when pairing devices using bash there is something happened

when you use this code

Code: Select all

echo -e "agent on\nexit\n" | bluetoothctl
It shows this message

Code: Select all

No agent registered 
However when you goto bluetoothctl and type "agent on" it shows this message

Code: Select all

[bluetooth]#agent on
Agent registered

Re: pBluetooth 4.0 alpha

Posted: Sun Oct 25, 2020 3:44 am
by norgo
@mistfire
here my output
( Bluez 5.47 compiled from source slacko 700RC3 )
of course I can send you the package for comparison if you are interested in

Code: Select all

# echo -e "agent on\nquit" | bluetoothctl
[NEW] Controller 00:19:7E:FF:3C:E5 BlueZ 5.47 [default]
Agent registered
[bluetooth]# agent on
Agent is already registered
[bluetooth]# quit
Agent unregistered
[DEL] Controller 00:19:7E:FF:3C:E5 BlueZ 5.47 [default]
#

Code: Select all

# echo -e "agent off\nquit" | bluetoothctl
[NEW] Controller 00:19:7E:FF:3C:E5 BlueZ 5.47 [default]
Agent registered
[bluetooth]# agent off
[bluetooth]# quit
[DEL] Controller 00:19:7E:FF:3C:E5 BlueZ 5.47 [default]
#

Re: pBluetooth 4.0 alpha

Posted: Sun Oct 25, 2020 4:07 am
by mistfire
@norgo

Nice. Can you please try the pBluetooth and see if the device pairing works on slacko 700RC3?
I use Bluez 5.36 on LxPupSc

Re: pBluetooth 4.0 alpha

Posted: Sun Oct 25, 2020 9:12 am
by step
mistfire wrote: Sat Oct 24, 2020 1:01 pm Before bluez5 you must need bluetooth-agent or bt-agent in order to pair Bluetooth devices. Since bluez5 those commands are seems to be dropped in favor of Bluetoothctl
For your information, those commands still exist. In in Fatdog64 they're in the bluez-tools package, and pairing is performed with command bt-device. Bluez5 itself is at version 5.52.
Bluetoothctl works however when pairing devices using bash there is something happened

when you use this code

Code: Select all

echo -e "agent on\nexit\n" | bluetoothctl
It shows this message

Code: Select all

No agent registered 
However when you goto bluetoothctl and type "agent on" it shows this message

Code: Select all

[bluetooth]#agent on
Agent registered
I ran your script in Fatdog64. The script runs this command:

Code: Select all

echo -e 'discoverable on\npairable on\nagent NoInputNoOutput\ndefault-agent\npair xx:xx:xx:xx:xx:xx\nexit'| bluetoothctl
There is no pairing and the whole command runs through to the end immediately and fails. Instead if I run every single command interactively from the bluetoothctl shell, each command works and devices pair up (I added a connect command before the pair command). Note that connect and pair can take several seconds. Most importantly, when devices are pairing up, bluetoothctl prompts for the remote's PIN code.

Code: Select all

[bluetooth]# pair xx:xx:xx:xx:xx:xx
Attempting to pair with xx:xx:xx:xx:xx:xx
[CHG] Device xx:xx:xx:xx:xx:xx Connected: yes
Request PIN code
[agent] Enter PIN code: 
How is it possible for bluetoothctl to prompt for a PIN code when it runs in a pipeline? Does your script prompt for a PIN code?

Re: pBluetooth 4.0 alpha

Posted: Sun Oct 25, 2020 1:49 pm
by mistfire
@step thanks for observation. As of now I searching on how to pair bluetooth devices using bluetoothctl. Otherwise use the bluez api via dbus-send.
Also the bluetooth scanning using bluetoothctl was very unreliable, it always shows the pair devices even those devices was not present on the host range. hcitool method is better

Re: pBluetooth 4.0 alpha

Posted: Sun Oct 25, 2020 2:08 pm
by norgo
@mistfire

pairing via commandline works without problems
pairing using pbluetooth failed unfortunately

Re: pBluetooth 4.0 alpha

Posted: Sun Oct 25, 2020 3:13 pm
by mistfire
Thanks @norgo
I wonder if bluez api on dbus-send works for pairing bluetooth device?

Re: pBluetooth 4.0 alpha

Posted: Mon Oct 26, 2020 1:12 am
by norgo
@mistfire
Here an idea how to handle needed delays or interrupts of the command chain.
Bluetoothctl via bash is a little bit tricky indeed.

update

example applied in pbluetooth
PIN usage for device authentication (PIN 1234)

Code: Select all

--- old/pbluetooth	2020-10-26 12:33:32.000000000 +0100
+++ new/pbluetooth	2020-10-26 23:49:19.561033375 +0100
@@ -340,8 +340,21 @@
 		#dbus-send --system --type=method_call --dest=org.bluez /org/bluez/$HCI_DEV/dev_$(echo $BDA | tr ':' '_') org.bluez.Device1.Pair
 		
 		echo 'echo -e "discoverable on\npairable on\nagent NoInputNoOutput\ndefault-agent\npair '$BDA'\nexit"' > /root/bt-dbus
-		
-		echo -e "discoverable on\npairable on\nagent NoInputNoOutput\ndefault-agent\npair $BDA\nexit" | bluetoothctl
+
+		######	echo -e "discoverable on\npairable on\nagent NoInputNoOutput\ndefault-agent\npair $BDA\nexit" | bluetoothctl
+	
+	{	printf 'agent on\n\n'
+		printf 'power on\n\n'
+		sleep 0.2
+		printf 'pairable on\n\n'
+		printf 'discoverable on\n\n'
+		printf 'scan on\n\n'
+		sleep 5
+		printf '%s\n' "pair $BDA"
+		sleep 3
+		printf '1234\n\n'
+		sleep 10
+	}	| bluetoothctl
 		
 		#echo 'dbus-send --system --print-reply --dest=org.bluez /org/bluez/'$(pidof bluetoothd)'/hci0 org.bluez.Adapter.CreatePairedDevice string:"'$BDA'" objpath:/org/bluez/agent_1317 string:"NoInputNoOutput"' > /root/bt-dbus2
=> pairing successful

Re: pBluetooth 4.0 alpha

Posted: Tue Oct 27, 2020 11:43 am
by mistfire
@norgo

It finally works! Thanks!

I made some modifications from your code in order to pair without entering PIN

Code: Select all

		{	
			printf 'pairable on\n\n'
			printf 'discoverable on\n\n'
			printf 'agent off\n\n'
			sleep 1
			printf 'agent NoInputNoOutput\n\n'
			sleep 1
			printf 'default-agent\n\n'
			sleep 1
			printf 'scan on\n\n'
			sleep 3
			printf '%s\n' "pair $BDA"
			sleep 3
		}	| bluetoothctl 

Re: pBluetooth 4.0 alpha 2

Posted: Tue Oct 27, 2020 12:23 pm
by mistfire
pBluetooth 4.0 alpha 2 release

Changes:
* Pairing bluetooth devices is now working (thanks @norgo )
* Added rescan capability on bluetooth scanning
* Some tweaks and fixes

Download was on the first post of this thread

Re: pBluetooth 4.0 alpha 2

Posted: Tue Oct 27, 2020 8:37 pm
by Clarity
I noticed that your effort and BarryK's effort started around the same time. Barry's is on hold for couple days now as he is focused on internationalization changes.

Are these parallel efforts to the same goal?

The ease of understanding, at a glance, and the stable ease of use are our key factors no matter which tools completes. Wehn complete, Hoping one or the other(s) (including FD811's) reach Puppy GIT for WoofCE builds.

Nice community contributions, insights and efforts.

Re: pBluetooth 4.0 alpha 2

Posted: Wed Oct 28, 2020 12:19 am
by mistfire
@Clarity

Maybe, but my goal here was to easily manage Bluetooth devices with less disk space consumed. Blueman, Bluedevil, and Gnome-Bluetooth are bloated.

pBluetooth started from abandoned PuppyBT by @fr33land. It was based from Bluez 4, it was a messed, requires exotic Bluez tools and works on 32-bit only.

This new pBluetooth was rebuilt from PuppyRus implementation of PuppyBT. The dependencies for Bluetooth implementation is now easier to find, full GUI, and architecture independent

In the past, Puppy users are having difficult to make Bluetooth worked on Puppy. Maybe due to PPM itself at that time which lack of updating system caches unlike today's PPM which is capable of updating system caches upon add/removal of packages. Even SFS loading supports updating system caches

Re: pBluetooth 4.0 alpha 2

Posted: Fri Oct 30, 2020 12:27 am
by mistfire
Right now we need testers to test the pBluetooth features which was not yet tested. It was mentioned on the first post of this thread which features are needed to test.

Re: pBluetooth 4.0 alpha 2

Posted: Fri Oct 30, 2020 4:48 pm
by TerryH
A little success, just sent a file from laptop to phone using pbluetooth alpha 2. Attempts to send from phone to laptop failed. In bionicpup32 I am able to pair/unpair earphones and phone. Unfortunately attempts to connect are failing. Similar results in Fossapup64, can pair but not connect with earphones. Haven't attempted file transfer in fossapup64.

Re: pBluetooth 4.0 alpha 2

Posted: Fri Oct 30, 2020 11:59 pm
by mistfire
TerryH wrote: Fri Oct 30, 2020 4:48 pm A little success, just sent a file from laptop to phone using pbluetooth alpha 2. Attempts to send from phone to laptop failed. In bionicpup32 I am able to pair/unpair earphones and phone. Unfortunately attempts to connect are failing. Similar results in Fossapup64, can pair but not connect with earphones. Haven't attempted file transfer in fossapup64.
So it means sending file via Bluetooth works?

Regarding receiving files from phone. Did you install obexd? If yes, then click RECEIVE files on pBluetooth. And try receive files. The received files will be saved at /var/bluetooth--share

I think we need a new approach for connecting Bluetooth devices using Bluetoothctl. I wonder if @norgo 's method works

Re: pBluetooth 4.0 alpha 2

Posted: Sat Oct 31, 2020 1:33 am
by TerryH
mistfire wrote: Fri Oct 30, 2020 11:59 pm
So it means sending file via Bluetooth works?

Regarding receiving files from phone. Did you install obexd? If yes, then click RECEIVE files on pBluetooth. And try receive files. The received files will be saved at /var/bluetooth--share
I couldn't find just an obexd package, I could only find in bionicpup32 bluez-obexd....deb, which I installed, I'm not sure if that is what is required. I don't get RECEIVE files option displayed, I only see send files, which was successful.

Installed packages:
These packages including 2 dependencies were all I could find and install.
These packages including 2 dependencies were all I could find and install.
pbluetooth.png (22.07 KiB) Viewed 2461 times

Re: pBluetooth 4.0 alpha 2

Posted: Sat Oct 31, 2020 2:23 am
by BarryK
@step
I am also working on a bluetooth manager, and have recently gone through the same puzzlement and learning experience with bluetoothctl and "agent on".

Doing either of these fails:

Code: Select all

# echo "agent on" | bluetoothctl
# bluetoothctl agent on
Because bluetoothctl is the agent, must be running in interactive mode. If bluetoothctl quits, so does the agent.

I found a link that turned on the light for me:

https://www.kynetics.com/docs/2018/pair ... nts_bluez/

I decided to use 'bt-agent', from the 'bluez-tools' package. Just start it, then do not run "agent on" or "default-agent" for bluetoothctl. bluetoothctl can then be happily used in one-shot mode (not interactive), for example:

Code: Select all

# bluetoothctl  --timeout 40 scan on

Re: pBluetooth 4.0 alpha 2

Posted: Sat Oct 31, 2020 4:32 am
by mistfire
@TerryH
bluez-obexd is the name of obexd in Ubuntu, Debian, and Fedora. Thanks for testing sending files via bluetooth the list functionalities posted on the first post of this thread is now updated.

@BarryK
I use this @norgo's method to pair bluetooth devices

Code: Select all

		{	
			printf 'pairable on\n\n'
			printf 'discoverable on\n\n'
			printf 'agent off\n\n'
			sleep 1
			printf 'agent NoInputNoOutput\n\n'
			sleep 1
			printf 'default-agent\n\n'
			sleep 1
			printf 'scan on\n\n'
			sleep 3
			printf '%s\n' "pair [bluetooth mac address]"
			sleep 3
		}	| bluetoothctl 
I have some problems on bluetooth scanning using bluetoothctl. Upon parsing the results, it always includes paired devices instead of detected bluetooth devices which was present. As a result scanning on pBluetooth was currently relied on hcitool

Re: pBluetooth 4.0 alpha 2

Posted: Sat Oct 31, 2020 7:13 am
by BarryK
@mistfire
Fair enough, norgo is feeding in all required commands to pair into stdin, so bluetoothctl does not exit.

I am using bluetoothctl one-shot, that is, one command at a time, like:

# bluetoothctl discoverable on
# bluetoothctl trust <dev>
# bluetoothctl pair <dev>

...or whatever, that is just the principle of how doing it.

But that means I have to use an external agent. I have just been starting "bt-agent" in a terminal. Pairing my keyboard, bt-agent asks if want to pair, shows a pin number and I have to enter "yes" or "no". Then over on the keyboard have to enter the pin number then enter.

But I was wondering if that could be simplified. bt-agent has the "--capability" option, but at this stage I haven't got a clue what those choices do.

Re: pBluetooth 4.0 alpha 2

Posted: Sat Oct 31, 2020 8:25 am
by step
I didn't test this approach in this particular case but perhaps you could still do it with bluetoothctl alone by running one instance of "bluetoothctl agent on" in the background -- with it's input connected to a named pipe (mkfifo) and its output flowing to the controlling shell script input loop, which can write single bluetoothctl commands to the named piped and then read the agent's responses from the named pipe's output. This use of named pipes is quite common to make two processes talk to each other the way a human and a process "talk" to each other in a terminal. A big advantage is that the two processes are automatically synchronized by way of their I/O, and there is no need to scatter arbitrary "sleep"s between commands.

Re: pBluetooth 4.0 alpha 2

Posted: Sun Nov 01, 2020 12:44 am
by BarryK
@step
Yes, that is an interesting possibility.

I am beginning to wonder about bluez, my experience so far is that it is poorly coded. The daemon crashes, not just for me, but heaps of reports about that on the Internet. And if the daemon crashes, bluetoothctl hangs!

I ran "bluetoothctl info <dev>" and it just hung, which I found out was because the daemon had crashed. Using "--timeout" option for blutoothctl does not help.

However, "bt-device -i <dev>" from the bluex-tools package does not hang, it reports that the daemon is not running and exits.

So it looks like will use bt-device. Already using bt-agent.

Re: pBluetooth 4.0 alpha 2

Posted: Sun Nov 01, 2020 6:54 am
by step
@BarryK , indeed, the Fatdog64 help file focuses on bt-device, from bluez-tools, as the go-to choice. Fatdog doesn't have a BT GUI.

Re: pBluetooth 4.0 alpha 2

Posted: Sun Nov 08, 2020 6:17 am
by mistfire

On my latest experiment, I successfully connect and disconnect a bluetooth headset via pbluetooth. It performs automatically to me because pulseaudio was installed on my test system. I added pulseaudio handling on my pbluetooth to avoid conflict with bluez-alsa if pulseaudio was running.


Re: pBluetooth 4.0 alpha 2

Posted: Sun Nov 08, 2020 8:11 am
by mistfire

I noticed that puppy doesn't start dbus-daemon. Starting dbus-daemon will greatly help and most linux applications requires dbus.

I made a pull request on woof-ce which starts dbus on boot before connectiong to network and starting any services. Also stops dbus upon all services stopped and disconnected from network.


Re: pBluetooth 4.0 alpha 2

Posted: Sun Nov 08, 2020 8:25 am
by greengeek

Hi mistfire, I am using Tahr32 to try your pet from the first post and when i try to run pBluetooth it tells me that "Bluez was missing. Install bluez first" so i looked for bluez in the package manager and i can see the following choices:
.

bluez_choices_Tahr32.jpg
bluez_choices_Tahr32.jpg (35.28 KiB) Viewed 2524 times

.
Do you have a recommendation for which package i should install please?
cheers!

EDIT : Package manager demanded an update and the new choices were:
.

bluez_choices_Tahr32_2.png
bluez_choices_Tahr32_2.png (48.02 KiB) Viewed 2519 times

.
Maybe that changes the most appropriate choice?


Re: pBluetooth 4.0 alpha 2

Posted: Sun Nov 08, 2020 9:54 am
by mistfire

@greengeek
The Bluez was too old for pBluetooth 4.0
pBluetooth 4.0 requires Bluez 5.0 onwards

for older Bluez I suggest to use pBluetooth 3.x, get it from old puppy forum.

I suggest to install all bluez packages except libbluedevil and python bluez

Also you will need to edit /etc/rc.d/rc.sysinit and add these line at the part before connecting to network and starting services

Code: Select all

dbus-daemon --system

Re: pBluetooth 4.0 alpha 3

Posted: Sun Nov 08, 2020 3:13 pm
by mistfire

pBluetooth alpha 3 released

Changes:

  • Connecting bluetooth speaker and headphones now working
  • Added pulseaudio handling
  • Receiving files via bluetooth now works
  • Improved bt_remove script
  • Some bugfixes

Download was on the first post of this thread

NOTICE:
For best results, do the following (Applicable from present to older puppies that support bluez5)

Edit /etc/rc.d/rc.sysinit and add these line at the part before connecting to network and starting services

Code: Select all

dbus-daemon --system

Edit /etc/rc.d/rc.shutdown and add these line at the part after disconnecting to network and stopping services

Code: Select all

killall dbus-daemon

D-Bus handling on boot and shutdown is now on Woof-CE pull request. When it merged, there is no need to edit the sysinit and shutdown script for future puppies