-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
58 lines (48 loc) · 1.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/php
<?php
chdir(__DIR__);
require __DIR__.'/vendor/autoload.php';
$config = include 'config.php';
require 'Netatmo.php';
// Initialize logger
Logger::configure('config.xml');
$logger = Logger::getLogger('main');
$logger->info('Start Netatmo collect');
$logger->debug('Log level: '.$logger->getEffectiveLevel()->toString());
// Get optionnal start date from script argument
$startTimestamp = null;
if ($argc > 1) {
$startDate = date_create_from_format('Y-m-d', $argv[1]);
if ($startDate === false) {
$logger->error('Argument must be a valid start date as Y-m-d, provided: ' . $argv[1]);
exit(1);
}
$startDate->setTime(0, 0);
$startTimestamp = $startDate->getTimestamp();
$logger->info('Provided start date: ' . $startDate->format('Y-m-d H:i:sP'));
}
// Initialize wrapper
$netatmo = new Netatmo($config);
if ($netatmo->hasError) {
exit(1);
}
// Authentication with Netatmo server (OAuth2)
if (!$netatmo->getExistingTokens()) {
$logger->error('No existing token found, go to https://dev.netatmo.com/apps to get a token');
exit(1);
}
// Retrieve user's Weather Stations Information
if (!$netatmo->getStations()) {
exit(1);
}
// For each stations request measures for every modules
foreach ($netatmo->devices as $device) {
$logger->debug('Handling device: ' . $device['home_name']);
// First, get main indoor module
$netatmo->getMeasures($startTimestamp, $device, null);
// Then for its modules
foreach ($device['modules'] as $module) {
$netatmo->getMeasures($startTimestamp, $device, $module);
}
}
$logger->info('End Netatmo collect');