mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-07-17 02:07:26 +02:00
Journaling settings enhanced
This commit is contained in:
parent
bbe973ea70
commit
0ac2e784ca
9 changed files with 141 additions and 66 deletions
|
@ -3,9 +3,8 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||||
#
|
||||
#get lock event for last 20 minutes
|
||||
#cronjob interval 15 minutes
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events"
|
||||
#
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 95"
|
||||
#
|
||||
#Ilockit GPS cloud
|
||||
#
|
||||
|
@ -53,16 +52,49 @@ $ua->agent("sharee APIclient");
|
|||
$ua->credentials( 'tracking.ilockit.bike:443', 'api', "$apikeyconf{Ilockitcloud}->{username}", "$apikeyconf{Ilockitcloud}->{passwd}");
|
||||
|
||||
my $json = JSON->new->allow_nonref;
|
||||
my $response_in = {};
|
||||
my $dbh = "";
|
||||
my $owner = 183;
|
||||
|
||||
my $todo = $ARGV[1];
|
||||
my $deviceId = $ARGV[2] || "";
|
||||
my $groupId = $ARGV[2] || "";
|
||||
my $deviceId = $ARGV[3] || "";
|
||||
|
||||
open(FILE,">>$varenv{logdir}/Ilockit_cloud.log");
|
||||
print FILE "\n\n*** $now_dt\n";
|
||||
|
||||
#2022-11-08 looping and rest changed to groupId and limit (max 10000)
|
||||
#get Ilockit events by groupId
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
|
||||
my $rest = "groupId=$groupId\&limit=100";
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
my $response_in = {};
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "Ilockit $todo response_in:" . Dumper($response_in);
|
||||
|
||||
#main
|
||||
#loop operators DB
|
||||
while (my ($key, $value) = each %{ $dbt->{operator} }) {
|
||||
if($value->{database}->{dbname} && $value->{hwtype} ne "sigo"){
|
||||
print FILE "\nON----------$value->{database}->{dbname}---$now_dt | $todo\n";
|
||||
my $rows = 0;
|
||||
|
||||
my $sharee_operator = $value->{database}->{dbname};
|
||||
my $dbh = "";
|
||||
$dbh = $dbt->dbconnect_extern($sharee_operator);
|
||||
|
||||
#per cronjob once a day to get and update content with cloud device id
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_devices"
|
||||
&get_devices($dbh) if($todo eq "get_devices");
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 95"
|
||||
#in cronjob disabled
|
||||
&get_events($dbh,$response_in) if($todo eq "get_events");
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_positions 6572"
|
||||
&get_positions($dbh) if($todo eq "get_positions");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#my $endpoint = "https://tracking.ilockit.bike/api/commands";
|
||||
#utc to localtime
|
||||
sub localizedtime {
|
||||
|
@ -110,7 +142,8 @@ sub utctime {
|
|||
|
||||
#get all device localy
|
||||
sub get_devicesONcontent_all {
|
||||
my $deviceId = shift;
|
||||
my $dbh = shift;
|
||||
my $serialnr = shift || "";
|
||||
my $pref = {
|
||||
table => "content",
|
||||
fetch => "all",
|
||||
|
@ -118,18 +151,20 @@ sub get_devicesONcontent_all {
|
|||
template_id => "205",
|
||||
int13 => ">::0",
|
||||
};
|
||||
$pref->{txt22} = "ilike::$serialnr%" if($serialnr);
|
||||
my $record = $dbt->fetch_record($dbh,$pref);
|
||||
return $record;
|
||||
}
|
||||
|
||||
#get one device localy in contenttranspos to check if bike is locked
|
||||
#get last (end_time) device locally in contenttranspos to get end_time of last state
|
||||
sub get_devicesONcontenttranspos {
|
||||
my $dbh = shift;
|
||||
my $deviceId = shift;
|
||||
my $pref = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
order => "end_time",
|
||||
int13 => "$deviceId",
|
||||
#int20 => "1",#locked
|
||||
};
|
||||
my $record = $dbt->fetch_tablerecord($dbh,$pref);
|
||||
return $record;
|
||||
|
@ -138,6 +173,7 @@ sub get_devicesONcontenttranspos {
|
|||
|
||||
#get one device localy
|
||||
sub get_devicesONcontent {
|
||||
my $dbh = shift;
|
||||
my $deviceId = shift;
|
||||
my $pref = {
|
||||
table => "content",
|
||||
|
@ -151,6 +187,7 @@ sub get_devicesONcontent {
|
|||
|
||||
#get and check if theft exist in contenttranspos not older than 1 day
|
||||
sub get_devicesONcontenttheftpos {
|
||||
my $dbh = shift;
|
||||
my $key = shift;
|
||||
my $id = shift;
|
||||
my $pref = {
|
||||
|
@ -164,14 +201,13 @@ sub get_devicesONcontenttheftpos {
|
|||
}
|
||||
|
||||
|
||||
#per cronjob once a day to get and update content with cloud device id
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_devices"
|
||||
&get_devices if($todo eq "get_devices");
|
||||
sub get_devices {
|
||||
my $dbh = shift;
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/devices";
|
||||
my $rest = "";
|
||||
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
my $response_in = {};
|
||||
$response_in = decode_json($ret_json);
|
||||
|
||||
print FILE "ilockit get_devices response_in:" . Dumper($response_in);
|
||||
|
@ -209,46 +245,48 @@ sub get_devices {
|
|||
}
|
||||
}
|
||||
|
||||
}#end if($todo eq "get_devices"){
|
||||
}#end get_devices
|
||||
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 6572 20"
|
||||
#TODO
|
||||
&get_events if($todo eq "get_events");
|
||||
#get_events
|
||||
sub get_events {
|
||||
my $dbh = shift;
|
||||
$response_in = shift;
|
||||
|
||||
#1. select all devices on content
|
||||
print FILE "ilockit get_events get_devicesONcontent_all\n";
|
||||
my $record_cc = get_devicesONcontent_all();
|
||||
my $record_cc = get_devicesONcontent_all($dbh,"");
|
||||
my $today = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$today .= "Z";
|
||||
my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$from_datetime->subtract( days => 1 );
|
||||
$from_datetime .= "Z";
|
||||
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
|
||||
#$today .= "Z";
|
||||
#my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
#$from_datetime->subtract( days => 1 );
|
||||
#$from_datetime .= "Z";
|
||||
#my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
|
||||
#my $rest = "from=2021-05-31T07:44:10Z\&to=2021-06-06T07:44:10Z\&deviceId=4272";
|
||||
#my $rest = "from=2021-06-11T07:44:10Z\&to=2021-06-11T12:44:10Z\&deviceId=$deviceId";
|
||||
#
|
||||
#2. loope cloud
|
||||
|
||||
#2. loope content to get deviceId
|
||||
foreach my $id (sort { $record_cc->{$a}->{barcode} <=> $record_cc->{$b}->{barcode} } keys (%$record_cc)){
|
||||
|
||||
my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
|
||||
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "ilockit get_events response_in:" . Dumper($response_in);
|
||||
|
||||
#get Ilockit events by deviceId
|
||||
#my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
|
||||
#my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
#$response_in = decode_json($ret_json);
|
||||
#print FILE "ilockit get_events response_in:" . Dumper($response_in);
|
||||
|
||||
foreach my $resp (@{ $response_in }) {
|
||||
#if($record_cc->{$id}->{int13} eq $resp->{deviceId} && $resp->{type} eq "deviceOnline"){
|
||||
if($record_cc->{$id}->{int13} && $record_cc->{$id}->{int13} eq $resp->{deviceId} && ref($resp->{attributes}) eq "HASH" && $resp->{attributes}->{statusCode} && $resp->{attributes}->{statusCode} eq "alarm"){
|
||||
my $theft_record = get_devicesONcontenttheftpos("int01",$resp->{id});
|
||||
my $theft_record = { c_id => 0 };
|
||||
$theft_record = get_devicesONcontenttheftpos($dbh,"int01",$resp->{id});
|
||||
|
||||
print FILE "id: $resp->{id}\n";
|
||||
print FILE "deviceId: $resp->{deviceId}\n";
|
||||
print FILE "type: $resp->{type}\n";
|
||||
print FILE "statusCode: $resp->{attributes}->{statusCode}\n";
|
||||
print FILE "serverTime: $resp->{serverTime}\n\n";
|
||||
#insert theft alarm if no theft alarm with theft id
|
||||
if(!$theft_record->{c_id}){
|
||||
my $serverTime = localizedtime($resp->{serverTime});
|
||||
my $insert = {
|
||||
|
@ -268,28 +306,27 @@ sub get_events {
|
|||
};
|
||||
|
||||
my $c_id = $dbt->insert_contentoid($dbh,$insert);
|
||||
print FILE "insert sub get_events:" . Dumper($insert);
|
||||
print FILE "insert theft_record:" . Dumper($insert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}#end if($todo eq "get_events"){
|
||||
}#end get_events
|
||||
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_positions 6572"
|
||||
#2021-10-27, cron disabled, unspecific and not only alarm
|
||||
&get_positions if($todo eq "get_positions");
|
||||
sub get_positions {
|
||||
#1. select all devices on content
|
||||
my $record_cc = get_devicesONcontent_all();
|
||||
my $dbh = shift;
|
||||
|
||||
my $record_cc = get_devicesONcontent_all($dbh,"C2-04");
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/positions";
|
||||
|
||||
my $today = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$today .= "Z";
|
||||
my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$from_datetime->subtract( days => 1 );
|
||||
$from_datetime .= "Z";
|
||||
|
||||
#my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
#$from_datetime->subtract( days => 1 );
|
||||
#$from_datetime .= "Z";
|
||||
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/positions";
|
||||
#my $rest = "from=2021-06-11T07:44:10Z\&to=2021-06-11T12:44:10Z\&deviceId=$deviceId" if($deviceId);
|
||||
#my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
#$response_in = decode_json($ret_json);
|
||||
|
@ -298,27 +335,29 @@ sub get_positions {
|
|||
#2. loope cloud
|
||||
foreach my $id (sort { $record_cc->{$a}->{barcode} <=> $record_cc->{$b}->{barcode} } keys (%$record_cc)){
|
||||
|
||||
my $ctpos = get_devicesONcontenttranspos("$record_cc->{$id}->{int13}");
|
||||
my $ctpos = { c_id => 0 };
|
||||
$ctpos = get_devicesONcontenttranspos($dbh,$record_cc->{$id}->{int13});
|
||||
if($ctpos->{int20} == 1){#if locked then get position in range of end_time to now
|
||||
print FILE "record_pos.int13: $ctpos->{int13} --> lock_state:$ctpos->{int20}| end_time:$ctpos->{end_time}\n";
|
||||
print FILE "get_position deviceId: $ctpos->{int13} --> lock_state:$ctpos->{int20}| last rental end_time:$ctpos->{end_time}\n";
|
||||
|
||||
#get only positions until smartlock end_time is locked
|
||||
if($ctpos->{int13} && $ctpos->{end_time} =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/){
|
||||
$ctpos->{end_time} =~ s/\..*$//;
|
||||
my $end_time = $ctpos->{end_time};
|
||||
$end_time =~ s/\s/T/;
|
||||
$from_datetime = utctime($end_time,"0");
|
||||
my $from_datetime = utctime($end_time,"0");
|
||||
$from_datetime .= "Z";
|
||||
|
||||
#keep in mind, api-from maybe deviceTime (end_time-1) and position timestamp is serverTime+2
|
||||
my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
my $response_in = {};
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "ilockit get_positions response_in:" . Dumper($response_in);
|
||||
|
||||
foreach my $resp (@{ $response_in }) {
|
||||
if($record_cc->{$id}->{int13} eq $resp->{deviceId}){
|
||||
my $theft_record = get_devicesONcontenttheftpos("int02",$resp->{id});
|
||||
my $theft_record = get_devicesONcontenttheftpos($dbh,"int02",$resp->{id});
|
||||
print FILE "id: $resp->{id}\n";
|
||||
print FILE "deviceId: $resp->{deviceId}\n";
|
||||
print FILE "serverTime: $resp->{serverTime}\n\n";
|
||||
|
@ -350,7 +389,7 @@ sub get_positions {
|
|||
}
|
||||
}
|
||||
|
||||
}#end if($todo eq "get_positions"){
|
||||
}#end get_positions
|
||||
|
||||
|
||||
#ilockit http request
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue