I am trying to connect my phone to my RaspberryPi using a blue tooth dongle (not trying to do anything earth shattering, just determine when my phone is in the area). If I turn my phone's blue tooth on and issue the following command, I get the following output (before anyone starts preaching to me about how this is a breach of security, let me remind you that that is not my actual phone bluetooth id):
command:
sudo rfcomm connect 0 AA:BB:CC:DD:EE:FF 10
echo $?
output:
Connected /dev/rfcomm0 to AA:BB:CC:DD:EE:FF on channel 10
Press CTRL-C for hangup
0
Now if I turn my phone's bluetooth off, and issue the same command, I get the following output (again, all id's have been changed to protect the innocent).
command:
sudo rfcomm connect 0 AA:BB:CC:DD:EE:FF 10
echo $?
output:
Can't connect RFCOMM socket: Host is down
0
Since I am trying to determine when the phone is in the room and when it leaves, I need some way (some other way) of detecting when the dongle can and can not connect to it. How can I go about achieving this? (NOTE: I tried removing the phone from the building and even turning it off completely)
EDIT: I have considered catching the stderr
message and testing it like so
error=$`sudo rfcomm connect 0 AA:BB:CC:DD:EE:FF 10 >/dev/null` &
if [ $error=="Can't connect RFCOMM socket: Host is down" ]
then
...
fi;
But the problem is that rfcomm has to run in the background.