Page 3 of 19

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 13:59
by woody4165
Sorry to bother again.

Is it normal that I get this with "sudo service check_beacon_presence status"

Code: Select all

● check_beacon_presence.service - LSB: This daemon manages the bluetooth low energy device detector : check_beacon_presence
   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: inactive (dead)
If I submit then a "sudo service check_beacon_presence start"
I get

Code: Select all

● check_beacon_presence.service - LSB: This daemon manages the bluetooth low energy device detector : check_beacon_presence
   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: active (exited) since dom 2016-05-08 13:53:22 CEST; 1s ago
  Process: xxxx ExecStart=/etc/init.d/check_beacon_presence start (code=exited, status=0/SUCCESS)

mag 08 13:53:22 raspberrypi check_beacon_presence[1518]: Starting check_beaco...
mag 08 13:53:22 raspberrypi systemd[1]: Started LSB: This daemon manages the....
Hint: Some lines were ellipsized, use -l to show in full.

If I start from commandline (after a service stop), if works at the first run...
The script is working great, don't understand where I am doling wrong on the startup phase.

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 15:12
by jmleglise
not sudo service ...
the right command :

Code: Select all

sudo /etc/init.d/check_beacon_presence status

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 15:50
by woody4165
Ops, sorry I didn't noticed also in previous post!!

So now I get

Code: Select all

   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: active (exited) since dom 2016-05-08 15:13:32 CEST; 27s ago
Is it correct?

Thanks again.

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 20:05
by blackdog65
sorry to sound like such a total noob :oops:
But I have my hardware today (thank you amazon prime) but how do I interogate my NUT to get the info needed for the python script? :roll:

Many thanks

Sean

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 20:34
by woody4165
Just put the info needed in the check_beacon_presence.py
You can get your nut Mac address from any Ble app, in my case for Android.
Then put Mac address and domoticz idx of a new User variable in string format.
And follow the instruction some post before to launch the script or to launch during boot phase

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 22:12
by jmleglise
blackdog65 wrote:sorry to sound like such a total noob :oops:
But I have my hardware today (thank you amazon prime) but how do I interogate my NUT to get the info needed for the python script? :roll:

Many thanks

Sean

You only need the MAC Adresse of your beacon. And to get it, just run the python script once (with the log enable). The MAC Adresse of your bluetooth device that are broadcasting around you will be displayed.

Re: How to check presence of Beacon ?

Posted: Sunday 08 May 2016 22:21
by jmleglise
woody4165 wrote:Ops, sorry I didn't noticed also in previous post!!

So now I get

Code: Select all

   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: active (exited) since dom 2016-05-08 15:13:32 CEST; 27s ago
Is it correct?

Thanks again.

Nop. what command did you use ?

Look at this sequence :
beacon.jpg
beacon.jpg (103.04 KiB) Viewed 2477 times
Hurry up, It's the end of the Week-end ;-)

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 6:41
by woody4165
Here are the results:

Code: Select all

pi@raspberrypi:~$ ps -ef | grep beacon
pi        1242   994  0 06:16 pts/0    00:00:00 grep beacon
pi@raspberrypi:~$ hciconfig
hci0:   Type: BR/EDR  Bus: UART
        BD Address: B8:27:EB:F9:9D:B1  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:717 acl:0 sco:0 events:42 errors:0
        TX bytes:1532 acl:0 sco:0 commands:42 errors:0

pi@raspberrypi:~$ sudo hciconfig hci0 up
pi@raspberrypi:~$ hciconfig
hci0:   Type: BR/EDR  Bus: UART
        BD Address: B8:27:EB:F9:9D:B1  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:717 acl:0 sco:0 events:42 errors:0
        TX bytes:1532 acl:0 sco:0 commands:42 errors:0

