Page 14 of 19

Re: How to check presence of Beacon ?

Posted: Monday 13 March 2017 8:33
by emme
..well.. how do you start the service?

note the follow:
- everytime you start the beacon service it is good procedure to reset the hci0 interface with

Code: Select all

sudo hciconfig hci0 down && sleep 1 && sudo hciconfig hci0 up
while beacon service is using the interface for detecting beacons... no other service should interact with the hci0 interface

I've added 1 interface more (using an external dongle) so I have: 1 for beacons discovery and the other for battery service

Re: How to check presence of Beacon ?

Posted: Monday 13 March 2017 20:34
by Guiggess
I followed the tutorial on first page so when I start the service manually, it works fine. It is only after the update-rc.d part that it doesn't work.
I had a look at the code but I not sure to get it properly. It looks like there is a "start" section (after case $1), but I don't know if it is the place to put the different lines.
Do you use that same file to start the service ?
I will try some of your proposal. Nothing can be broken ;-)

Re: How to check presence of Beacon ?

Posted: Monday 13 March 2017 21:11
by Guiggess
So I did try a few things with your proposal : no success :-(

You were talking about a .service file. Is it automatically generated? Where is it supposed to be located ?

Re: How to check presence of Beacon ?

Posted: Thursday 16 March 2017 8:18
by emme
no, the file is not automatically enerted, you have to...

is is normally stored in /lib/systemd/system/servicename.service

than you have to issue few commands to enable and autorun it

..is your file running correctly from a command line? Do you have to press CTRL-C to interrupt it?

if so these are the instruction to create a .service file:

Code: Select all

sudo nano /lib/systemd/system/beacon.service
then copy/paste the following

Code: Select all

[Unit]
Description=Beaconing Service
After=multi-user.target

[Service]
User=root
Type=idle
ExecStart= <full path to your beacon file> (like /home/pi/beacon/mybeaconservice.py)

[Install]
WantedBy=multi-user.target
save and exit with ctrl-X (confirm with Y)

now the file is created.. let's update the services system daemon and enable it

Code: Select all

sudo systemctl daemon-reload
sudo systemctl enable beacon.service
sudo systemctl start beacon.service
now the service should have been started... check it with

Code: Select all

systemctl status beacon.service
you should see something like:

Code: Select all

● domoticz.service - LSB: Home Automation System
   Loaded: loaded (/etc/init.d/domoticz.sh)
   Active: active (running) since Wed 2017-03-15 14:15:03 CET; 18h ago
   CGroup: /system.slice/domoticz.service
           └─32467 /home/pi/domoticz/domoticz -daemon -www 8080 -sslwww 443 -log /tmp/domoticz.txt
the main important thing is the 3rd line: Active: active (running)

you can try to reboot and check the status to ensure it works (but it would)
ciao
M

Re: How to check presence of Beacon ?

Posted: Tuesday 16 May 2017 20:53
by jonluk
what can I say. Followed the wiki and everything worked perfectly.
Battery level works great, presence detection appears spot on.

Now to load it onto a few more pi's and see how it works on a per room basis.

Oh, I'm using a nut3 btw.

Re: How to check presence of Beacon ?

Posted: Friday 26 May 2017 20:33
by Padster
Hi,

I'm using the python script with the tag mode set to switch mode. I've set up Blocky to send a notification when the variable is set to AWAY and another when the variable returns to HOME.

The purpose of me setting this up is for my dog. I've attached the tag to his collar. One problem I have is when he is in the garden the status floats between home and away so I get numerous alerts.

Any pointers on how I can solve this?

EDIT Not sure if range is problem a it is now changing between home and away while he is sleeping about 3 metres from the raspberry pi.

Thanks

Re: How to check presence of Beacon ?

Posted: Monday 29 May 2017 8:24
by emme
you can avoid it using RSSI instead of a simple switch
based on the signal stenght you can better guess the distance form the antenna.
This would drain your battery faster, eventually you can add another script to check battery status ;)

