diff --git a/defaults/main.yaml b/defaults/main.yaml
index 6d1c595..d8dae47 100644
--- a/defaults/main.yaml
+++ b/defaults/main.yaml
@@ -36,6 +36,8 @@ sd_unmounted: true
arm_arch: false
+refresh_special: true
+
streamer_packages:
- ffmpeg
- alsa-utils
diff --git a/files/service_control_api/website/index.php b/files/service_control_api/website/index.php
index 06546aa..cd623ac 100644
--- a/files/service_control_api/website/index.php
+++ b/files/service_control_api/website/index.php
@@ -9,21 +9,54 @@ $button_recent = false;
$button_action = "";
$button_result = "";
$http_host = $_SERVER['HTTP_HOST'];
-$debug_string = "";
+$capture_duration = "3";
+$elapsed_time = "0";
-if (isset($_GET['action'])) {
- $debug_string = $debug_string."GET called, ".$_GET['action']."
";
- $button_recent = true;
- $button_result = runAPI($_GET['action']);
- $debug_string = $debug_string."Button Result: ".$button_result."
";
- sleep(1);
+// Service Status API Checker
+$status_API_URL = "http://172.17.0.1:5000/status";
+
+// Use file_get_contents to fetch data from the API
+try {
+ $status_API_response = file_get_contents($status_API_URL);
+} catch (Exception $e) {
+ $status_API_response = '{ "Message": "unknowable", "Status": "unknowable" }';
+}
+// Check if the request was successful
+if ($status_API_response === FALSE) {
+ $data = "Failed to fetch data.";
}
-function runAPI($submitted_status) {
- if(!isset($debug_string)){
- $debug_string = "";
+else {
+ // Decode the JSON response (assuming the API returns JSON)
+ $data = json_decode($status_API_response, true);
+ if (isset($data['Message'])) {
+ $message = $data['Message'];
+ } else {
+ $message = "No message found in the response.";
}
- $debug_string = $debug_string."runAPI called, ".$submitted_status."
";
+ if (isset($data['Status'])) {
+ $status = $data['Status'];
+ } else {
+ $status = "None";
+ }
+ if (isset($data['Elapsed_Time'])) {
+ $elapsed_time = $data['Elapsed_Time'];
+ } else {
+ $elapsed_time = "-1";
+ }
+}
+
+if (isset($_GET['new_duration'])){
+ $button_recent = true;
+ set_duration($_GET['new_duration']);
+}
+
+if (isset($_GET['action'])) {
+ $button_recent = true;
+ $button_result = service_manager($_GET['action']);
+}
+
+function service_manager($submitted_status) {
switch ($submitted_status) {
case "stop":
$apiUrl = "http://172.17.0.1:5000/stop";
@@ -35,8 +68,6 @@ function runAPI($submitted_status) {
$apiUrl = "http://172.17.0.1:5000/status";
break;
}
- // API URL
- $debug_string = $debug_string."After switch, apiUrl is ".$apiUrl."
";
// Use file_get_contents or cURL to fetch the API data
try {
$response = file_get_contents($apiUrl);
@@ -44,77 +75,15 @@ function runAPI($submitted_status) {
$response = '{ "Message": "unknowable", "Status": "unknowable" }';
}
if ($response === FALSE) {
- $debug_string = $debug_string."Response ERROR!!
";
return "error"; // API error
}
// Decode the JSON response (assuming the API returns JSON)
$data = json_decode($response, true);
- $debug_string = $debug_string."Data from API call: ".$data['Message']."
";
// Assuming the API returns a single word result (like "success", "failure", etc.)
return isset($data['Status']) ? $data['Status'] : 'unknown';
}
-// | awk '{printf(\"%.5f\n\", $1)}'
-// | awk '{printf(\"%.5f\n\", $1)}'
-
-
-function getGPS(){
- // check the API
- $gps_data = file_get_contents("http://172.17.0.1:5000/return_gps");
- try {
- $gps_data = json_decode($gps_data, true);
-
- } 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) || $LON == 0) {
- return "No GPS data available - null LON";
- }
-
- return $LAT.", ".$LON.", ".$SPEED."mph";
-}
-
-// URL of the external API
-$apiUrl = "http://172.17.0.1:5000/status";
-
-// Use file_get_contents to fetch data from the API
-try {
- $response = file_get_contents($apiUrl);
-} catch (Exception $e) {
- $response = '{ "Message": "unknowable", "Status": "unknowable" }';
-}
-
-// Check if the request was successful
-if ($response === FALSE) {
- $data = "Failed to fetch data.";
-}
-else {
- // Decode the JSON response (assuming the API returns JSON)
- $data = json_decode($response, true);
- // If you want to display specific data, adjust this part
- // For example, if the API returns a 'message' key, display it
- if (isset($data['Message'])) {
- $message = $data['Message'];
- } else {
- $message = "No message found in the response.";
- }
- if (isset($data['Status'])) {
- $status = $data['Status'];
- } else {
- $status = "None";
- }
-}
-
switch ($status) {
case "active":
$button_text = "Stop Service";
@@ -168,6 +137,133 @@ if($button_recent){
exit(); // Always include exit() after headers are sent
}
+
+function duration_button_handler($button_ID, $function) {
+ // Duration Status API Checker
+ $duration_API_URL = "http://172.17.0.1:5000/check_duration";
+
+ // Use file_get_contents to fetch data from the API
+ try {
+ $duration_API_URL = file_get_contents($duration_API_URL);
+ } catch (Exception $e) {
+ $duration_API_URL = '{ "Message": "unknowable", "Status": "unknowable" }';
+ }
+ // Check if the request was successful
+ if ($duration_API_URL === FALSE) {
+ $raw_duration = "Failed to fetch data.";
+ }
+
+ else {
+ // Decode the JSON response (assuming the API returns JSON)
+ $raw_duration = json_decode($duration_API_URL, true);
+ if (isset($raw_duration['duration'])) {
+ $capture_duration = $raw_duration['duration'];
+ } else {
+ $capture_duration = "3";
+ }
+ }
+
+
+ // Service Status API Checker
+ $status_API_URL = "http://172.17.0.1:5000/status";
+
+ // Use file_get_contents to fetch data from the API
+ try {
+ $status_API_response = file_get_contents($status_API_URL);
+ } catch (Exception $e) {
+ $status_API_response = '{ "Message": "unknowable", "Status": "unknowable" }';
+ }
+ // Check if the request was successful
+ if ($status_API_response === FALSE) {
+ $data = "Failed to fetch data.";
+ }
+
+ else {
+ // Decode the JSON response (assuming the API returns JSON)
+ $data = json_decode($status_API_response, true);
+ if (isset($data['Message'])) {
+ $message = $data['Message'];
+ } else {
+ $message = "No message found in the response.";
+ }
+ if (isset($data['Status'])) {
+ $status = $data['Status'];
+ } else {
+ $status = "None";
+ }
+ }
+
+ # function 0 - return class string
+ # function 1 - return active string
+ switch ($function) {
+ case "0":
+ # these classes are weird because reasons
+ # specifically because the classes are named
+ # based on service status
+ # to decode this, inactive is green
+ # and deactivating is blue
+ # so all the selectable buttons are blue and the active one is green
+ if($button_ID == $capture_duration){
+ return "inactive";
+ }
+ else {
+ return "selected";
+ }
+ break;
+
+ case "1":
+ # this disables clicking the active button
+ if($status == "active") {
+ return " disabled";
+ }
+ else if($button_ID == $capture_duration){
+ return " disabled";
+ }
+ else {
+ return "";
+ }
+ break;
+
+ default:
+ break;
+ }
+
+}
+
+# this will be an integer from 0-3 for
+# 30min, 1hr, 2hr, and 6rh respectively
+# info = {
+# "duration": new_duration
+# }
+function set_duration($duration) {
+ switch ($duration) {
+ case "0":
+ $apiUrl = "http://172.17.0.1:5000/store_duration?new_duration=0";
+ break;
+ case "1":
+ $apiUrl = "http://172.17.0.1:5000/store_duration?new_duration=1";
+ break;
+ case "2":
+ $apiUrl = "http://172.17.0.1:5000/store_duration?new_duration=2";
+ break;
+ case "3":
+ $apiUrl = "http://172.17.0.1:5000/store_duration?new_duration=3";
+ break;
+ default:
+ $apiUrl = "http://172.17.0.1:5000/status";
+ break;
+ }
+ try {
+ $response = file_get_contents($apiUrl);
+ } catch (Exception $e) {
+ $response = '{ "Message": "unknowable", "Status": "unknowable" }';
+ }
+ if ($response === FALSE) {
+ return "error"; // API error
+ }
+}
+
+
?>
@@ -185,22 +281,53 @@ if($button_recent){
+ +
++
";
+ if ($status == "active"){
+ echo "Time Elapsed:
".htmlspecialchars($elapsed_time)."s
";
+ }
echo "Current Date:
".date("F j, Y, g:i:s a")."
";
- echo "Current GPS Data:
".getGPS();
?>
+