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.
User avatar
emme
Posts: 835
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 22 July 2018 9:39

does the service quits or is it still alive?
by issuing a systemctl status check_beacon_presence you sould get something like:
Active: active (running)
and not
Active: active (dead)
or
Active: kill
or something else

if so... the script encounter an error and must be checked

most of the times errors are generated by interface (hci0) unavailability
if you have other applications that use hci0 (even issuing a hcitool lescan while the service is running will hang the service) you have to remeber to reset the interface afer each use to get the service work back again

Due to these issues I moved to nodeRed to check beacons and it works quite good!!
ciao
M
That's one small step for a programmer, one giant leap for me!
- - - - -
rPI 3b+ zWave + rfxComm + nodeMcu + mySensors

redfirebrooks
Posts: 16
Joined: Sunday 07 January 2018 16:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by redfirebrooks » Monday 23 July 2018 13:27

Hello,

I bought 2 nut find 3 and i'd like to use them as beacon.
I tried to follow the tutorial here https://www.domoticz.com/wiki/Presence_ ... _Beacon%29
but I have this message when testing ;

Code: Select all

pi@domoticz:~ $ sudo python test_beacon.py
Traceback (most recent call last):
  File "test_beacon.py", line 31, in <module>
    import bluetooth._bluetooth as bluez
ImportError: No module named bluetooth._bluetooth
I have a RPI3

User avatar
emme
Posts: 835
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 23 July 2018 14:14

looks like you miss the bluetooth stack for python

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
That's one small step for a programmer, one giant leap for me!
- - - - -
rPI 3b+ zWave + rfxComm + nodeMcu + mySensors

redfirebrooks
Posts: 16
Joined: Sunday 07 January 2018 16:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by redfirebrooks » Monday 23 July 2018 14:31

Thanks, but still no luck

Code: Select all

pi@domoticz:~ $ sudo python test_beacon.py
Traceback (most recent call last):
  File "test_beacon.py", line 33, in <module>
    import requests
ImportError: No module named requests
Ok solved installing some more packages

Running test_beacon.py I have endless lines...

Code: Select all

2018-07-23 19:14:16,543 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -78. DATA (-36,)
2018-07-23 19:14:16,570 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -59. DATA (0,)
2018-07-23 19:14:16,680 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -62. DATA (53,)
2018-07-23 19:14:16,751 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -59. DATA (0,)
2018-07-23 19:14:16,795 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -68. DATA (-36,)
2018-07-23 19:14:16,830 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -81. DATA (-53,)
2018-07-23 19:14:16,932 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -59. DATA (0,)
2018-07-23 19:14:16,965 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -88. DATA (-53,)
2018-07-23 19:14:17,015 - root - DEBUG - Tag c2:89:4e:74:07:0b is back after 1 sec. (Max 2). RSSI -89. DATA (-10,)
2018-07-23 19:14:17,056 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -79. DATA (-36,)
2018-07-23 19:14:17,100 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -82. DATA (-53,)
2018-07-23 19:14:17,115 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -59. DATA (0,)
2018-07-23 19:14:17,190 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -62. DATA (53,)
2018-07-23 19:14:17,233 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -76. DATA (-53,)
2018-07-23 19:14:17,299 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -60. DATA (0,)
2018-07-23 19:14:17,312 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -71. DATA (-36,)
2018-07-23 19:14:17,363 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -85. DATA (-53,)
2018-07-23 19:14:17,443 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -63. DATA (53,)
2018-07-23 19:14:17,481 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -61. DATA (0,)
2018-07-23 19:14:17,499 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -87. DATA (-53,)
2018-07-23 19:14:17,572 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -82. DATA (-36,)
2018-07-23 19:14:17,629 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -85. DATA (-53,)
2018-07-23 19:14:17,665 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -61. DATA (0,)
2018-07-23 19:14:17,698 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -62. DATA (53,)
2018-07-23 19:14:17,764 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -82. DATA (-53,)
2018-07-23 19:14:17,825 - root - DEBUG - Tag c2:89:4e:74:07:0b is back after 0 sec. (Max 2). RSSI -88. DATA (-10,)
2018-07-23 19:14:17,838 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -82. DATA (-36,)
2018-07-23 19:14:17,851 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -49. DATA (0,)
2018-07-23 19:14:17,895 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -73. DATA (-53,)
2018-07-23 19:14:17,953 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -64. DATA (53,)
2018-07-23 19:14:18,027 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -70. DATA (-53,)
2018-07-23 19:14:18,032 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -65. DATA (0,)
2018-07-23 19:14:18,097 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -80. DATA (-36,)
2018-07-23 19:14:18,159 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -88. DATA (-53,)
2018-07-23 19:14:18,208 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -62. DATA (53,)
2018-07-23 19:14:18,213 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -64. DATA (0,)
2018-07-23 19:14:18,291 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -83. DATA (-53,)
2018-07-23 19:14:18,359 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -71. DATA (-36,)
2018-07-23 19:14:18,423 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -83. DATA (-53,)
2018-07-23 19:14:18,585 - root - DEBUG - Tag 65:21:da:b6:04:12 is back after 0 sec. (Max 0). RSSI -58. DATA (0,)
2018-07-23 19:14:18,617 - root - DEBUG - Tag 56:71:82:fd:19:12 is back after 0 sec. (Max 0). RSSI -82. DATA (-36,)
2018-07-23 19:14:18,637 - root - DEBUG - Tag c2:89:4e:74:07:0b is back after 0 sec. (Max 2). RSSI -98. DATA (-10,)
2018-07-23 19:14:18,688 - root - DEBUG - Tag 47:78:82:9e:69:92 is back after 0 sec. (Max 0). RSSI -82. DATA (-53,)
2018-07-23 19:14:18,722 - root - DEBUG - Tag da:06:c2:e1:01:15 is back after 0 sec. (Max 0). RSSI -46. DATA (53,)
How should I select the NUT beacon ?

Frucoboti
Posts: 6
Joined: Thursday 17 May 2018 1:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to check presence of Beacon ?

Post by Frucoboti » Sunday 12 August 2018 23:04

emme wrote:
Sunday 22 July 2018 9:39
does the service quits or is it still alive?
by issuing a systemctl status check_beacon_presence you sould get something like:
Active: active (running)
and not
Active: active (dead)
or
Active: kill
or something else

if so... the script encounter an error and must be checked

most of the times errors are generated by interface (hci0) unavailability
if you have other applications that use hci0 (even issuing a hcitool lescan while the service is running will hang the service) you have to remeber to reset the interface afer each use to get the service work back again

Due to these issues I moved to nodeRed to check beacons and it works quite good!!
ciao
M
Hello, thanks for your answer. I have been on holidays since today.

I have been seeing that something in my Raspbian happens every hour, at hour:00 time. Then the script stops without exiting or anything:
Spoiler: show
2018-08-12 21:59:59,356 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-70,) - DATA unknown (85,)
2018-08-12 21:59:59,997 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-63,) - DATA unknown (85,)
2018-08-12 22:00:00,317 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-56,) - DATA unknown (85,)
2018-08-12 22:00:00,636 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-72,) - DATA unknown (85,)
2018-08-12 22:00:00,961 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-62,) - DATA unknown (85,)
2018-08-12 22:00:01,288 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-79,) - DATA unknown (85,)
2018-08-12 22:00:01,933 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-60,) - DATA unknown (85,)
2018-08-12 22:00:02,584 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-77,) - DATA unknown (85,)
2018-08-12 22:00:02,903 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-70,) - DATA unknown (85,)
2018-08-12 22:00:02,989 - root - DEBUG - Tag Tag_Mami Detected d6:19:04:59:11:d6 - RSSI (-81,) - DATA unknown (-42,)
2018-08-12 22:00:03,221 - root - DEBUG - Tag Tag_PasFco Detected c4:ab:d1:fd:87:55 - RSSI (-60,) - DATA unknown (85,)
2018-08-12 22:00:29,258 - root - WARNING - Tag Tag_Papi not seen since 34 sec => update absence
2018-08-12 22:00:29,273 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): 192.168.1.125
2018-08-12 22:00:29,282 - requests.packages.urllib3.connectionpool - DEBUG - http://192.168.1.125:8090 "GET /json.htm?type=command&dparam=updateuservariable&idx=4&vname=Tag_Papi&vtype=2&vvalue=AWAY HTTP/1.1" 200 58
2018-08-12 22:00:29,289 - root - DEBUG - <Thread(Thread-13, started daemon 1969222768)> -> <Response [200]>
2018-08-12 22:00:34,263 - root - WARNING - Tag Tag_Mami not seen since 31 sec => update absence
2018-08-12 22:00:34,270 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): 192.168.1.125
2018-08-12 22:00:34,270 - root - WARNING - Tag Tag_PasFco not seen since 31 sec => update absence
2018-08-12 22:00:34,281 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): 192.168.1.125
2018-08-12 22:00:34,284 - requests.packages.urllib3.connectionpool - DEBUG - http://192.168.1.125:8090 "GET /json.htm?type=command&dparam=updateuservariable&idx=3&vname=Tag_Mami&vtype=2&vvalue=AWAY HTTP/1.1" 200 58
2018-08-12 22:00:34,289 - requests.packages.urllib3.connectionpool - DEBUG - http://192.168.1.125:8090 "GET /json.htm?type=command&dparam=updateuservariable&idx=7&vname=Tag_PasFco&vtype=2&vvalue=AWAY HTTP/1.1" 200 58
2018-08-12 22:00:34,290 - root - DEBUG - <Thread(Thread-14, started daemon 1969222768)> -> <Response [200]>
2018-08-12 22:00:34,294 - root - DEBUG - <Thread(Thread-15, started daemon 1958737008)> -> <Response [200]>
I can paste full log from the last start of the service, but I think that there is anything special, all normal. The last lines are the above, and since this Response 200, no more...