pi@raspberrypi:~$ sudo /etc/init.d/check_beacon_presence  start
[....] Starting check_beacon_presence (via systemctl): check_beacon_presence.ser[ ok.
pi@raspberrypi:~$ sudo /etc/init.d/check_beacon_presence  status
● check_beacon_presence.service - LSB: This daemon manages the bluetooth low energy device detector : check_beacon_presence
   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: active (exited) since lun 2016-05-09 06:14:10 CEST; 3min 23s ago
  Process: 366 ExecStart=/etc/init.d/check_beacon_presence start (code=exited, status=0/SUCCESS)

mag 09 06:14:10 raspberrypi check_beacon_presence[366]: Starting check_beacon...
mag 09 06:14:10 raspberrypi systemd[1]: Started LSB: This daemon manages the....
mag 09 06:17:26 raspberrypi systemd[1]: Started LSB: This daemon manages the....
Hint: Some lines were ellipsized, use -l to show in full.
pi@raspberrypi:~$ ps -ef | grep beacon
pi        1445   994  0 06:17 pts/0    00:00:00 grep beacon
pi@raspberrypi:~$ sudo /etc/init.d/check_beacon_presence  start
[....] Starting check_beacon_presence (via systemctl): check_beacon_presence.ser[ ok.
pi@raspberrypi:~$ sudo /etc/init.d/check_beacon_presence  status
● check_beacon_presence.service - LSB: This daemon manages the bluetooth low energy device detector : check_beacon_presence
   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: active (exited) since lun 2016-05-09 06:14:10 CEST; 4min 3s ago
  Process: 366 ExecStart=/etc/init.d/check_beacon_presence start (code=exited, status=0/SUCCESS)

mag 09 06:14:10 raspberrypi check_beacon_presence[366]: Starting check_beacon...
mag 09 06:14:10 raspberrypi systemd[1]: Started LSB: This daemon manages the....
mag 09 06:17:26 raspberrypi systemd[1]: Started LSB: This daemon manages the....
mag 09 06:18:11 raspberrypi systemd[1]: Started LSB: This daemon manages the....
Hint: Some lines were ellipsized, use -l to show in full.
pi@raspberrypi:~$
There is something wrong on my side... :shock:

This is my check_beacon_presence in /etc/init.d

Code: Select all

#! /bin/sh 
#
# /etc/init.d/check_beacon_presence
#
# Author: jmleglise
# Date : 7 May 2016
# https://github.com/jmleglise/mylittle-domoticz/tree/master/Presence%20detection%20%28beacon%29
#
### BEGIN INIT INFO
# Provides:          check_beacon_presence
# Required-Start:    
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: This daemon manages the bluetooth low energy device detector : check_beacon_presence
# Description:       Check the presence of a list of beacon and send HTTP request to Domoticz to update uservariables accordingly.
### END INIT INFO

# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/local/bin/check_beacon_presence.py

# The process ID of the script when it runs is stored here:
PIDFILE=/var/run/check_beacon_presence.pid

NAME=check_beacon_presence

test -x $DAEMON_OPTS || exit 0

. /lib/lsb/init-functions


do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started

	if pidofproc -p $PIDFILE "$DAEMON" > /dev/null 2>&1 ; then
	        return 1
	fi
}

case "$1" in
  start)
     log_daemon_msg "Starting $NAME"
     do_start
     RET_STATUS=$?
     case "$RET_STATUS" in
	1)
	   log_success_msg
           [ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Daemon was already running"
	;;
	*)
     	   start-stop-daemon --start  --background --oknodo --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --exec $DAEMON  $DAEMON_OPTS 
           log_end_msg $?
        ;;
     esac
     ;;
  stop)
     log_daemon_msg "Stopping $NAME"
     start-stop-daemon --stop --pidfile $PIDFILE --retry 10
     log_end_msg $?
   ;;
  force-reload|restart)
     $0 stop
     $0 start
   ;;
  status)
     status_of_proc -p $PIDFILE $DAEMON $NAME  && exit 0 || exit $?
   ;;
 *)
   echo "Usage: /etc/init.d/check_beacon_presence {start|stop|restart|force-reload|status}"
   exit 1
  ;;
esac
exit 0
These are the files permissions:

Code: Select all

pi@raspberrypi:~$ ls -l /etc/init.d/check_beacon_presence
-rwxr-xr-x 1 root root 2140 mag  8 18:37 /etc/init.d/check_beacon_presence
pi@raspberrypi:~$ ls -l /usr/local/bin/check_beacon_presence.py
-rwxr-xr-x 1 root staff 8240 mag  8 15:09 /usr/local/bin/check_beacon_presence.py
:shock: :shock: :shock:

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 11:12
by blackdog65
Hi guys,

Thanks for the earlier help :D
I have it all installed but I'm struggling now with getting the daemon to run.

Code: Select all

pi@bluetooth1 ~ $ sudo /etc/init.d/check_beacon_presence start
[ ok ] Starting check_beacon_presence:.
pi@bluetooth1 ~ $ sudo /etc/init.d/check_beacon_presence status
[FAIL] check_beacon_presence is not running ... failed!
and the /var/log/check_beacon_presence.log isn't being generated so I can't see why. :x

