How to check presence of Beacon ?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
roblom
Posts: 565
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Re: How to check presence of Beacon ?

Post by roblom » Wednesday 16 August 2017 19:30

I have this working but it only works for a few seconds. After that no updates are made. When I do a reset then it works for a few seconds again.

honselbonsel
Posts: 1
Joined: Thursday 17 August 2017 20:25
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by honselbonsel » Friday 18 August 2017 10:25

Hi jimieglise,
i installed your script and it is running as a service. All is fine Thanks for the Great Work.
But there is one thing which makes me crazy.
Example: i sit nearby the Bluetooth dongle location (with the beacon laying down on the desk) the Presence should be ok but on each checking of the script it returns the beacon Away then a value then Away then a Value and so on...
The Beacon is not Moving. But the status is flapping

any ideas? :-)

thx
jens

nizaga
Posts: 96
Joined: Monday 30 November 2015 12:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by nizaga » Thursday 24 August 2017 23:23

Hi! I just got a Mini Nut 2. Is it possible to call mi nut from domoticz like I can do from the iOS app? I want to be able to search my keys currently attached to the Nut. So, can I get my Nut to beep via domoticz? Thanks


Enviado desde mi iPhone utilizando Tapatalk Pro

guantolento
Posts: 172
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: How to check presence of Beacon ?

Post by guantolento » Monday 04 September 2017 16:48

hi, i have reinstall all bluez with fw 5.46.
in the folder attribute i can't find the file gatttool,so i can't take the command
sudo cp attrib/gatttool /usr/local/bin/ as in the wiki.
any info for me ?
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F

User avatar
emme
Posts: 615
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: How to check presence of Beacon ?

Post by emme » Monday 04 September 2017 17:00

mine gets at 30% after almost a year

battery check will drain the battery, so do not check it too much... once a week should be enough.
I use to check it every time the nut will appear back in the network... soon I'll move this to once a day as soon as it is back availble

ciao
M
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

TheCondor
Posts: 31
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by TheCondor » Monday 04 September 2017 17:35

Hello, i'm using this script since 6 month ago circa with my PI3 internal BT. All is working fine but the signal is so strong that the variable "home/away" changes also when i'm out of the building and i go from my car to my garage :lol:

Any trick for set in the script an RSSI max value for the discovery?

User avatar
emme
Posts: 615
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: How to check presence of Beacon ?

Post by emme » Monday 04 September 2017 17:47

RSSI is gather once the beacon is discovered as available in the network...

this means that if your beacon bumps off and on it means that is not seen during the scan... this is possible for a wide range of reasons:

- BT atenna is shielded by walls, metals or other stuff
- BT interface is not availble by the time of scan (do you have other services that runs at the same time that use hci0?)
- Scan time is too short (specially when there are a lot of LE devices available)

my old script used to check 3 times in 10 seconds before setting off a device due to those bumps (my pi is inside a closet), than I placed a CRS bt4 dongle which was more efficient.. and did not get this issue anymore.

Sometimes the BLE itself won't beacon as it is supposed to do ;)
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
solidum90
Posts: 35
Joined: Tuesday 01 August 2017 20:59
Target OS: NAS (Synology & others)
Domoticz version: Debian
Location: Milan
Contact:

Re: How to check presence of Beacon ?

Post by solidum90 » Tuesday 05 September 2017 22:40

Hello to everyone,
this script works great.. but I have two questions:

I have a nut 3 Beacon, when the Beacon is associated iphone's app this script doesn't see beacon, is it correct?
There's no way to works both ?

Otherwise, can not you run this script even to detect iphone?
(I try to add my iphone on TAG_DATA but it doesn't work)

Thanks to everyone and congratulations for this project! :)

guantolento
Posts: 172
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: How to check presence of Beacon ?

Post by guantolento » Tuesday 05 September 2017 23:40

solidum90 wrote:
Tuesday 05 September 2017 22:40
Hello to everyone,
this script works great.. but I have two questions:

I have a nut 3 Beacon, when the Beacon is associated iphone's app this script doesn't see beacon, is it correct?
There's no way to works both ?

Otherwise, can not you run this script even to detect iphone?
(I try to add my iphone on TAG_DATA but it doesn't work)

Thanks to everyone and congratulations for this project! :)
Hi, i think the nut can't work in 2 system. Actually i have 5 nut and all work ok, but no nut is connected to the app.
But i'm waiting a response from Mr. Emme.
Bye Bye.
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F

User avatar
emme
Posts: 615
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: How to check presence of Beacon ?

Post by emme » Wednesday 06 September 2017 8:35

solidum90 wrote:
Tuesday 05 September 2017 22:40
when the Beacon is associated iphone's app this script doesn't see beacon, is it correct?
unfortunately yes :(
if the BLE is paired than it disappear from the scan, unfortunately there is no workaround to have it works either way

presence of iOS devices is quite wired...
since they do NOT reply to WLAN ping, it looks they do on Bluetooth...
so you could use hcitool scan (instead of lescan) to identify it, of course you cannot use gatttool for battery, but you could only discover its presence

just remember to leave bt On on the device ;)
ciao
M
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
solidum90
Posts: 35
Joined: Tuesday 01 August 2017 20:59
Target OS: NAS (Synology & others)
Domoticz version: Debian
Location: Milan
Contact:

Re: How to check presence of Beacon ?

Post by solidum90 » Wednesday 06 September 2017 10:28

emme wrote:
Wednesday 06 September 2017 8:35
solidum90 wrote:
Tuesday 05 September 2017 22:40
when the Beacon is associated iphone's app this script doesn't see beacon, is it correct?
unfortunately yes :(
if the BLE is paired than it disappear from the scan, unfortunately there is no workaround to have it works either way

presence of iOS devices is quite wired...
since they do NOT reply to WLAN ping, it looks they do on Bluetooth...
so you could use hcitool scan (instead of lescan) to identify it, of course you cannot use gatttool for battery, but you could only discover its presence

just remember to leave bt On on the device ;)
ciao
M
Thanks for reply (sei italiano? ;) )

I found a "workaround", I use l2ping on inside an ula script that they already use to detect presence with ping, but with iphone has no sense because when it is locked it does not respond to ping.
Then I use your script to query the nut.
In this way if the nut is connected to the ap I ping iphone via l2ping, otherwise I query the nut directly.
Every minute runs an ula script that verifies if at least one device responds to determining the presence.
Is it a good way?

This is a part of my ula script:

Code: Select all

DisposiviPresenza = {};
DisposiviPresenza[1] = {nome="iPhoneLorenzo", ip = "ip.xxx.xxx.xxx", bluetooth="mac:xx:xx:xx:xx:xx"}

-- ping dispositivi di presenza
for i, v in pairs(DisposiviPresenza) do
    local ping = false;
    local string;
    
    if v.bluetooth  ~= nil then
        
        string = 'l2ping -c1 -s32 -t1 '..v.bluetooth
        TraceLog ("l2ping : " .. string)
        ping = os.execute(string); 
        if (ping) then 
            TraceLog ("==> "..v.nome.." ping OK")
        else
            TraceLog ("==> "..v.nome.." ping NOK")
        end
        
    end
    
    if not ping and v.ip  ~= nil then
        
        string = 'ping -c 1 -w 1 '..v.ip
        TraceLog (">ping : " .. string)
        ping = os.execute(string); 
        if (ping) then 
            TraceLog ("==> "..v.nome.." ping OK")
        else
            TraceLog ("==> "..v.nome.." ping NOK")
        end
    
    end
   
    ping_success = ping_success or ping
end


User avatar
emme
Posts: 615
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: How to check presence of Beacon ?

Post by emme » Wednesday 06 September 2017 10:51

solidum90 wrote:
Wednesday 06 September 2017 10:28
Thanks for reply (sei italiano? )
..abbastanza :lol: (Milano ;) )

I think your script is GREAT solution
I did not knew the iOS device does not reply in standby mode (thanks Apple! :( ) and your way to seek for the device and then the nut is good!

ciao
M
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
solidum90
Posts: 35
Joined: Tuesday 01 August 2017 20:59
Target OS: NAS (Synology & others)
Domoticz version: Debian
Location: Milan
Contact:

Re: How to check presence of Beacon ?

Post by solidum90 » Wednesday 06 September 2017 11:01

emme wrote:
Wednesday 06 September 2017 10:51
solidum90 wrote:
Wednesday 06 September 2017 10:28
Thanks for reply (sei italiano? )
..abbastanza :lol: (Milano ;) )

I think your script is GREAT solution
I did not knew the iOS device does not reply in standby mode (thanks Apple! :( ) and your way to seek for the device and then the nut is good!

ciao
M
Allora siamo anche vicini di casa (io Monza :p)
Always say thanks to Apple (my girlfriend given iphone, otherwise I would never have taken it! :p)

PABben
Posts: 80
Joined: Friday 31 January 2014 15:32
Target OS: Windows
Domoticz version:
Location: Norway
Contact:

Re: How to check presence of Beacon ?

Post by PABben » Sunday 15 October 2017 14:00

I do have problems understanding the concept of user variables and thus getting the script to work with domoticz.

I've installed the script and manually running the script gives me a log file without errors:
Spoiler: show

Code: Select all

2017-10-15 00:59:48,085 - root - DEBUG - Tag Mi_band is still there with an RSSI of -84  : update presence with RSSI
2017-10-15 00:59:48,091 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): localhost
2017-10-15 00:59:48,095 - requests.packages.urllib3.connectionpool - DEBUG - http://localhost:8080 "GET /json.htm?type=command&param=updateuservariable&idx=1226&vname=Mi_band&vtype=2&vvalue=-84 HTTP/1.1" 200 58
2017-10-15 00:59:48,098 - root - DEBUG -  <Thread(Thread-312, started 140169388463872)> -> <Response [200]>
2017-10-15 00:59:48,633 - root - DEBUG - Tag Mi_band Detected e4:26:0a:74:c3:50 - RSSI (-87,) - DATA unknown (80,)
2017-10-15 00:59:50,851 - root - DEBUG - Tag Mi_band Detected e4:26:0a:74:c3:50 - RSSI (-90,) - DATA unknown (80,)
2017-10-15 00:59:54,149 - root - DEBUG - Tag Mi_band Detected e4:26:0a:74:c3:50 - RSSI (-86,) - DATA unknown (80,)
2017-10-15 00:59:54,153 - root - DEBUG - Tag Mi_band is still there with an RSSI of -86  : update presence with RSSI
2017-10-15 00:59:54,156 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): localhost
2017-10-15 00:59:54,160 - requests.packages.urllib3.connectionpool - DEBUG - http://localhost:8080 "GET /json.htm?type=command&param=updateuservariable&idx=1226&vname=Mi_band&vtype=2&vvalue=-86 HTTP/1.1" 200 58
2017-10-15 00:59:54,163 - root - DEBUG -  <Thread(Thread-313, started 140169388463872)> -> <Response [200]>
2017-10-15 00:59:56,356 - root - DEBUG - Tag Mi_band Detected e4:26:0a:74:c3:50 - RSSI (-64,) - DATA unknown (80,)
I have made a virtual/dummy switch with idx 1226 and "tag_data" from the script is as following:
Spoiler: show