or add a delay between checks (add a sleep(20) at the endo of the script :P)

Re: How to check presence of Beacon ?

Posted: Friday 02 June 2017 14:25
by Padster
I've managed to get it a bit better by adjusting a couple of the timeouts.

I'm still getting false alarms and I am convinced that the Nut 2 stops broadcasting sometimes. The reviews on Amazon also suggest this.

Has anyone found a reliable beacon that doesn't generate false alarms?

Re: How to check presence of Beacon ?

Posted: Monday 05 June 2017 8:27
by emme
NUT (but I assume all BLE devices) quit broadcast as soon as they are paired with an app (ie: the NRF tool or the NutSpace App)

the only workaround is: do not pair them :P

Re: How to check presence of Beacon ?

Posted: Monday 05 June 2017 11:39
by b0b56
Hello,

I try to use Jmleglise's script on Domoticz
My NUT keeps disconnecting after 10 seconds (it disconnects when discovering mode ends).
In discovering mode (when I have been pressing on button for 3 seconds), I can see it, note its MAC address, I appears on domoticz.
Then the NUT stops blinking, and I lose it ("AWAY" in domoticz)

I tried to pair it with my phone -> same result in domoticz (but still working with my phone when the nut stops blinking)

I bought this NUT : http://www.banggood.com/Mini-Smart-Patc ... 88462.html (recommended in this forum).

Could you please help me ?
Thanks

Re: How to check presence of Beacon ?

Posted: Monday 05 June 2017 15:09
by b0b56
b0b56 wrote:Hello,

I try to use Jmleglise's script on Domoticz
My NUT keeps disconnecting after 10 seconds (it disconnects when discovering mode ends).
In discovering mode (when I have been pressing on button for 3 seconds), I can see it, note its MAC address, I appears on domoticz.
Then the NUT stops blinking, and I lose it ("AWAY" in domoticz)

I tried to pair it with my phone -> same result in domoticz (but still working with my phone when the nut stops blinking)

I bought this NUT : http://www.banggood.com/Mini-Smart-Patc ... 88462.html (recommended in this forum).

Could you please help me ?
Thanks
Well, I don't really know what I did but that works, NUTs are now OK on domoticz.
Thanks

Re: How to check presence of Beacon ?

Posted: Tuesday 06 June 2017 12:07
by Padster
I'm still getting false alerts.

I'm running a Pi 3 but as I have a Razberry 2 fitted that disables onboard Bluetooth I'm using a usb dongle.

I've tried two different usb dongles with a NUT 2 and now a Lapa beacon but I still get AWAY alerts. The Tag can be in the same location, then for no reason I get an alert. The debug log shows ;

Code: Select all

