Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 14 Oct 2019, 05:12
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Bluetooth: simple utility with Yad gui
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Fri 11 Jan 2019, 00:00    Post subject:  Bluetooth: simple utility with Yad gui
Subject description: connect bt devices
 

Here is a working yad gui bluetooth scanning and connection utility.
Connects audio device using hcitool and bt-device/bt-audio/bt-obex/bt-network etc. Connects and Disconnects, shows added devices and current connection.

First scan then press one of the buttons for the desired connection type. Then select by highlighting the mac address of the device to be used, drag the mac to the dnd pane at the lower half of the gui, and wait for the results in the same gui.

This is my first use of hcitool and bluez in bash/cli ... any pointers welcomed.

Work in progress.
Code:
#!/bin/sh
# simple bluetooth connection gui tool
# by stemsee copyright @ 2019 Marcos M Contant
#
[[ "`whoami`" != "root" ]] && exec sudo -E -S ${0} "$\""
export OUTPUT_CHARSET=UTF-8
running=`ps -e | grep bt.sh | wc -l`
[[ "$running" -gt 2 ]] && exit #check if running, one instance only
export camino=$HOME/.wifi-connect
export track=/tmp/Wifi-TrayNet
export pics=/usr/share/pixmaps
[[ ! -d /tmp/Wifi-TrayNet ]] && mkdir /tmp/Wifi-TrayNet
function sayonara {     #MochiMoppel/stemsee geometry recorder
[[ ! -f "$track"/geom ]] && exit
   yad --text="$WINDOWTITLE: WT Geometry-Recorder" --window-icon="$pics/wireless.png" \
   --geometry=200x10+100-100 --no-focus --no-buttons --undecorated \
   --on-top --form --skip-taskbar --field="MoreTime:FBTN" "bash -c sayonara" \
   --timeout-indicator=top --timeout=6
   nought=`xwininfo -stats -name "$WINDOWTITLE" | grep "$WINDOWTITLE"`
   XWININFO=`xwininfo -stats -name "$WINDOWTITLE"`
   if [[ ! -z "$nought" ]]; then
      ARRAY=(${XWININFO#* X: })
      AX=${ARRAY[0]}
      AY=${ARRAY[4]}
      RX=${ARRAY[8]}
      RY=${ARRAY[12]}
      W=${ARRAY[14]}
      H=${ARRAY[16]}
      X=$((AX-RX))
      Y=$((AY-RY))
      echo "$W"x"$H"+"$X"+"$Y" > $camino/geometry/$WINDOWTITLE
   else
      exit
   fi
}; export -f sayonara
function btscanfn (){
   timeout 14 hcitool scan | grep -v 'Scanning' | tr '\t' ' ' >/tmp/Wifi-TrayNet/btresults &
function flash (){
   echo -e '\f'
   sleep 0.4
   echo "Please Wait ... !"
   sleep 0.4
}; export -f flash
for i in `seq 1 1 13`
do
   bash -c   flash
done
   cat /tmp/Wifi-TrayNet/btresults
}; export -f btscanfn

function btcon (){
bash -c btset
echo "DnD mac to connect"
cat /tmp/Wifi-TrayNet/btresults
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
listed=`bt-device -l | grep $line`
if [[ -z "$listed" ]]; then
   bt-device -c $line
else
   hcitool lecc $line
fi
bt-audio -c $line
bash -c blank
done
}; export -f btcon

function btobex (){
kill $btpid >/dev/null
bash -c btset
kill $obxpid
echo "DnD mac for btobex"
sleep 1
cat /tmp/Wifi-TrayNet/btresults
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
bt-obex -s &
export obxpid=$!
echo -e "#
# RFCOMM configuration file.
#

rfcomm4 {
#   # Automatically bind the device at startup
   bind yes;
#
#   # Bluetooth address of the device
   device $line;
#
#   # RFCOMM channel for the connection
   channel   4;
#
#   # Description of the connection
   comment \"Bluetooth rfcomm4 $line\";
}
" > /etc/bluetooth/rfcomm.conf
yes | bt-obex -s /root/Downloads &
export btpid=$!
listed=`bt-device -l | grep $line`
if [[ -z "$listed" ]]; then
    bt-device -c $line --set Trusted
    rfcomm connect rfcomm4 4
    bt-obex -f $line &
    wait $!
else
   hcitool lecc $line
   rfcomm connect rfcomm4 4
   bt-obex -f $line &
   wait $!
fi
bash -c blank
done &
export btobexpid=$!
}; export -f btobex

function btnet (){
bash -c btset
echo "DnD mac for network"
sleep 1
cat /tmp/Wifi-TrayNet/btresults
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
listed=`bt-device -l | grep $line`
if [[ -z "$listed" ]]; then
   bt-device -c $line
   sleep 2
   bt-network -c $line
   bt-network -f $line
   bt-network -s $line
else
   echo "yes" | hcitool lecc $line
   sleep 2
   bt-network -c $line
   bt-network -s $line
   bt-network -f $line
fi
sleep 3
bash -c blank
done
}; export -f btnet

function btdisconfn (){
bash -c btset
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
   bt-device -d $line
   hcitool ledc $line
   hcitool dc $line
   sleep 3
   bash -c blank
done
}; export -f btdisconfn

function rmdev (){
bash -c btset
echo "Drag'n'Drop mac of device to remove"
bt-device -l
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do   
   bt-device -r $line
   sleep 3
   bash -c blank
done
}; export -f rmdev

function macrx (){
echo "macrx"
tail -fn0 /tmp/Wifi-TrayNet/hciselect | while read line
do
   dupe=`echo "$line" | grep -ixE '([0-9A-Z:]*)'`
   if [[ ! -z "$dupe" ]]; then
      echo "$line" > /tmp/Wifi-TrayNet/btmac
   else
      echo "$line" > /tmp/Wifi-TrayNet/btcmd
   fi
done &
export macrxpid=$!
}; export -f macrx

function combt (){
bash -c btset
tail -fn0 /tmp/Wifi-TrayNet/btfn | while read line
do
echo -e '\f'
case $line in
   btcon) cat /tmp/Wifi-TrayNet/btresults;;
   input|btnet|btobex|btsend|btdiscon) hcitool con;;
   rmdev) bt-device -l;;
