//API client configuration $config = array("client_id" => $client_id, "client_secret" => $client_secret, "scope" => Netatmo\Common\NAScopes::SCOPE_READ_STATION); $client = new Netatmo\Clients\NAWSApiClient($config); //if code is provided in get param, it means user has accepted your app and been redirected here if (isset($_GET["code"])) { //get the tokens, you can store $tokens['refresh_token'] in order to quickly retrieve a new access_token next time try { $tokens = $client->getAccessToken(); } catch (Netatmo\Exceptions\NAClientException $ex) { echo "An error occured while trying to retrieve your tokens \n"; echo "Reason: " . $ex->getMessage() . "\n"; die; } //retrieve user's weather station data try { $data = $client->getData(); } catch (Netatmo\Exceptions\NAClientException $ex) { echo "An error occured while retrieving data: " . $ex->getMessage() . "\n"; die; } if (!isset($data['devices']) || !is_array($data['devices']) || count($data['devices']) < 1) { echo "User has no devices \n"; die; } //In this example, we will only deal with the first weather station linked to the user account $device = $data['devices'][0]; //last month report $reports = getMonthReport($device, $client); //Get device timezone if (!is_null($device) && !empty($device)) { if (isset($device['place']['timezone'])) {
* 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); } }
$config['client_secret'] = "client-secret-from-dev.netatmo.com"; $config['scope'] = 'read_station read_thermostat write_thermostat'; $client = new Netatmo\Clients\NAWSApiClient($config); #token $username = "******"; $pwd = "your-netatmo-password"; $client->setVariable('username', $username); $client->setVariable('password', $pwd); try { $tokens = $client->getAccessToken(); $refresh_token = $tokens["refresh_token"]; $access_token = $tokens["access_token"]; } catch (Netatmo\Exceptions\NAClientException $ex) { echo "An error occcured while trying to retrieve your tokens \n"; } $data = $client->getData(NULL, TRUE); foreach ($data['devices'] as $device) { // print_r($device['dashboard_data']); // echo "Device name: " . $device['station_name'] . "\n"; if ($argv[1] == "discovery") { echo "Device name: " . $device['station_name'] . "\n"; } elseif ($argv[1] == "data") { echo "- netatmo." . $device['station_name'] . ".main.pressure " . $device['dashboard_data']['Pressure'] . "\n"; echo "- netatmo." . $device['station_name'] . ".main.noise " . $device['dashboard_data']['Noise'] . "\n"; echo "- netatmo." . $device['station_name'] . ".main.temp " . $device['dashboard_data']['Temperature'] . "\n"; echo "- netatmo." . $device['station_name'] . ".main.humidity " . $device['dashboard_data']['Humidity'] . "\n"; echo "- netatmo." . $device['station_name'] . ".main.co2 " . $device['dashboard_data']['CO2'] . "\n"; } foreach ($device['modules'] as $module) { //print_r($module['dashboard_data']); if ($argv[1] == "discovery") {