From ee6ce2114405851c9fd53b2392e9d533d8a0dd8a Mon Sep 17 00:00:00 2001 From: PatrickR <> Date: Fri, 22 Sep 2017 18:33:30 +0000 Subject: [PATCH] lepresenced: Version 0.83 (additional debug code, detect if already running) lepresenced-0.83-3.deb: Added. Changed init-script to systemd service. git-svn-id: https://svn.fhem.de/fhem/trunk@15118 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- .../PRESENCE/deb/lepresenced-0.83-3.deb | Bin 0 -> 7088 bytes fhem/contrib/PRESENCE/lepresenced | 25 +++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 fhem/contrib/PRESENCE/deb/lepresenced-0.83-3.deb diff --git a/fhem/contrib/PRESENCE/deb/lepresenced-0.83-3.deb b/fhem/contrib/PRESENCE/deb/lepresenced-0.83-3.deb new file mode 100644 index 0000000000000000000000000000000000000000..fc65856006f11d1125174bad5315dfe7c77938f4 GIT binary patch literal 7088 zcmai(RZtuNm#p!?;4Z=42e;tvo?yYliRu2`E$Yy5T{^d!%b>_8j1D$V{Jx8KgTQlj=0psm(+T`!$^jOaf}sLuEwI~ z#dP2`zniczGTAPh-QYe8N*w7?Q!*Nf#d^b_0owyvTgp;G0>jB&vX%a zEWgBb;==@|Ar@UTYvdg2CZb8$)r|f1mHF_-+QvRTxY!-qPy6K;Bc3}hf^s*|4qAL5 zB4Lr!swokf&-A=u{^YJHk&YF#s`6ICMlgGERYxUj` zYb5*ilU`BwGh(@yiQ@$!gl-6Zq$m=&&W{PY7e2IdhF_)G^!EN zTh!X2$Mv@4u+y&x%2UFLVf_Cd3OS&|GP%QsqKASqGj=upZ(u$D1MGkFzcJ6l!Sg@Z z8v)*Vy|s0rpx};Inxx_STG#?_pedm7{u^VcgDohwU5`%!R(&XZ>AcL#gGJ8WFkOR?LqG<$e4NZ?7LUhG)vPj!t70t zm)mdNC+~bGq}q&ljE>quI5n*w$zN%xpdR_9SxT36KS=ig+&w1EslRfPFNPuL{PNi( zze|Xu?Ot)nT_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-+TpL(h6bC7J#!sZB zBtnxc&*MOjD|K70&<8f|9D_1d1x=m&jTV=J7xqsnfDzw5J+q4XZCYo0#k7qQu=@Lc*1MJ97KY*gI|A{ zW$94yvPd26k4joT8G1=O>#!80;$2k7(}V^`&f}P>qa;M>8~oRL@bhN9oLxHz00q79 XUz-BdG7X$>{gCA=%zr)Mbaej@=q7uc literal 0 HcmV?d00001 diff --git a/fhem/contrib/PRESENCE/lepresenced b/fhem/contrib/PRESENCE/lepresenced index 3bdd67551..37052211d 100755 --- a/fhem/contrib/PRESENCE/lepresenced +++ b/fhem/contrib/PRESENCE/lepresenced @@ -34,6 +34,8 @@ use warnings; use threads; use threads::shared; +use Digest::MD5; +use Fcntl 'LOCK_EX', 'LOCK_NB'; use IO::Select; use IO::Socket::INET; @@ -56,7 +58,7 @@ use constant DEFAULT_RSSI_THRESHOLD => 10; use constant RSSI_WINDOW => 10; use constant ME => 'lepresenced'; -use constant VERSION => '0.82'; +use constant VERSION => '0.83'; use constant PIDFILE => '/var/run/' . ME . '.pid'; @@ -72,6 +74,7 @@ my %devices :shared; my @clients = (); my $syslog_level; my $debug; +my ($beacons_hcitool, $beacons_hcidump) : shared; sub syslogw { return if (scalar(@_) < 2); @@ -147,6 +150,15 @@ sub parse_options() { sub sanity_check($) { my ($legacy_mode) = @_; + + error_exit(3, "ERROR: lepresenced is already running. Exiting.") if (!flock DATA, LOCK_EX | LOCK_NB); + + # log md5 digest of lepresenced + open (my $me, "<$0"); + binmode ($me); + syslogw(LOG_INFO, "md5 digest of '%s' is: %s.", $0, Digest::MD5->new->addfile($me)->hexdigest()); + + # check if necessary external binaries exist my $ok = 1; foreach my $binary ($legacy_mode ? qw/hciconfig hcitool/ : qw/hciconfig hcitool hcidump/) { my $binpath = `which $binary 2>/dev/null`; @@ -158,7 +170,7 @@ sub sanity_check($) { $ok = 0; } } - error_exit(3, "ERROR: Exiting due to missing binaries.") if (!$ok); + error_exit(4, "ERROR: Exiting due to missing binaries.") if (!$ok); } sub update_device($$$) { @@ -191,6 +203,7 @@ sub bluetooth_scan_thread($$) { if ($_ eq 'LE Scan ...') { syslogw(LOG_INFO, "Received '%s'.", $_); } elsif (my ($fbmac, $fbname) = $_ =~ /^([\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2})\s(.*)$/i) { + $beacons_hcitool++; if ($legacy_mode) { #syslogw(LOG_DEBUG, "Received advertisement from bluetooth mac address '%s' with name '%s'.", $fbmac, $fbname); update_device($fbmac, $fbname, 'unknown'); @@ -270,6 +283,7 @@ sub bluetooth_dump_thread($) { } } elsif ($state == HCIDUMP_STATE_SCAN_RSP || $state == HCIDUMP_STATE_ADV_INT) { if ($_ =~ m/^ bdaddr ([0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}) \((Public|Random)\)$/) { + $beacons_hcidump++; $current_mac = $1; } elsif ($_ =~ m/^ Complete local name: '(.*)'$/) { $current_name = $1; @@ -329,7 +343,8 @@ sub stats_task() { $max_age = $age if (!defined($max_age) || $age > $max_age); } } - syslogw(LOG_INFO, "Active clients: %i, known devices: %i (min/max age: %s/%s)", scalar(@clients), $devices, $min_age // '%', $max_age // '%'); + syslogw(LOG_INFO, "Active clients: %i, known devices: %i (min/max age: %s/%s), received beacons (hcitool/hcidump/difference): %i/%i/%i", + scalar(@clients), $devices, $min_age // '%', $max_age // '%', $beacons_hcitool, $beacons_hcidump, abs($beacons_hcitool - $beacons_hcidump)); } sub dump_task() { @@ -343,6 +358,7 @@ sub dump_task() { $devices{$mac}{'name'} ); } + printf("Received beacons (hcitool/hcidump): %i/%i, difference: %i\n", $beacons_hcitool, $beacons_hcidump, abs($beacons_hcitool - $beacons_hcidump)); } sub cleanup_task() { @@ -473,3 +489,6 @@ for(;;) { usleep(MAINLOOP_SLEEP_US); } $server_socket->close(); + +__DATA__ +This exists to allow the locking code at the beginning of the file to work and to praise adamk's wisdom.