esac
[[ ! -z "$line" ]] && bash -c "$line" &>/tmp/Wifi-TrayNet/btpipe &
export funcpid=$!
done &
export combtpid=$!
}; export -f combt
function btftp (){
bash -c btset
sleep 2
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
   bt-obex -f "$line" &
   wait $!
done
}; export -f btftp
function btserial (){
bash -c btset
sleep 2
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
echo -e "#
# RFCOMM configuration file.
#

rfcomm4 {
#   # Automatically bind the device at startup
   bind yes;
#
#   # Bluetooth address of the device
   device $line;
#
#   # RFCOMM channel for the connection
   channel   4;
#
#   # Description of the connection
   comment \"Bluetooth rfcomm4 $line\";
}
" > /etc/bluetooth/rfcomm.conf
rfcomm connect rfcomm4 4
bt-obex -f $line &
wait $!
bash -c blank
done
}; export -f btftp

function btsend (){
bash -c btset
sleep 1
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do   
bt-obex -s &
export obxpid=$!
echo -e "#
# RFCOMM configuration file.
#

rfcomm4 {
#   # Automatically bind the device at startup
   bind yes;
#
#   # Bluetooth address of the device
   device $line;
#
#   # RFCOMM channel for the connection
   channel   4;
#
#   # Description of the connection
   comment \"Bluetooth rfcomm4 $line\";
}
" > /etc/bluetooth/rfcomm.conf
   this=`yad --file`
   [[ -z "$this" ]] && exit
rfcomm connect rfcomm4 4
yes | bt-obex -p "$line" "$this" &
wait $!
   sleep 1
   bash -c blank
done
}; export -f btsend
function btget (){
echo "ftp search"
sdptool search FTP
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do
echo -e "#
# RFCOMM configuration file.
#

rfcomm4 {
#   # Automatically bind the device at startup
   bind yes;
#
#   # Bluetooth address of the device
   device $line;
#
#   # RFCOMM channel for the connection
   channel   4;
#
#   # Description of the connection
   comment \"Bluetooth rfcomm4 $line\";
}
" > /etc/bluetooth/rfcomm.conf
rfcomm connect rfcomm4 4
rfcomm listen 4
obexfs -b$line
cd /
ls /
done
}; export -f btget
function btset (){
   echo -e '\f'
   hcitool con >/tmp/Wifi-TrayNet/btpipe
   kill $funcpid >/dev/null
}; export -f btset