2017-06-06 10:52:25,335 - root - DEBUG -  <Thread(Thread-38, started 1974465632)> -> <Response [200]>
2017-06-06 10:52:27,567 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-76,) - DATA unknown (0,)
2017-06-06 10:52:32,075 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-77,) - DATA unknown (0,)
2017-06-06 10:52:32,082 - root - DEBUG - Tag Tag_Mason is still there with an RSSI of -77  : update presence with RSSI
2017-06-06 10:52:32,084 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:52:32,100 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=-77 HTTP/1.1" 200 58
2017-06-06 10:52:32,104 - root - DEBUG -  <Thread(Thread-39, started 1974465632)> -> <Response [200]>
2017-06-06 10:52:34,331 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-60,) - DATA unknown (0,)
2017-06-06 10:52:36,590 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-77,) - DATA unknown (0,)
2017-06-06 10:52:52,371 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-80,) - DATA unknown (0,)
2017-06-06 10:52:52,373 - root - DEBUG - Tag Tag_Mason is still there with an RSSI of -80  : update presence with RSSI
2017-06-06 10:52:52,380 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:52:52,396 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=-80 HTTP/1.1" 200 58
2017-06-06 10:52:52,400 - root - DEBUG -  <Thread(Thread-40, started 1974465632)> -> <Response [200]>
2017-06-06 10:52:54,629 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-82,) - DATA unknown (0,)
2017-06-06 10:53:03,649 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-85,) - DATA unknown (0,)
2017-06-06 10:53:03,651 - root - DEBUG - Tag Tag_Mason is still there with an RSSI of -85  : update presence with RSSI
2017-06-06 10:53:03,658 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:53:03,674 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=-85 HTTP/1.1" 200 58
2017-06-06 10:53:03,677 - root - DEBUG -  <Thread(Thread-41, started 1974465632)> -> <Response [200]>
2017-06-06 10:53:14,925 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-85,) - DATA unknown (0,)
2017-06-06 10:53:14,927 - root - DEBUG - Tag Tag_Mason is still there with an RSSI of -85  : update presence with RSSI
2017-06-06 10:53:14,934 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:53:14,950 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=-85 HTTP/1.1" 200 58
2017-06-06 10:53:14,954 - root - DEBUG -  <Thread(Thread-42, started 1974465632)> -> <Response [200]>
2017-06-06 10:53:17,178 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-76,) - DATA unknown (0,)
2017-06-06 10:53:26,190 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-85,) - DATA unknown (0,)
2017-06-06 10:53:26,192 - root - DEBUG - Tag Tag_Mason is still there with an RSSI of -85  : update presence with RSSI
2017-06-06 10:53:26,199 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:53:26,216 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=-85 HTTP/1.1" 200 58
2017-06-06 10:53:26,219 - root - DEBUG -  <Thread(Thread-43, started 1974465632)> -> <Response [200]>
2017-06-06 10:53:57,054 - root - WARNING - Tag Tag_Mason not seen since 30 sec => update absence
2017-06-06 10:53:57,061 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:53:57,077 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=AWAY HTTP/1.1" 200 58
2017-06-06 10:53:57,081 - root - DEBUG -  <Thread(Thread-44, started daemon 1974465632)> -> <Response [200]>
2017-06-06 10:55:39,213 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-90,) - DATA unknown (0,)
2017-06-06 10:55:39,218 - root - DEBUG - Tag Tag_Mason is still there with an RSSI of -90  : update presence with RSSI
2017-06-06 10:55:39,222 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:55:39,239 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=-90 HTTP/1.1" 200 58
2017-06-06 10:55:39,243 - root - DEBUG -  <Thread(Thread-45, started 1974465632)> -> <Response [200]>
2017-06-06 10:56:12,175 - root - WARNING - Tag Tag_Mason not seen since 32 sec => update absence
2017-06-06 10:56:12,183 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-06-06 10:56:12,199 - urllib3.connectionpool - DEBUG - "GET /json.htm?type=command&param=updateuservariable&idx=1&vname=Tag_Mason&vtype=2&vvalue=AWAY HTTP/1.1" 200 58
2017-06-06 10:56:12,202 - root - DEBUG -  <Thread(Thread-46, started daemon 1974465632)> -> <Response [200]>
2017-06-06 10:56:33,297 - root - DEBUG - Tag Tag_Mason Detected fe:42:b8:64:32:15 - RSSI (-92,) - DATA unknown (0,)
:
Here is the RSSI for the last day. I'm getting 30+ false alerts a day
rssi.JPG
rssi.JPG (53.34 KiB) Viewed 4539 times
Anyone got any ideas on how to solve this?


***EDIT*** I've improved things by seperating the usb BT dongle from the Pi by using a usb extension lead.

Re: How to check presence of Beacon ?

Posted: Tuesday 20 June 2017 10:27
by Padster
I've been using this for a while now and its pretty reliable.

I wonder though if this is a good thing to be running on a RPi3 with SD card. I am running the python script and raspberry piet's script on page 6.

Will this be causing a lot of writes to the SD card?

Re: How to check presence of Beacon ?

Posted: Thursday 13 July 2017 22:32
by bertbigb
Hi All,

