mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
lepresenced: V0.92: Restart hcitool on HCI Command (forum #75559).
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@21704 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7831b8fc26
commit
121c17086e
BIN
contrib/PRESENCE/deb/lepresenced-0.92-1.deb
Normal file
BIN
contrib/PRESENCE/deb/lepresenced-0.92-1.deb
Normal file
Binary file not shown.
@ -58,7 +58,7 @@ use constant DEFAULT_RSSI_THRESHOLD => 10;
|
||||
use constant RSSI_WINDOW => 10;
|
||||
|
||||
use constant ME => 'lepresenced';
|
||||
use constant VERSION => '0.9';
|
||||
use constant VERSION => '0.92';
|
||||
|
||||
use constant PIDFILE => '/var/run/' . ME . '.pid';
|
||||
|
||||
@ -75,6 +75,7 @@ my @clients = ();
|
||||
my ($log_level, $log_target);
|
||||
my $debug;
|
||||
my ($beacons_hcitool, $beacons_hcidump) : shared = (0, 0);
|
||||
my $restart_hcitool :shared;
|
||||
|
||||
sub syslogw {
|
||||
return if (scalar(@_) < 2);
|
||||
@ -207,9 +208,15 @@ sub update_device($$$) {
|
||||
sub bluetooth_scan_thread($$) {
|
||||
my ($device, $legacy_mode) = @_;
|
||||
my $hcitool;
|
||||
$restart_hcitool = 0;
|
||||
for(;;) {
|
||||
($beacons_hcitool, $beacons_hcidump) = (0, 0);
|
||||
my $pid = open($hcitool, "-|", "stdbuf -oL hcitool -i " . $device . " lescan --duplicates 2>&1") || die('Unable to start scanning. Please make sure hcitool and stdbuf are installed!');
|
||||
while (<$hcitool>) {
|
||||
if ($restart_hcitool) {
|
||||
$restart_hcitool = 0;
|
||||
last();
|
||||
}
|
||||
chomp($_);
|
||||
if ($_ eq 'LE Scan ...') {
|
||||
syslogw(LOG_INFO, "Received '%s'.", $_);
|
||||
@ -249,7 +256,12 @@ sub bluetooth_dump_thread($) {
|
||||
|
||||
while (<$hcidump>) {
|
||||
chomp($_);
|
||||
if ($_ =~ m/^>/) {
|
||||
if ($_ =~ m/^< HCI Command: / && $beacons_hcitool > 0) { # Ignore initial settings, i. e. before first beacon
|
||||
# https://forum.fhem.de/index.php/topic,75559.msg1007719.html#msg1007719
|
||||
syslogw(LOG_WARNING, "Received '%s', telling hcidump to restart...", $_);
|
||||
$state = HCIDUMP_STATE_NONE;
|
||||
$restart_hcitool = 1;
|
||||
} elsif ($_ =~ m/^>/) {
|
||||
if ($current_mac) {
|
||||
#printf("DEBUG: mac: %s, name: '%s', rssi: %s\n", $current_mac, $current_name, $current_rssi);
|
||||
|
||||
@ -404,12 +416,12 @@ sub cleanup_task() {
|
||||
openlog(ME, 'pid', LOG_USER);
|
||||
(my $device, my $daemonize, my $listen_address, my $listen_port, $log_level, $log_target, $debug, my $legacy_mode, my $rssi_threshold) = parse_options();
|
||||
|
||||
local $SIG{INT} = local $SIG{TERM} = local $SIG{HUP} = sub {
|
||||
local $SIG{INT} = local $SIG{TERM} = local $SIG{HUP} = sub {
|
||||
syslogw(LOG_NOTICE, "Caught signal, cleaning up and exiting...");
|
||||
unlink(PIDFILE) if (-e PIDFILE);
|
||||
closelog();
|
||||
exit(1);
|
||||
};
|
||||
};
|
||||
|
||||
syslogw(LOG_NOTICE, "Version %s started (device: %s, listen addr: %s, listen port: %s, daemonize: %i, legacy mode: %i, rssi threshold: %i, log level: %i, debug: %i).",
|
||||
VERSION, $device, $listen_address, $listen_port, $daemonize, $legacy_mode, $rssi_threshold, $log_level, $debug);
|
||||
@ -449,7 +461,6 @@ for(;;) {
|
||||
syslogw(LOG_INFO, "Connection from %s:%s. Connected clients: %i.", $client_socket->peerhost(), $client_socket->peerport(), $select->count()-1);
|
||||
} else {
|
||||
sysread ($current_client, my $buf, INET_RECV_BUFFER);
|
||||
|
||||
my $disconnect;
|
||||
if ($buf) {
|
||||
chomp($buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user