public static function addLocationFromIridiumMail($header, $messageBody) { $from = $header->sender[0]->mailbox . '@' . $header->sender[0]->host; $unixtime = (int) $header->udate; //echo 'u'.$unixtime.'u'; //print_r($unixtime); $lat = getStringBetween($messageBody, 'Lat+', ' Lon'); //Lon+13.493400 Alt $lon = getStringBetween($messageBody, 'Lon+', ' Alt'); // echo 'f**k'; // echo $from; // echo $unixtime; // echo $header->fromaddress; // echo "\n"; // //echo strpos($header->fromaddress, '@msg.iridium.com'); if (strpos($header->fromaddress, '@msg.iridium.com') !== FALSE) { $sat_number = (int) str_replace('@msg.iridium.com', '', $header->fromaddress); $vehicle = Vehicle::where('sat_number', '=', $sat_number)->get(); if (isset($vehicle[0])) { echo 'Vehicle: ' . $vehicle[0]->id . "\n"; $vehicleLocation = new \App\VehicleLocation(array('lat' => $lat, 'lon' => $lon, 'vehicle_id' => $vehicle[0]->id, 'timestamp' => $unixtime, 'connection_type' => 'iridium')); $vehicleLocation->save(); return true; } else { echo "The vehicle is not added to the database:" . $sat_number . "\n"; return false; } } return false; //echo 'coord:'.$lat.','.$lon; }
/** * Execute the console command. * * @return mixed */ public function handle() { $jsonString = '[[[14.8513,22.86295],[14.143871,22.491289],[13.581425,23.040506],[11.999506,23.471668],[11.560669,24.097909],[10.771364,24.562532],[10.303847,24.379313],[9.948261,24.936954],[9.910693,25.365455],[9.319411,26.094325],[9.716286,26.512206],[9.629056,27.140953],[9.756128,27.688259],[9.683885,28.144174],[9.859998,28.95999],[9.805634,29.424638],[9.48214,30.307556],[9.970017,30.539325],[10.056575,30.961831],[9.950225,31.37607],[10.636901,31.761421],[10.94479,32.081815],[11.432253,32.368903],[11.488787,33.136996],[12.66331,32.79278],[13.08326,32.87882],[13.91868,32.71196],[15.24563,32.26508],[15.71394,31.37626],[16.61162,31.18218],[18.02109,30.76357],[19.08641,30.26639],[19.57404,30.52582],[20.05335,30.98576],[19.82033,31.75179],[20.13397,32.2382],[20.85452,32.7068],[21.54298,32.8432],[22.89576,32.63858],[23.2368,32.19149],[23.60913,32.18726],[23.9275,32.01667],[24.92114,31.89936],[25.16482,31.56915],[24.80287,31.08929],[24.95762,30.6616],[24.70007,30.04419],[25,29.238655],[25,25.6825],[25,22],[25,20.00304],[23.85,20],[23.83766,19.58047],[19.84926,21.49509],[15.86085,23.40972],[14.8513,22.86295]]]'; $posSW = getPositionFromEpak(); $vehicleLocation = new \App\VehicleLocation(array('lat' => $posSW[0], 'lon' => $posSW[1], 'vehicle_id' => 16, 'timestamp' => time(), 'connection_type' => 'epak')); $vehicleLocation->save(); $countryPolygon = json_decode($jsonString); $smallestDistance = 9999999; foreach ($countryPolygon[0] as $coordinates) { $distance = distanceGeoPoints($coordinates[1], $coordinates[0], $posSW[0], $posSW[1]); if ($distance < $smallestDistance) { $smallestDistance = $distance; $smallestDistanceCoordinates = $coordinates; } } $this->info('asdf'); $this->info($smallestDistance); if ($smallestDistance < 44448) { $this->info('sendmail!'); $message = "Hey there,\n the sea-watch is currently " . round($smallestDistance / 1852) . " Nautical Miles away from the libyan shore.\n For more infos visit app.sea-watch.org/admin/public/map.\n Best regards,\n The Sea-Watch-App Team."; sendMail('nic@transparency-everywhere.com,giorgia@sea-watch.org,axel@sea-watch.org,harald.h@sea-watch.org,reinier@sea-watch.org,ruben@sea-watch.org', 'SW2 within 24 Miles Zone', $message); } $this->info($smallestDistanceCoordinates[0] . '-' . $smallestDistanceCoordinates[1]); /*$this->info($smallestDistanceCoordinates[1]); $this->info($smallestDistanceCoordinates[0]); $this->info('Display this on the screen');*/ }