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 Thu 24 Jan 2019, 06:25
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 [8 Posts]  
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2293
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
#
[[ -d /tmp/Wifi-TrayNet ]] && rm -rf /tmp/Wifi-TrayNet
[[ ! -d /tmp/Wifi-TrayNet ]] && mkdir /tmp/Wifi-TrayNet
function btscanfn (){
   timeout 14 hcitool scan | grep -v 'Scanning' | tr '\t' ' ' 1>/tmp/Wifi-TrayNet/btresults &
function flash (){
   echo -e '\f'
   sleep 0.4
   echo "Please Wait ... !"
   sleep 0.4
}; export -f flash >/tmp/Wifi-TrayNet/btpipe
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"
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
yes | bt-device -c $line
   bt-audio -c $line
else
yes | hcitool lecc $line
   bt-audio -c $line
fi
sleep 3
bash -c blank
done
}; export -f btcon

function btobex (){
bash -c btset   
echo "DnD mac for btobex"
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   
    bt-obex -s $line
   bt-obex -f $line
else
   hcitool lecc $line
   bt-obex -s $line
   bt-obex -f $line
fi
sleep 3
bash -c blank
done
}; 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" 1> /tmp/Wifi-TrayNet/btmac
   else
      echo "$line" 1> /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 &
#wait $!
export funcpid=$!
done &
export combtpid=$!
}; export -f combt

function btsend (){
bash -c btset
sleep 2
tail -fn0 /tmp/Wifi-TrayNet/btmac | while read line
do   
   this=`yad --file`
   [[ -z "$this" ]] && exit
   bt-obex -c $line
   bt-obex -p "$this" $line
   sleep 3
   bash -c blank
done
}; export -f btsend

function btset (){
   hcitool con >/tmp/Wifi-TrayNet/btpipe
   kill $funcpid &>/dev/null
}; export -f btset

function clear (){
export tap=/dev/null
echo -e '\f'
echo "rfkill block bluetooth"
echo "rfkill unblock bluetooth"
echo "hcitool lewladd"
echo "hcitool con"
echo "hcitool lescan"
echo "bt-input -c"
echo "bt-obex"
echo "bt-device -l"
echo "bt-network"
echo "***Edit command & drag to Command DnD pane"
#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 clear
      else
         bash -c blank
         exec $line
      fi
export tap=/tmp/Wifi-TrayNet/hciselect
done
}; export -f clear

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

function bluetooth (){
[[ -f /tmp/Wifi-TrayNet/started ]] && exit
kill $combtpid &>/dev/null
kill $macrxpid &>/dev/null
export tap=/tmp/Wifi-TrayNet/hciselect
[[ ! -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
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\tMAC/Command DnD pane\n\tClick a button\n\tThen Drag the mac address here!" --dnd | tee /tmp/Wifi-TrayNet/selecthci 1>$tap &
yad --title=Bluetooth --key=$$ --columns=2 --paned --height=220 --width=300 --tab=Found --tab=DnD --button="Command":"echo clear" --button="Scan":"echo btscanfn" --button="Remove":"echo rmdev" --button="Connect":"echo btcon" --button="Disconnect":"echo btdisconfn" 1>/tmp/Wifi-TrayNet/btfn &
bash -c macrx &
bash -c combt &
sleep 0.1
echo -e '\f' >/tmp/Wifi-TrayNet/btpipe
touch /tmp/Wifi-TrayNet/started
}; export -f bluetooth
bash -c bluetooth &
xscreenshot-20190117T035153.png
 Description   
 Filesize   20.64 KB
 Viewed   67 Time(s)

xscreenshot-20190117T035153.png


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


Joined: 09 Dec 2013
Posts: 1125
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: 2293
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  26 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: 1125
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: 2293
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  32 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: 1125
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: 111

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: 2293
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 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 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.0602s ][ Queries: 13 (0.0196s) ][ GZIP on ]