Page 2 of 19
Re: How to check presence of Beacon ?
Posted: Friday 06 May 2016 23:49
by woody4165
VERY NICE!!!!!
It's working.
I need to launch with sudo (don't know why).
When the python script has been launched it remains running without exiting, right?
So it should not be launched by crontab, how can I launch it when the RPi boot (or reboot)?
Then the uservariable can be checked in a Lua Device script (better that time one?) ?
Thanks again for sharing!!!!!
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 8:15
by korniza
I runned for some hours and I see that script random lose all BLE NUT (AWAY) for a while. Also if script restarted and beacons are labeled as HOME, but they moved away, script does not put them away. still it is unstable comparing to FHEM. Still it is a good start and promising to get a domoticz service for BLE presence.

Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 9:49
by jmleglise
@korniza :
you need continuous update only for "presence" ? right ? (not for "absence")
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 9:52
by jmleglise
@woody :
For using user variables in Lua scripts, there are three tables available: uservariables, uservariables_lastupdate and
uservariablechanged. The uservariablechanged table (with only the variable that triggered the event) is only available in your event scripts (script_variable_name.lua), the other two are always available. Reference your variable by name, e.g. if uservariables["MyVar"] = ...
Have a look here :
https://www.domoticz.com/wiki/Events
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 9:56
by jmleglise
@woody
My script is multi thread. No crontab , a service is better to start with raspberry. I will look after that later.
TODO :
- Transform this script in a linux service (/etc/init.d) ...
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 11:45
by korniza
jmleglise wrote:@korniza :
you need continuous update only for "presence" ? right ? (not for "absence")
not only for presence. I need also to arm security panel, so if a sensor in home activated (when i am away) to do some sttuff (send sms for example)
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 14:04
by jmleglise
korniza,
I'm not sure to understand you well. Could you precise your needs ?
For example :
- My tag broadcasts at different rate. Sometimes every 4 secondes and sometimes several times per secondes. Do you want that domoticz is updated at the same frequency ? (This will conduct to an issue : Several times per secondes can cause a saturation of the server)
- if the tag is away : how frequently should domoticz be updated ?
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 14:42
by jmleglise
and get my update :
Version : 1.1 Log + Mac Adress case insensitive
https://github.com/jmleglise/mylittle-d ... resence.py
With the verbose log system, you may follow how does your beacon work.
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 15:16
by woody4165
Is it normal that I get this CPU % from the python script, the only one that is running since I'm on an RPi3 where is located Domoticz, but not running since it's a test environment, and no other stuff?
Code: Select all
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
xxxx root 20 0 43128 11796 6068 S 110,4 1,2 7:42.64 python
Cpu temp also raised more than 60°C from normal 40°C.
Is it because I'm running (don't know why, but for me the only way) as "sudo python" ?
I launched it as
Code: Select all
sudo python check_beacon_presence &
Thanks
PS: After last update, now it seems normal CPU% use by python!!!
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 16:03
by jmleglise
korniza wrote:Also if script restarted and beacons are labeled as HOME, but they moved away, script does not put them away.
Fix in v1.2
https://raw.githubusercontent.com/jmleg ... resence.py
Could you confirm ?
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 16:13
by jmleglise
woody4165 wrote: Cpu temp also raised more than 60°C from normal 40°C.
PS: After last update, now it seems normal CPU% use by python!!!
hi,
the summer is going to be hot
I've fixed this in the v1.1
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 16:22
by jmleglise
The script takes around 0,2% CPU now. And for you ?
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 16:58
by jmleglise
And now the installation as a service (and auto run at start of the raspberryPi)
Copy the daemon file
https://raw.githubusercontent.com/jmleg ... n_presence to /etc/init.d
Code: Select all
sudo cp check_beacon_presence /etc/init.d
sudo chmod 755 /etc/init.d/check_beacon_presence
Copy the python script
https://raw.githubusercontent.com/jmleg ... resence.py to /usr/local/bin
Code: Select all
sudo cp check_beacon_presence.py /usr/local/bin
sudo chmod 755 /usr/local/bin/check_beacon_presence.py
To launch the script :
Code: Select all
sudo /etc/init.d/check_beacon_presence restart
And to run the script at each reboot of the server :
Code: Select all
sudo update-rc.d check_beacon_presence defaults
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 17:15
by woody4165
I'm getting this error on service restart
Code: Select all
[....] Restarting check_beacon_presence (via systemctl): check_beacon_presence.serviceFailed to restart check_beacon_presence.service: Unit check_beacon_presence.service failed to load: No such file or directory.
failed!
I have /usr/local/bin/check_beacon_presence.py and is set to 755 as well as the /etc/init.d/check_beacon_presence
what I can check?
Thanks
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 18:03
by jmleglise
woody4165 wrote:I'm getting this error on service restart
Code: Select all
check_beacon_presence.service failed to load: No such file or directory.
Thanks
Hi,
1/ Make sure that the both files are in UNIX format. (If DOS format, convert them. Check with nano :
sudo nano check_beacon_presence
Ctrl+o to save
Alt+d to alternate betwen DOS and Unix/Linux line-endings.
Press enter
Ctrl+x
2/ Dont' forget to modify check_beacon_presence.py to configure log to file :
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'
Then you have several command to test: start, stop, restart, status
sudo /etc/init.d/check_beacon_presence status
Does-it work ?
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 19:07
by woody4165
I have used the dos2unix command since I don't understand (in a Osx Terminal) which command should I do to convert after Ctrl-o
Shame on me!!!
I get the same error.
I checked also the log stuff but I have it on CRITICAL
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
In any case, when I created the file in /etc/init.d I did directly from terminal with sudo nano, probably was directly in Unix format.
Don't understand where is the issue on my side...
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 20:55
by woody4165
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]
Re: How to check presence of Beacon ?
Posted: Saturday 07 May 2016 21:36
by jmleglise
2 ideas :
1/ Of course, when you try to launch the service (start), you don't have an another instance still running ?
check with this :
=> reboot to be sure. and after reboot test the "status" command.
Code: Select all
sudo /etc/init.d/check_beacon_presence status
2/And in the check_beacon_presence modify the first line to root :
Re: How to check presence of Beacon ?
Posted: Sunday 08 May 2016 7:01
by woody4165
Great!
It's working now!.
First I changed the DAEMON to root in the /etc/init.d/check_beacon_presence and rebooted
Working
Then I just tried to set again pi as DAEMON, rebooted, and worked again.
I'm sure that I previously rebooted several times, but now is the working one.
Thanks again!
Just to let you know that I tried also to monitor a Mi Band 1S, but I think it doesn't transmit continuously, since I got the AWAY and HOME after a lot of time (several minutes) while for the Nut it's almost immediate!!!!
I think you need to make a Wiki on this!
Re: How to check presence of Beacon ?
Posted: Sunday 08 May 2016 8:25
by jmleglise
Good. I'am happy to hear that from you.
Yep i'll do a wiki