No devices specified."; exit; } /** * Fetches and parses the device data from the API. * * @param string $key The device key. * @param bool $testMode Whether to use dummy test data. * @return array An associative array with device data. */ function getDeviceData($key, $testMode = false) { if ($testMode) { // Dummy test data for testing purposes return [ 'timeRemaining' => 25, // minutes remaining 'temperature' => 38, // temperature in Celsius 'autoHeat' => 'on', // autoHeat status (on/off) 'sessionLength' => 60, // total session length in minutes 'error' => null ]; } // Build the real API URL using the provided device key. // Example: https://api.controlbyweb.cloud/DAT/{key}/customState.xml $apiUrl = "https://api.controlbyweb.cloud/DAT/{$key}/customState.xml"; // Fetch the XML content from the API using file_get_contents $xmlContent = @file_get_contents($apiUrl); if ($xmlContent === false) { return [ 'timeRemaining' => null, 'temperature' => null, 'autoHeat' => null, 'sessionLength' => null, 'error' => 'Unable to fetch data' ]; } // Parse the XML content $xml = @simplexml_load_string($xmlContent); if ($xml === false) { return [ 'timeRemaining' => null, 'temperature' => null, 'autoHeat' => null, 'sessionLength' => null, 'error' => 'Invalid XML' ]; } // Extract the desired data from the XML. // Adjust the node names according to the real structure of customState.xml. $timeRemaining = (string) $xml->timeRemaining; $temperature = (string) $xml->setTemperature; // Update if the XML uses a different node name $autoHeat = (string) $xml->autoHeat; $sessionLength = (string) $xml->sessionLength; // New: total session time return [ 'timeRemaining' => is_numeric($timeRemaining) ? (int)$timeRemaining : 0, 'temperature' => $temperature, 'autoHeat' => $autoHeat, 'sessionLength' => is_numeric($sessionLength) ? (int)$sessionLength : 60, // default to 60 if not valid 'error' => null ]; } ?> Float/Spa Device Monitor

Float/Spa Device Monitor

"; // Display device header (device name) echo "
{$name}
"; // If there is an error fetching device data, display it if ($data['error']) { echo "
Error: {$data['error']}
"; } else { $sessionLength = $data['sessionLength']; // If timeRemaining is greater than 0, display countdown and progress bar if ($data['timeRemaining'] > 0) { $timeRemaining = $data['timeRemaining']; echo "
{$timeRemaining} minutes remaining (of {$sessionLength} minutes total)
"; // Use sessionLength as the maximum session time $progressPercentage = ($timeRemaining / $sessionLength) * 100; $progressPercentage = min($progressPercentage, 100); echo "
"; echo "
Temperature: {$data['temperature']}°C | AutoHeat: " . ucfirst($data['autoHeat']) . "
"; } else { // If timeRemaining is 0, display default status with temperature and autoHeat info echo "
Device ready to start
"; echo "
Temperature: {$data['temperature']}°C | AutoHeat: " . ucfirst($data['autoHeat']) . " (Session Length: {$sessionLength} minutes)
"; } } echo "
"; // End device card } ?>