function funclist (){
export tap=/tmp/Wifi-TrayNet/selecthci
echo "bash -c blank"
echo "bash -c btcon"
echo "bash -c btdisconfn"
echo "bash -c btnet"
echo "bash -c btobex"
echo "bash -c btscanfn"
echo "bash -c btsend"
echo "bash -c btrmdev"
echo "bash -c btget"
echo "bash -c btftp"
echo "bash -c command"
echo "What have you?"
tail -fn0 /tmp/Wifi-TrayNet/selecthci | while read line
do
      if [[ -z "$line" ]]; then
         echo "nope"
         bash -c command
      else
         bash -c blank
         exec $line
      fi
export tap=/tmp/Wifi-TrayNet/hciselect
done
}; export -f funclist

function command (){
export tap=/dev/null
echo -e '\f'
echo "bash -c funclist"
echo "rfkill block bluetooth"
echo "rfkill unblock bluetooth"
echo "hcitool lewladd"
echo "bt-device -l"
echo "rfcomm connect rfcomm4 4"
echo "bash -c btsend"
echo "geany /usr/sbin/Wifi-TrayNet"
echo "ls /root/.wifi-connect/profiles"
echo "cat /tmp/Wifi-TrayNet/btresults"
echo "google-chrome-stable --no-sandbox www.google.com"
echo "seamonkey http://www.murga-linux.com/puppy/"
#line=$(yad --geometry=100x100+100+100 --on-top --text="Command D'n'D" --undecorated --skip-taskbar --dnd)
tail -fn0 /tmp/Wifi-TrayNet/selecthci | while read line
do
      if [[ -z "$line" ]]; then
         echo "nope"
         bash -c command
      else
         bash -c blank
         exec $line
      fi
export tap=/tmp/Wifi-TrayNet/hciselect
done
}; export -f command

function blank (){
   echo -e '\f' >/tmp/Wifi-TrayNet/btpipe
}; export -f blank

function bluetooth (){
kill $btpid &>/dev/null
kill $combtpid &>/dev/null
kill $macrxpid &>/dev/null
export tap=/tmp/Wifi-TrayNet/hciselect
export pat=/tmp/Wifi-TrayNet/selecthci
[[ ! -f /tmp/Wifi-TrayNet/btpipe ]] && mkfifo -m 755 /tmp/Wifi-TrayNet/btpipe
exec 2<> /tmp/Wifi-TrayNet/btpipe
[[ ! -f /tmp/Wifi-TrayNet/hciselect ]] && touch /tmp/Wifi-TrayNet/hciselect
[[ ! -f /tmp/Wifi-TrayNet/selecthci ]] && touch /tmp/Wifi-TrayNet/selecthci
[[ ! -f /tmp/Wifi-TrayNet/btfn ]] && touch /tmp/Wifi-TrayNet/btfn
[[ ! -f /tmp/Wifi-TrayNet/btmac ]] && touch /tmp/Wifi-TrayNet/btmac

WINDOWTITLE="Bluetooth"
export WINDOWTITLE
bash -c sayonara &
yad --listen --plug=$$ --tabnum=1 --item-separator=" " --form --cycle-read --columns=2 --field=A --field=0 --field=1 --field=2 --field=3 --field=4 --field=5 --field=6 --field=7 --field=8 --field=9 --field=10 <& 2 &
yad --plug=$$ --tabnum=2 --text="\t\t\t\t\t\t\tDnD panel\n\tClick a button Then Drag the mac address here!\n\tDrop command string here..." --dnd | tee $pat >$tap &
yad --geometry=$(cat $camino/geometry/$WINDOWTITLE) --title="$WINDOWTITLE" --window-icon=$pics/bluetooth-active.png --key=$$ --columns=2 --paned --height=220 --width=300 --tab=Found --tab=DnD --button="Command":"echo command" --button="Scan":"echo btscanfn" --button="Remove":"echo rmdev" --button="Connect":"echo btcon" --button="Disconnect":"echo btdisconfn" >/tmp/Wifi-TrayNet/btfn &
bash -c macrx &
bash -c combt &
sleep 0.1
echo -e '\f' >/tmp/Wifi-TrayNet/btpipe
}; export -f bluetooth
bash -c bluetooth &
xscreenshot-20190117T035153.png
 Description   
 Filesize   20.64 KB
 Viewed   1043 Time(s)

xscreenshot-20190117T035153.png


Last edited by stemsee on Sun 17 Feb 2019, 10:12; edited 3 times in total
Back to top
View user's profile Send private message MSN Messenger 
perdido


Joined: 09 Dec 2013
Posts: 1366
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Fri 11 Jan 2019, 12:38    Post subject:  

Hi stemsee,

Just wondering what are the packages needed? I want to try this utility and test it.

I see bluez , yad , wifi-tray-net , hcitool ,

Any others?

Thanks for working on this bluetooth utility! I have never had a consistent bluetooth connection with puppy, just hit and miss,
a working bluetooth utility would be so good for puppy.!


.
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Fri 11 Jan 2019, 13:14    Post subject:  

Hi

Wifi-TrayNEt is not needed. This was developed for TrayNet but this version is standalone.

Bluez / tools etc
hcitool
yad
xscreenshot-20190111T170309.png
Description 
png

 Download 
Filename  xscreenshot-20190111T170309.png 
Filesize  21.21 KB 
Downloaded  209 Time(s) 

Last edited by stemsee on Wed 16 Jan 2019, 23:50; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger 
perdido


Joined: 09 Dec 2013
Posts: 1366
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Fri 11 Jan 2019, 14:44    Post subject:  

stemsee wrote:
Hi

Wifi-TrayNEt is not needed. This was developed for TrayNet but this version is standalone.

Bluez / tools etc
hcitool
yad

I actually upgraded significantly with a commandline execution facility.


Thanks for the quick reply, will try this later tonite and see what I can see Smile

.
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Fri 11 Jan 2019, 15:10    Post subject:  

Here is a video of usage.
https://drive.google.com/file/d/1rf5g8hpcCO0Gew3NdGrbGzyALStk7TzH
xscreenshot-20190111T190928.png
Description 
png

 Download 
Filename  xscreenshot-20190111T190928.png 
Filesize  17.1 KB 
Downloaded  222 Time(s) 

Last edited by stemsee on Wed 16 Jan 2019, 23:50; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger 
perdido


Joined: 09 Dec 2013
Posts: 1366
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Sat 12 Jan 2019, 01:39    Post subject:  

Hi stemsee,

I have a bluetooth adapter in my dell e6400 laptop that is very difficult.
It never initializes with bluez version 5 or later, I was hoping to see it
using the latest ubuntu version of bluez 5.48 & bluez tools in upupbb but that did not happen. It is my hardware that is a problem.

I am still going to keep trying this and will report back if I can figure out the hardware issues.

The video did help me understand the procedure for scanning and connecting. Thanks!

.
Back to top
View user's profile Send private message 
Pro

Joined: 12 Feb 2010
Posts: 112

PostPosted: Mon 14 Jan 2019, 01:26    Post subject:  

it's for bluez4 or bluez5?

I do something like this, maybe it will be useful for you
http://murga-linux.com/puppy/viewtopic.php?t=111331
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Fri 18 Jan 2019, 12:38    Post subject:  

Thanks Pro

I am studying your code.

Whats the functional difference between bluez4 and 5?
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Sat 16 Feb 2019, 09:39    Post subject:  

I changed a bit of the code (rfcomm connect rfcomm4 4) and I was able to send files to android phone. Audio devices connect. Command function is more comprehensively implemented, but basically is a terminal. Just lacking interactive input ... for the moment.
xscreenshot-20190216T132721.png
 Description   
 Filesize   25.08 KB
 Viewed   843 Time(s)

xscreenshot-20190216T132721.png

xscreenshot-20190216T132739.png
 Description   functions listing
 Filesize   21.35 KB
 Viewed   846 Time(s)

xscreenshot-20190216T132739.png

Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Sun 24 Feb 2019, 06:52    Post subject:  

So this version is for bluez5, using bluetoothctl in places.
bt.sh.gz
Description 
gz

 Download 
Filename  bt.sh.gz 
Filesize  10.15 KB 
Downloaded  156 Time(s) 
xscreenshot-20190224T093524.png
 Description   
 Filesize   21.91 KB
 Viewed   722 Time(s)

xscreenshot-20190224T093524.png

Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0785s ][ Queries: 13 (0.0259s) ][ GZIP on ]