I'm using a raspberry 3 with internal bluetooth.
It is working OK I think since I'm running the Mi Flora Bluetooth LE succesfully
I also liked to check presence of people with a beacon so I bought a few, installed the script (following the wiki)
now I get the following error:

Code: Select all

pi@raspberrypi:/usr/local/bin $ sudo python /usr/local/bin/check_beacon_presence.py
  Traceback (most recent call last):
  File "/usr/local/bin/check_beacon_presence.py", line 75, in <module>
   import bluetooth._bluetooth as bluez
   ImportError: No module named bluetooth._bluetooth
The message is quit obvious but how do I get the bluetooth._bluetooth module?

During installation of bluez I got:

Code: Select all

pi@raspberrypi:/usr/local/bin $ sudo apt-get install bluez
Reading package lists... Done
Building dependency tree       
Reading state information... Done
bluez is already the newest version.
Hope someone can help me or point me out what to do.
Thanks for any help

Re: How to check presence of Beacon ?

Posted: Friday 14 July 2017 8:17
by emme
try with...

Code: Select all

sudo apt-get update
sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez

Re: How to check presence of Beacon ?

Posted: Friday 14 July 2017 8:41
by bertbigb
emme wrote:try with...

Code: Select all

sudo apt-get update
sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez
I'm not at home right now and don't have access to the pi.
Will try this weekend and keep you informed.
Molto grazias for your quick reply.

Re: How to check presence of Beacon ?

Posted: Saturday 15 July 2017 22:19
by bertbigb
emme wrote:try with...

Code: Select all

sudo apt-get update
sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez
Thank you very much. This did the job

Re: How to check presence of Beacon ?

Posted: Tuesday 25 July 2017 13:28
by bertbigb
Hi All / emme

Due to an accident I removed a few files to much from my Raspberry 3.
It was that worse that I had to completely reinstall the raspbian jessie and reinstall domoticz.
I got it all up and running again :lol: it only cost a bit of time.

Then I would start again with the presence detection. I followed the wiki again and installed also

Code: Select all

sudo apt-get update
sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez
When I now start the check_beacon_presence.py I get the following error.

Code: Select all

pi@raspberrypi:/usr/local/bin $ sudo python /usr/local/bin/check_beacon_presence.py
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/bin/check_beacon_presence.py", line 127, in request_thread
    logging.critical(' %s Request Failed %s - %s' % (threading.current_thread(), e, url) )
TypeError: __str__ returned non-string (type Error)

I hope someone can help me out to get this fixed.

Best regards Bert

Re: How to check presence of Beacon ?

Posted: Tuesday 25 July 2017 14:33
by bertbigb
bertbigb wrote:Hi All / emme

Due to an accident I removed a few files to much from my Raspberry 3.
It was that worse that I had to completely reinstall the raspbian jessie and reinstall domoticz.
I got it all up and running again :lol: it only cost a bit of time.

Then I would start again with the presence detection. I followed the wiki again and installed also

Code: Select all

sudo apt-get update
sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez
When I now start the check_beacon_presence.py I get the following error.

Code: Select all

pi@raspberrypi:/usr/local/bin $ sudo python /usr/local/bin/check_beacon_presence.py
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/bin/check_beacon_presence.py", line 127, in request_thread
    logging.critical(' %s Request Failed %s - %s' % (threading.current_thread(), e, url) )
TypeError: __str__ returned non-string (type Error)

I hope someone can help me out to get this fixed.

Best regards Bert
Just found out myself, by looking at line 127 in the script I thought it should have something to do with parameters I gave in. When I thoughtfully inspected I found out that I typed httpS://localhost instead of http://localhost.
Now it is working well. Hope someone who get this same type of error can found out easily also

NUT mini battery life?

Posted: Sunday 06 August 2017 14:28
by Hesmink
Hi All,

What is the expected battery life of a mini NUT when used in this presence detection method?
Mine died after a month, that seems a bit quick.