if (filemtime('/tmp/netatmo_cache') < time() - 900) { unlink('/tmp/netatmo_cache'); require_once "Netatmo-API/NAApiClient.php"; require_once "Netatmo-API/Config.php"; $client = new NAApiClient($config); $client->setVariable("username", $test_username); $client->setVariable("password", $test_password); $helper = new NAApiHelper(); try { $tokens = $client->getAccessToken(); } catch (NAClientException $ex) { echo "An error happend while trying to retrieve your tokens\n"; die; } // Retrieve User Info : $user = $client->api("getuser", "POST"); $devicelist = $client->api("devicelist", "POST"); $devicelist = $helper->SimplifyDeviceList($devicelist); $last_mesures = $helper->GetLastMeasures($client, $devicelist); file_put_contents('/tmp/netatmo_cache', serialize($last_mesures)); } else { echo "# Using cache\n"; $last_mesures = unserialize(file_get_contents('/tmp/netatmo_cache')); } foreach ($last_mesures[0]['modules'] as $module) { if ($module['module_name'] == $get_module) { echo $get_module . $get_value . ".value " . floatval($module[$get_value]); echo "\n"; die; } }
function getLastMeasures($devicelist) { $client = $_SESSION['client']; $helper = new NAApiHelper(); return $helper->GetLastMeasures($client, $devicelist); }