/** * Prints a list of devices * */ function printDevices($devices, $title = NULL) { if (!is_null($devices) && is_array($devices) && !empty($devices)) { if (!is_null($title)) { printMessageWithBorder($title); } foreach ($devices as $device) { printWSBasicInfo($device); } } }
/** * function printing a weather station or modules basic information such as id, name, dashboard data, modules (if main device), type(if module) * */ function printWSBasicInfo($device) { if (isset($device['station_name'])) { echo "- " . $device['station_name'] . " -\n"; } else { if ($device['module_name']) { echo "- " . $device['module_name'] . " -\n"; } } echo "id: " . $device['_id'] . "\n"; if (isset($device['type'])) { echo "type: "; switch ($device['type']) { // Outdoor Module case "NAModule1": echo "Outdoor\n"; break; //Wind Sensor //Wind Sensor case "NAModule2": echo "Wind Sensor\n"; break; //Rain Gauge //Rain Gauge case "NAModule3": echo "Rain Gauge\n"; break; //Indoor Module //Indoor Module case "NAModule4": echo "Indoor\n"; break; case "NAMain": echo "Main device \n"; break; } } if (isset($device['place']['timezone'])) { $tz = $device['place']['timezone']; } else { $tz = 'GMT'; } if (isset($device['dashboard_data'])) { echo "Last data: \n"; foreach ($device['dashboard_data'] as $key => $val) { if ($key === 'time_utc' || preg_match("/^date_.*/", $key)) { echo $key . ": "; printTimeInTz($val, $tz, 'j F H:i'); echo "\n"; } else { if (is_array($val)) { //do nothing : don't print historic } else { echo $key . ": " . $val; printUnit($key); echo "\n"; } } } if (isset($device['modules'])) { echo " \n\nModules: \n"; foreach ($device['modules'] as $module) { printWSBasicInfo($module); } } } echo " ---------------------- \n"; }
* Example of PARTNER Weather station API * If you need more details, please take a glance at https://dev.netatmo.com/doc */ define('__ROOT__', dirname(dirname(__FILE__))); require_once __ROOT__ . '/src/Netatmo/autoload.php'; require_once 'Utils.php'; require_once 'Config.php'; //App client configuration $config = array("client_id" => $client_id, "client_secret" => $client_secret, "username" => $test_username, "password" => $test_password); $client = new Netatmo\Clients\NAWSApiClient($config); //Authentication with Netatmo server (OAuth2) try { $tokens = $client->getAccessToken(); } catch (Netatmo\Exceptions\NAClientException $ex) { handleError("An error happened while trying to retrieve your tokens: " . $ex->getMessage() . "\n", TRUE); } try { $deviceList = $client->getPartnerDevices(); } catch (Netatmo\Exceptions\NAClientException $ex) { handleError("An error occured while retrieving device list: " . $ex->getMessage() . "\n", TRUE); } if (!isset($deviceList['weather_stations']) || empty($deviceList['weather_stations'])) { echo "No Weather stations affiliated to partner app"; } else { try { $data = $client->getData($deviceList['weather_stations'][0]); printWSBasicInfo($data['devices'][0]); } catch (Netatmo\Exceptions\NAClientException $ex) { handleError("An error occured while retrieving device data " . $ex->getMessage() . "\n", TRUE); } }