Esempio n. 1
0
<?php

$cubename_sel = $_GET['cube'];
include "../config.php";
include "aggregate_functions.php";
include "views/views.php";
$xml = simplexml_load_file($xmlfile);
foreach ($xml->Cube as $cube) {
    $cubename = $cube['name'];
    $cubetable = $cube->Table;
    $cubetablename = $cubetable['name'];
    if ($cubename == $cubename_sel) {
        foreach ($cube->Measure as $measure) {
            $measurecol = $measure['column'];
            $measurename = $measure['name'];
            if ($measurecol != "") {
                printMeasure($cubename, $measurename, $img_plus, $img_lastlink, $img_mea, $img_del);
            }
        }
        foreach ($cube->CalculatedMember as $calc_measure) {
            $calc_measurename = $calc_measure['name'];
            printMeasure($cubename, $calc_measurename, $img_plus, $img_lastlink, $img_mea, $img_del);
        }
    }
}
         handleError("An error occured while changing the device schedule: " . $ex->getMessage() . "\n", TRUE);
     }
     printMessageWithBorder("Schedule changed to testSchedule");
 }
 //Let's set this thermostat to away mode
 try {
     $client->setToAwayMode($device['_id'], $module_id);
     printMessageWithBorder($device['station_name'] . " is now in Away Mode");
 } catch (NAClientException $ex) {
     handleError("An error occured while setting the thermostat to away mode: " . $ex->getMessage() . "\n");
 }
 //Get daily measurements of the last 30 days
 $type = "temperature,max_temp,min_temp";
 try {
     $measurements = $client->getMeasure($thermData['devices'][1]['_id'], $thermData['devices'][1]['modules'][0]['_id'], "1day", $type, time() - 3600 * 24 * 30, time(), 30, FALSE, FALSE);
     printMeasure($measurements, $type, $device['place']['timezone'], "Daily Measurements of the last 30 days");
 } catch (NAClientException $ex) {
     handleError("An error occured while retrieving measures: " . $ex->getMessage() . "\n");
 }
 //Rename test schedule
 try {
     $client->renameSchedule($device['_id'], $module_id, $schedule_id, "To be deleted");
     printMessageWithBorder("Schedule renamed");
 } catch (NAClientException $ex) {
     handleError("An error occured while renaming schedule {$schedule_id}: " . $ex->getMessage() . "\n");
 }
 //switch back to previous program
 if (!is_null($currentProgram)) {
     try {
         $client->switchSchedule($device['_id'], $module_id, $currentProgram);
         printMessageWithBorder("Switching back to the original schedule");
    foreach ($device['modules'] as $module) {
        //requested data type depends on the module's type
        switch ($module['type']) {
            case "NAModule3":
                $type = "sum_rain";
                break;
            case "NAModule2":
                $type = "WindStrength,WindAngle,GustStrength,GustAngle,date_max_gust";
                break;
            case "NAModule1":
                $type = "temperature,humidity";
                break;
            default:
                $type = "temperature,Co2,humidity";
        }
        try {
            $measure = $client->getMeasure($device['_id'], $module['_id'], "1day", $type, time() - 24 * 3600 * 30, time(), 30, FALSE, FALSE);
            printMeasure($measure, $type, $tz, $module['_id'] . "'s daily measurements of the last 30 days ");
        } catch (Netatmo\Exceptions\NAClientException $ex) {
            handleError("An error occured while retrieving main device's daily measurements: " . $ex->getMessage() . "\n");
        }
    }
    //Finally, retrieve general info about last month for main device
    $type = "max_temp,date_max_temp,min_temp,date_min_temp,max_hum,date_max_hum,min_hum,date_min_hum,max_pressure,date_max_pressure,min_pressure,date_min_pressure,max_noise,date_max_noise,min_noise,date_min_noise,max_co2,date_max_co2,min_co2,date_min_co2";
    try {
        $measures = $client->getMeasure($device['_id'], NULL, "1month", $type, NULL, "last", 1, FALSE, FALSE);
        printMeasure($measures, $type, $tz, "Last month information of " . $device['_id'], TRUE);
    } catch (Netatmo\Exceptions\NAClientException $ex) {
        handleError("An error occcured while retrieving last month info: " . $ex->getMessage() . " \n");
    }
}