Code: Select all

# choose between DEBUG (log every information) or CRITICAL (almost no log)
#logLevel=logging.DEBUG
logLevel=logging.CRITICAL

logOutFilename='/var/log/check_beacon_presence.log'       # comment this line to console output
I've tried all the above "fixes" but can't see where I'm going wrong.

This part confuses me a little too,

Code: Select all

# Configure your Beacon here : 
# [Name,MacAddress,Timeout,0,idx,mode]
# Name : same as the uservariable in Domoticz
# Timeout is in secondes the elapsed time  without a detetion for switching the beacon AWAY. Ie :if your beacon emits every 3 to 8 seondes, a timeout of 15 secondes seems good.
# 0 : used by the script (will keep the time of the last broadcast) 
# idx of the uservariable in Domoticz for this beacon
# mode : 0 for 1 update per status change / 1 continuous updating

TAG_DATA = [  
           ["Foo_Tag","xx:xx:xx:xx:xx:xx",15,0,1]
           ]
shouldn't it be

Code: Select all

["Foo_Tag","xx:xx:xx:xx:xx:xx",15,0,1,0]
Many thanks

Sean

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 11:46
by woody4165
blackdog65 wrote:Hi guys,

Thanks for the earlier help :D
I have it all installed but I'm struggling now with getting the daemon to run.

Code: Select all

pi@bluetooth1 ~ $ sudo /etc/init.d/check_beacon_presence start
[ ok ] Starting check_beacon_presence:.
pi@bluetooth1 ~ $ sudo /etc/init.d/check_beacon_presence status
[FAIL] check_beacon_presence is not running ... failed!
and the /var/log/check_beacon_presence.log isn't being generated so I can't see why. :x
What is the DAEMON_USER in /etc/init.d/check_beacon_presence ?
It was pi, that I changed to root

blackdog65 wrote:

Code: Select all

# choose between DEBUG (log every information) or CRITICAL (almost no log)
#logLevel=logging.DEBUG
logLevel=logging.CRITICAL

logOutFilename='/var/log/check_beacon_presence.log'       # comment this line to console output
I've tried all the above "fixes" but can't see where I'm going wrong.
To see log, uncomment the .DEBUG one and comment the .CRITICAL
blackdog65 wrote: This part confuses me a little too,

Code: Select all

# Configure your Beacon here : 
# [Name,MacAddress,Timeout,0,idx,mode]
# Name : same as the uservariable in Domoticz
# Timeout is in secondes the elapsed time  without a detetion for switching the beacon AWAY. Ie :if your beacon emits every 3 to 8 seondes, a timeout of 15 secondes seems good.
# 0 : used by the script (will keep the time of the last broadcast) 
# idx of the uservariable in Domoticz for this beacon
# mode : 0 for 1 update per status change / 1 continuous updating

TAG_DATA = [  
           ["Foo_Tag","xx:xx:xx:xx:xx:xx",15,0,1]
           ]
shouldn't it be

Code: Select all

["Foo_Tag","xx:xx:xx:xx:xx:xx",15,0,1,0]
Many thanks

Sean
I didn't noticed the last parameter, I don't have it, and it works (not the service part for me, just launching with sudo pyhton check_beacon_presence.py).

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 13:00
by blackdog65
Hi Woody,
I'm slowly catching up,

I found that I had a few python "bits n bobs" missing... which REALLY didn't help :lol:

Sooo...

I cannot get the daemon to run manually or as a service as either user (pi/root) but I can get

Code: Select all

sudo python /usr/local/bin/check_beacon_presence.py
to run now
In the log it says my NUT is away... in reality it's 1cm away :roll:

and on checking my dongle with

Code: Select all

hcitool scan
I see my phone but no nut. I added my phone to the python script but that shows as away too :shock:

dear oh dear

Thanks for the support so far though

Sean

PS is the 65 in woody4165 a year? are you a fellow 65er?

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 13:47
by johnArran
thanks for the wonderful replies guys.

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 13:58
by woody4165
Yeah, I'm a 65er "guy"... :D

Have you tried with an app like "BLE Scanner" to check if your Nut is seen (Nut 2 or 3)?

