commit b613307a6f14c353dda24df9ce049628aee3e8b1 Author: Maximilian Giller Date: Tue Feb 21 04:29:53 2023 +0100 Initial version diff --git a/index.php b/index.php new file mode 100755 index 0000000..25bf28f --- /dev/null +++ b/index.php @@ -0,0 +1,65 @@ + date(DATE_ATOM, $last_activity) +); + +// Estimate current activity +$now = time(); +$diff = $now - $last_activity; // DIFFERENCE IN SECONDS +if ($diff >= $SLEEP_DURATION_THRESHOLD) { + $response['status'] = "Sleeping"; +} else if ($diff >= $IDLE_DURATION_THRESHOLD) { + $response['status'] = "Idle"; +} else { + $response['status'] = "Active"; +} + +// Estimated time until wake up +if ($response['status'] == "Sleeping") { + $response['time_until_wake'] = $EXPECTED_SLEEP_DURATION - $diff; +} else { + $response['time_until_wake'] = 0; +} + +// Respond with JSON +header('Content-Type: application/json'); +echo json_encode($response); + +