Code: Select all

TAG_DATA = [  
            ["Mi_band","e4:26:0a:74:c3:50",15,0,1226,REPEAT_MODE],
            ["pab_sonyx2","30:a8:db:7d:51:a7",15,0,1227,REPEAT_MODE]
           ]
I did expect the script to update my virtual switch, but i assume this is where the user variable comes in. In my head the variable name is the name of the script, but what should the script contain and how can i get this lua(?) script/variable to update the dummy switch?

PS! Running the script as a service fails. I don't know if this is relevant as the script seems to work by manually starting the script.
Spoiler: show

Code: Select all

[email protected]:~/domoticz/scripts$ sudo /etc/init.d/check_beacon_presence start
[sudo] passord for pabben: 
[ ok ] Starting check_beacon_presence (via systemctl): check_beacon_presence.service.
[email protected]:~/domoticz/scripts$ sudo systemctl status check_beacon_presence.service -l
● check_beacon_presence.service - check_beacon_presence Service
   Loaded: loaded (/lib/systemd/system/check_beacon_presence.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since sø. 2017-10-15 13:54:39 CEST; 6s ago
  Process: 29551 ExecStart=/usr/local/bin/check_beacon_presence.py (code=exited, status=1/FAILURE)
 Main PID: 29551 (code=exited, status=1/FAILURE)

okt. 15 13:54:39 linux-pab systemd[1]: Started check_beacon_presence Service.
okt. 15 13:54:39 linux-pab check_beacon_presence.py[29551]: Traceback (most recent call last):
okt. 15 13:54:39 linux-pab check_beacon_presence.py[29551]:   File "/usr/local/bin/check_beacon_presence.py", line 77, in <module>
okt. 15 13:54:39 linux-pab check_beacon_presence.py[29551]:     import requests
okt. 15 13:54:39 linux-pab check_beacon_presence.py[29551]: ImportError: No module named requests
okt. 15 13:54:39 linux-pab systemd[1]: check_beacon_presence.service: Main process exited, code=exited, status=1/FAILURE
okt. 15 13:54:39 linux-pab systemd[1]: check_beacon_presence.service: Unit entered failed state.
okt. 15 13:54:39 linux-pab systemd[1]: check_beacon_presence.service: Failed with result 'exit-code'.
[email protected]:~/domoticz/scripts$ sudo pip install requests
The directory '/home/pabben/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/pabben/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: requests in /home/pabben/.local/lib/python2.7/site-packages

User avatar
emme
Posts: 615
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: How to check presence of Beacon ?

Post by emme » Sunday 15 October 2017 14:24

The external script does update a user variable, if you want to act a device istead you have 2 ways:

1) change the script in order to
  • replace HOME/AWAY with On/Off
  • do not use REPEAT_MODE but only SWITCH_MODE
  • change the http request to update the variable with the request to update a switch
OR....
use a UserVariable event in domoticz by which you switch a device based on the variable...
for my needs I used this way and here is the portion of my script that apply a device..
note that both user variable and switch have the same name and same prefix (NUT_*)
ciao
M

Code: Select all

return {
	active = true,
	on = {	variables = { 'NUT_*' }	},
	logging = {
        level = domoticz.LOG_FORCE,
        marker = "[NUT Script] ==> "
        },
        execute = function(dz, nVar)
            if nVar.value == 'AWAY' then
                dz.devices(nVar.name).switchOff().checkFirst()
            else
               dz.devices(nVar.name).switchOn().checkFirst()
            end
        end
 }
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

Ascari
Posts: 4
Joined: Thursday 28 September 2017 21:35
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by Ascari » Wednesday 18 October 2017 15:48

Any Solution with Synology ?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests