Access right problem (bluetooth dongle)

I have setup a presence check according to https://klenzel.de/3328#comment-5710
(sorry - it’s in German ony).
The general setup seems to be ok:
I can run the following script (as root) in the command line and will get an “ON” if my phone is within range:

#!/bin/bash
#1=iPhone1, 2=iPhone2
case $1 in
   1) MAC="xx:xx:xx:xx:xx:xx" ;;
   2) MAC="xx:xx:xx:xx:xx:xx" ;;
esac
 
if /usr/bin/l2ping -c 1 $MAC &> /dev/null
   then
      echo "ON"
   else
      echo "OFF"
fi

My item is setup accordingly:
Switch iPhone1_BT "iPhone1(BT) [%s]" { exec="<[/usr/share/openhab/configurations/scripts/bt.sh 1:60000:REGEX((.*?))]" }

But I never get the switch to the “ON” state.
The script bt.sh has the same access right like other scripts running fine and the default user openhab is in the group “dialout” (which was the solution for an earlier problem with zwave USB dongle).
Any idea?

I know you say it’s an access problem, but the “.*?” in your regex looks suspicious. This does a [“non-greedy” match] (http://www.regular-expressions.info/repeat.html) which means that matches against “ON” and “OFF” will be “” (zero length string). I think this will either result in an error in openHAB or always evaluate to OFF. Try REGEX((.*)) instead.

Thanks, Steve - I will try it.
As I had the syntax from another website, I thought, it must be alright…
Will keep you posted.

I tried it, but it did not help.
I have re-checked the code and remember, that I got the syntax for the REGEX from here:


as an example.
exec="<[php ./configurations/scripts/script.php:60000:REGEX((.*?))]"

What OS are you running?
Check if the user that runs the script can create the lock file for the USB device. I had similar problem with z-wave USB on CentOS 7, adding openhab user to the dialout was not enough, I had to change the access rights to the /var/lock directory for the lock user group and add openhab user to this group.

I am running Raspbian, but the lock doens’t seem to be the problem, because openhab obviously has the rights (there is a lock file for the zwave USB stick).

pi@Raspen /var/lock $ ls -la
total 4
drwxrwxrwt  2 root    root     60 Nov 16 09:47 .
drwxr-xr-x 15 root    root    700 Nov 16 09:45 ..
-rw-rw-r--  1 openhab openhab  11 Nov 16 09:47 LCK..ttyACM0

The problem seems to be more on the lower level:
When I run the script and use inside it a sudo command:
if /usr/bin/sudo /usr/bin/l2ping -c 1 $MAC
to check for the BT devices, I get the response:
sudo: no tty present and no askpass program specified
Any idea what this means?

Thanks!!
That’s it.
Actually I have found a similar post, but just messed the sudoers file up:
/usb/bin/l2ping instead of /usr/bin/l2ping
stupid mistake - so thanks for pushing me again into this direction. :smile: