2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 08:11:44 +00:00

98_GEOFANCY: enhanced BTLE beacon support

git-svn-id: https://svn.fhem.de/fhem/trunk@17591 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2018-10-22 13:41:11 +00:00
parent 03f80ccc78
commit c1730901f7

View File

@ -109,14 +109,16 @@ sub GEOFANCY_CGI() {
my $long = ""; my $long = "";
my $posLat = ""; my $posLat = "";
my $posLong = ""; my $posLong = "";
my $posBeaconUUID = "";
my $posTravDist = ""; my $posTravDist = "";
my $address = "-"; my $address = "-";
my $posAddress = "-";
my $entry = ""; my $entry = "";
my $msg = ""; my $msg = "";
my $date = ""; my $date = "";
my $time = ""; my $time = "";
my $locName = ""; my $locName = "";
my $radius = ""; my $radius = 0;
my $posDistLoc = ""; my $posDistLoc = "";
my $posDistHome = ""; my $posDistHome = "";
my $locTravDist = ""; my $locTravDist = "";
@ -329,6 +331,8 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
$lat = $webArgs->{latitude}; $lat = $webArgs->{latitude};
$long = $webArgs->{longitude}; $long = $webArgs->{longitude};
$device = $webArgs->{device}; $device = $webArgs->{device};
$posLat = $lat;
$posLong = $long;
if ( defined( $webArgs->{timestamp} ) ) { if ( defined( $webArgs->{timestamp} ) ) {
my ( $sec, $min, $hour, $d, $m, $y ) = my ( $sec, $min, $hour, $d, $m, $y ) =
@ -357,20 +361,24 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
if ( defined( $webArgs->{wifiSSID} ) ); if ( defined( $webArgs->{wifiSSID} ) );
$wifiBSSID = $webArgs->{wifiBSSID} $wifiBSSID = $webArgs->{wifiBSSID}
if ( defined( $webArgs->{wifiBSSID} ) ); if ( defined( $webArgs->{wifiBSSID} ) );
$posBeaconUUID = $webArgs->{beaconUUID}
if ( defined( $webArgs->{beaconUUID} ) );
if ( defined( $webArgs->{currentLatitude} ) if (
&& defined( $webArgs->{currentLongitude} ) ) !defined( $webArgs->{currentLatitude} )
{ || !defined( $webArgs->{currentLongitude} )
if ( $webArgs->{currentLatitude} == 0 || ( $webArgs->{currentLatitude} == 0
&& $webArgs->{currentLongitude} == 0 ) && $webArgs->{currentLongitude} == 0 )
)
{ {
$posLat = $webArgs->{latitude}; $posLat = $webArgs->{latitude};
$posLong = $webArgs->{longitude}; $posLong = $webArgs->{longitude};
$posAddress = $address;
} }
else { else {
$posLat = $webArgs->{currentLatitude}; $posLat = $webArgs->{currentLatitude};
$posLong = $webArgs->{currentLongitude}; $posLong = $webArgs->{currentLongitude};
} $posAddress = $address if ( $posBeaconUUID ne "" );
} }
} }
@ -387,6 +395,9 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
$address = $webArgs->{address} $address = $webArgs->{address}
if ( defined( $webArgs->{address} ) ); if ( defined( $webArgs->{address} ) );
$device = $webArgs->{device}; $device = $webArgs->{device};
$posLat = $lat;
$posLong = $long;
$posAddress = $address;
} }
else { else {
return "fatal error"; return "fatal error";
@ -560,10 +571,7 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
readingsBulkUpdate( $hash, "lastDeviceUUID", $device ); readingsBulkUpdate( $hash, "lastDeviceUUID", $device );
readingsBulkUpdate( $hash, "lastDevice", $deviceAlias ); readingsBulkUpdate( $hash, "lastDevice", $deviceAlias );
# update local device readings if if ( $deviceAlias ne "-" ) {
# - UUID was not assigned to any resident device
# - UUID has a defined devAlias
if ( $matchingResident == 0 && $deviceAlias ne "-" ) {
$id = $locName if ( defined($locName) && $locName ne "" ); $id = $locName if ( defined($locName) && $locName ne "" );
@ -581,10 +589,23 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
my $currVal; my $currVal;
# backup last known position # backup last known position
$currReading = "currPosTime_" . $deviceAlias;
$currVal = ReadingsVal( $name, $currReading, undef );
readingsBulkUpdate( $hash, "lastPosArr_" . $deviceAlias, $currVal );
if ($currVal) {
readingsBulkUpdate( $hash, "lastPosDep_" . $deviceAlias, $time );
readingsBulkUpdate(
$hash,
"lastPosDur_" . $deviceAlias,
UConv::duration( $time, $currVal, "sec" )
);
}
foreach ( foreach (
'PosSSID', 'PosBSSID', 'PosMotion', 'PosLat', 'PosSSID', 'PosBSSID', 'PosMotion', 'PosLat',
'PosLong', 'PosDistHome', 'PosDistLoc', 'PosTravDist', 'PosLong', 'PosAddr', 'PosBeaconUUID', 'PosDistHome',
'LocTravDist', 'LocRadius' 'PosDistLoc', 'PosTravDist', 'LocTravDist', 'LocRadius'
) )
{ {
$currReading = "curr" . $_ . "_" . $deviceAlias; $currReading = "curr" . $_ . "_" . $deviceAlias;
@ -597,8 +618,12 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
readingsBulkUpdate( $hash, "currPosSSID_" . $deviceAlias, $wifiSSID ); readingsBulkUpdate( $hash, "currPosSSID_" . $deviceAlias, $wifiSSID );
readingsBulkUpdate( $hash, "currPosBSSID_" . $deviceAlias, $wifiBSSID ); readingsBulkUpdate( $hash, "currPosBSSID_" . $deviceAlias, $wifiBSSID );
readingsBulkUpdate( $hash, "currPosMotion_" . $deviceAlias, $motion ); readingsBulkUpdate( $hash, "currPosMotion_" . $deviceAlias, $motion );
readingsBulkUpdate( $hash, "currPosBeaconUUID_" . $deviceAlias,
$posBeaconUUID );
readingsBulkUpdate( $hash, "currPosLat_" . $deviceAlias, $posLat ); readingsBulkUpdate( $hash, "currPosLat_" . $deviceAlias, $posLat );
readingsBulkUpdate( $hash, "currPosLong_" . $deviceAlias, $posLong ); readingsBulkUpdate( $hash, "currPosLong_" . $deviceAlias, $posLong );
readingsBulkUpdate( $hash, "currPosAddr_" . $deviceAlias, $posAddress );
readingsBulkUpdate( $hash, "currPosTime_" . $deviceAlias, $time );
readingsBulkUpdate( $hash, "currPosDistHome_" . $deviceAlias, readingsBulkUpdate( $hash, "currPosDistHome_" . $deviceAlias,
$posDistHome ); $posDistHome );
readingsBulkUpdate( $hash, "currPosDistLoc_" . $deviceAlias, readingsBulkUpdate( $hash, "currPosDistLoc_" . $deviceAlias,
@ -639,6 +664,11 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
$currVal ); $currVal );
readingsBulkUpdate( $hash, "lastLocDep_" . $deviceAlias, readingsBulkUpdate( $hash, "lastLocDep_" . $deviceAlias,
$time ); $time );
readingsBulkUpdate(
$hash,
"lastLocDur_" . $deviceAlias,
UConv::duration( $time, $currVal, "sec" )
);
foreach ( 'Loc', 'LocLat', 'LocLong', 'LocAddr' ) { foreach ( 'Loc', 'LocLat', 'LocLong', 'LocAddr' ) {
$currReading = "curr" . $_ . "_" . $deviceAlias; $currReading = "curr" . $_ . "_" . $deviceAlias;
@ -674,8 +704,9 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
RESIDENTStk_SetLocation( RESIDENTStk_SetLocation(
$deviceAlias, $locName, $trigger, $id, $deviceAlias, $locName, $trigger, $id,
$time, $lat, $long, $address, $time, $lat, $long, $address,
$device, $radius, $posLat, $posLong, $posDistHome, $device, $radius, $posLat, $posLong,
$posDistLoc, $motion, $wifiSSID, $wifiBSSID $posDistHome, $posDistLoc, $motion, $wifiSSID,
$wifiBSSID
) if ( IsDevice( $deviceAlias, "ROOMMATE|GUEST" ) ); ) if ( IsDevice( $deviceAlias, "ROOMMATE|GUEST" ) );
} }