0

Is it possible to make the script run when it shifts from normal mode to the interactive mode.

#/bash/bin  
sudo gatttool -b 80:EA:CA:00:00:03 -I  
# All these commands are typed in interactive mode  
connect  
while [ 1 ]; do  
char_read_hnd 0x0030 > a.txt  
done  
exit 1

3 Answers 3

1

are you looking for

 sudo gatttool -b 80:EA:CA:00:00:03 -I  <<EOF
 # All these commands are entered in interactive mode  
connect  
while [ 1 ]; do  
char_read_hnd 0x0030 > a.txt  
done  
exit 1
EOF

the syntax cmd <<EOF (lines ) EOF (on a line of its onw) is called a here doc.

2
  • more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries. Commented Oct 28, 2015 at 9:34
  • @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language. Commented Oct 28, 2015 at 9:53
1

If you need just write or read you can use one string command like this:

gatttool -i hci0 -b device=MAC --char-write-req -a handle=0x0001 -n value=0x0001

gatttool -i hci0 -b device=MAC --char-read -a handle=0x0001

I found it here: http://www.mathieupassenaud.fr/control-your-plugs-with-bluetooth-and-bash-scripts/.

To find more options see gatttool --help-all.

0

You can use expect for shell or pexpect for python.

I think you're searching for something like this: https://www.torsten-traenkner.de/wissen/smarthome/heizung.php

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.