puh current config pre departure
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
date_default_timezone_set('America/Los_Angeles');
|
||||
# set default values
|
||||
$status = "Unchecked";
|
||||
$message = "No attempt made yet.";
|
||||
@ -8,7 +9,7 @@ $button_recent = false;
|
||||
$button_action = "";
|
||||
$button_result = "";
|
||||
$http_host = $_SERVER['HTTP_HOST'];
|
||||
|
||||
$run_file = "{{ gps_service_directory }}/gps_data";
|
||||
$debug_string = "";
|
||||
|
||||
if (isset($_GET['action'])) {
|
||||
@ -38,8 +39,11 @@ function runAPI($submitted_status) {
|
||||
// API URL
|
||||
$debug_string = $debug_string."After switch, apiUrl is ".$apiUrl."<br>";
|
||||
// Use file_get_contents or cURL to fetch the API data
|
||||
$response = file_get_contents($apiUrl);
|
||||
|
||||
try {
|
||||
$response = file_get_contents($apiUrl);
|
||||
} catch (Exception $e) {
|
||||
$response = '{ "Message": "unknowable", "Status": "unknowable" }';
|
||||
}
|
||||
if ($response === FALSE) {
|
||||
$debug_string = $debug_string."Response ERROR!!<br>";
|
||||
return "error"; // API error
|
||||
@ -52,47 +56,44 @@ function runAPI($submitted_status) {
|
||||
return isset($data['Status']) ? $data['Status'] : 'unknown';
|
||||
}
|
||||
|
||||
// | awk '{printf(\"%.5f\n\", $1)}'
|
||||
// | awk '{printf(\"%.5f\n\", $1)}'
|
||||
|
||||
|
||||
function getGPS(){
|
||||
if (!file_exists("{{ gps_service_directory }}/gps_data")) {
|
||||
return "No GPS data available.";
|
||||
}
|
||||
// check the API
|
||||
$gps_data = file_get_contents("http://172.17.0.1:5000/return_gps");
|
||||
try {
|
||||
$LAT = shell_exec("cat {{ gps_service_directory }}/gps_data | grep lat | cut -d ':' -f 2 | awk '{printf(\"%.5f\n\", $1)}')");
|
||||
$LON = shell_exec("cat {{ gps_service_directory }}/gps_data | grep lon | cut -d ':' -f 2 | awk '{printf(\"%.5f\n\", $1)}')");
|
||||
$SPEED = floatval(trim(shell_exec("cat {{ gps_service_directory }}/gps_data | grep speed | cut -d ':' -f 2)"))) * 0.62;
|
||||
} catch (Exception $e) {
|
||||
return "Failed to parse gps_data: ".$e;
|
||||
}
|
||||
$gps_data = json_decode($gps_data, true);
|
||||
|
||||
if (is_null($LAT)) {
|
||||
return "No GPS data available.";
|
||||
} catch (Exception $e){
|
||||
$gps_data = '{c}';
|
||||
}
|
||||
|
||||
//set the vars
|
||||
$LAT = $gps_data['lat'];
|
||||
$LON = $gps_data['lon'];
|
||||
$SPEED = $gps_data['speed'];
|
||||
|
||||
if (is_null($LAT) || $LAT == 0) {
|
||||
return "No GPS data available - null LAT";
|
||||
}
|
||||
if (is_null($LON)) {
|
||||
return "No GPS data available.";
|
||||
if (is_null($LON) || $LON == 0) {
|
||||
return "No GPS data available - null LON";
|
||||
}
|
||||
|
||||
return $LAT.", ".$LON.", ".$SPEED."mph";
|
||||
}
|
||||
|
||||
|
||||
// Check if the button was clicked via AJAX request
|
||||
// if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// $button_recent = true;
|
||||
// $status_at_submit = $_POST['status'];
|
||||
// echo "Set when clicked, second in code - ".$status_at_submit."<br>";
|
||||
// // Get the API result
|
||||
// $apiResult = runAPI($status_at_submit);
|
||||
// // Return the result as a JSON response
|
||||
// echo json_encode(['status' => $apiResult]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// URL of the external API
|
||||
$apiUrl = "http://172.17.0.1:5000/status";
|
||||
|
||||
// Use file_get_contents to fetch data from the API
|
||||
$response = file_get_contents($apiUrl);
|
||||
try {
|
||||
$response = file_get_contents($apiUrl);
|
||||
} catch (Exception $e) {
|
||||
$response = '{ "Message": "unknowable", "Status": "unknowable" }';
|
||||
}
|
||||
|
||||
// Check if the request was successful
|
||||
if ($response === FALSE) {
|
||||
@ -132,6 +133,10 @@ switch ($status) {
|
||||
$button_text = "Service Stopping...";
|
||||
$button_active = false;
|
||||
break;
|
||||
case "unknowable":
|
||||
$button_text = "Service Manager Down...";
|
||||
$button_active = false;
|
||||
break;
|
||||
default:
|
||||
$button_text = "Error, No Status";
|
||||
$button_active = false;
|
||||
|
||||
Reference in New Issue
Block a user