I got my MAC address from there (didn't know the script can do this!) and just filled out the py script

Code: Select all

["MyTag","xx:xx:xx:xx:xx:xx",15,0,yy]
The last tag you have does not need the comma at the end, if you have more than one.

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 14:46
by blackdog65
ok,
if I run

Code: Select all

sudo python /usr/local/bin/check_beacon_presence.py &
after manual starting my BLE dongle, user variable for the NUT is switching between home and away... so I just need it to start on boot and I'm super-happy! :lol:

Could I have a peep at the script you wrote Woody? I assume it turns on a virtual/dummy switch when the variable says "HOME"

Cheers buddy

Sean

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 18:03
by korniza
blackdog65 wrote: In the log it says my NUT is away... in reality it's 1cm away :roll:

and on checking my dongle with

Code: Select all

hcitool scan
I see my phone but no nut. I added my phone to the python script but that shows as away too :shock:

Code: Select all

Hcitool scan
is not your friend. Instead you need

Code: Select all

hcitool lescan 
to get Low Energy devices! hope that helps :D

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 18:12
by korniza
New BLE idea: I just got my TI SensorTag (29 US$. read more: http://www.ti.com/ww/en/wireless_connec ... =sensortag ) which has 9 embedded sensors and provides via bluetooth it's data.
As first thought was to get it as a personal Tag, BUT now I have a better project: Monitor my refrigarator! I get temperature, moisture, motion data (if someone opens the door of fridge) as also Lux.
The main problem is that presence beacon script hijacks bluetooth usb stick and can not perform any other bluetooth action. A workaround is to get a second bluetooth dongle and use it as interface with SensorTag. Before starting to fill all my usb hub ports with BLE dongles, does someone knows a way to use BLE donge as presence and also get connected to another device? :cry: :o :shock:

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 18:23
by woody4165
blackdog65 wrote:ok,
if I run

Code: Select all

sudo python /usr/local/bin/check_beacon_presence.py &
after manual starting my BLE dongle, user variable for the NUT is switching between home and away... so I just need it to start on boot and I'm super-happy! :lol:

Could I have a peep at the script you wrote Woody? I assume it turns on a virtual/dummy switch when the variable says "HOME"

Cheers buddy

Sean
Happy that it's working with python.
I'm not the writer of this script!!!
I'm in the same situation, I'm not able to let it start at boot...

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 18:51
by blackdog65
woody4165 wrote:In the meantime I made a tiny script to check my Nut when entering home, turn on a light and I work like a charm!
Really impressive!
Thanks again for sharing... [WINKING FACE]
was the one I meant, but I bodged a blockly script together for doing just that... yay! :D

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 22:10
by jmleglise
Hi,

@woody :
Are-you sure , it didn't work ? You have a different output than mine but yours says it works too. Look : active since 4min 3s ago !

sudo /etc/init.d/check_beacon_presence status
● check_beacon_presence.service - LSB: This daemon manages the bluetooth low energy device detector : check_beacon_presence
Loaded: loaded (/etc/init.d/check_beacon_presence)
Active: active (exited) since lun 2016-05-09 06:14:10 CEST; 4min 3s ago
Process: 366 ExecStart=/etc/init.d/check_beacon_presence start (code=exited, status=0/SUCCESS)


So finish the install,

Code: Select all

sudo update-rc.d check_beacon_presence defaults
reboot, and check .log with a tail /var/log/check_beacon_presence.log

Re: How to check presence of Beacon ?

Posted: Monday 09 May 2016 22:28
by woody4165
The status is the same

The log is stuck at

Code: Select all

2016-05-09 22:24:00,747 - root - INFO - Connect to bluetooth device 0
But if I stop it

Code: Select all

sudo /etc/init.d/check_beacon_presence stop
restart it

Code: Select all

sudo /etc/init.d/check_beacon_presence start
I get this

Code: Select all

pi@raspberrypi:~$ sudo /etc/init.d/check_beacon_presence status
● check_beacon_presence.service - LSB: This daemon manages the bluetooth low energy device detector : check_beacon_presence
   Loaded: loaded (/etc/init.d/check_beacon_presence)
   Active: active (exited) since lun 2016-05-09 22:23:58 CEST; 50s ago
  Process: 366 ExecStart=/etc/init.d/check_beacon_presence start (code=exited, status=0/SUCCESS)
and this from the log

Code: Select all

2016-05-09 22:25:53,640 - root - INFO - Connect to bluetooth device 0
2016-05-09 22:25:54,340 - root - DEBUG - Tag Detected