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
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.

  • 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. – cas Oct 28 '15 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. – Ank Khandelwal Oct 28 '15 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.