The service still running:
Spoiler: show
pi@raspberrypi:~ $ sudo systemctl status check_beacon_presence.service
* check_beacon_presence.service - check_beacon_presence Service
Loaded: loaded (/lib/systemd/system/check_beacon_presence.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-08-12 21:42:02 CEST; 1h 15min ago
Main PID: 19870 (check_beacon_pr)
CGroup: /system.slice/check_beacon_presence.service
`-19870 /usr/bin/python /usr/local/bin/check_beacon_presence.py

ago 12 21:42:02 raspberrypi systemd[1]: Started check_beacon_presence Service.
ago 12 21:42:03 raspberrypi sudo[19880]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/hciconfig hci0 down
ago 12 21:42:03 raspberrypi sudo[19880]: pam_unix(sudo:session): session opened for user root by (uid=0)
ago 12 21:42:03 raspberrypi sudo[19880]: pam_unix(sudo:session): session closed for user root
ago 12 21:42:03 raspberrypi sudo[19889]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/hciconfig hci0 up
ago 12 21:42:03 raspberrypi sudo[19889]: pam_unix(sudo:session): session opened for user root by (uid=0)
ago 12 21:42:03 raspberrypi sudo[19889]: pam_unix(sudo:session): session closed for user root
ago 12 21:42:03 raspberrypi sudo[19898]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/hciconfig
ago 12 21:42:03 raspberrypi sudo[19898]: pam_unix(sudo:session): session opened for user root by (uid=0)
ago 12 21:42:03 raspberrypi sudo[19898]: pam_unix(sudo:session): session closed for user root
And daemon.log shows:
Spoiler: show
Aug 12 21:42:02 raspberrypi systemd[1]: Started check_beacon_presence Service.
Aug 12 21:44:00 raspberrypi mosquitto[380]: 1534103040: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
Aug 12 21:46:52 raspberrypi systemd[1]: Started Session c4 of user pi.
Aug 12 22:14:01 raspberrypi mosquitto[380]: 1534104841: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
Aug 12 22:44:02 raspberrypi mosquitto[380]: 1534106642: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
I am using internal RP3 BT, and acquiring info for Xiaomi Mi Flower Plan too, with another script that no stops never.

How can I check what is happening every hour?

BTW, someone knows a better way to do the same?

Lot of thanks.

User avatar
emme
Posts: 835
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 » Thursday 16 August 2018 17:08

uh... do you have another script that uses hci (bluetooth LE interface) for doing something else?

that could be the issue! the script uses hci in exclusive mode, if someting else uses the same hci it would be unavailable to the script since its reset

I see by the log that tah_papi and tag_mami are coorectly setted as AWAY (response 200)
...I do believe the problem is on the interface unavailability.... can you try to stop the other script for a couple of days?



P.S.
are you italian?
That's one small step for a programmer, one giant leap for me!
- - - - -
rPI 3b+ zWave + rfxComm + nodeMcu + mySensors

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest