Пример #1
0
<?php

/**
 * Created by PhpStorm.
 * User: Íàçàð
 * Date: 16.10.2015
 * Time: 19:59
 */
header('Content-Type:application/json');
include '../../../services/InsideSensorsService.php';
$inside = new InsideSensorsService();
print "{\"data\": \"";
print $inside->getHumidity();
print "\"}";
<?php

/**
* run this script in cron every 1-5 minutest
*/
$condition = false;
require '../services/NotificationService.php';
require_once '../services/InsideSensorsService.php';
require_once '../services/OutsideSensorsService.php';
$notifications = new NotificationService();
$inside = new InsideSensorsService();
$insideT = $inside->getTemperature();
$insideH = $inside->getHumidity();
$outside = new OutsideSensorsService();
$outsideT = $outside->getTemperature();
$outsideH = $outside->getHumidity();
if ($outsideT === 'NaN' && $outsideH === 'NaN') {
    $condition = true;
}
if ($insideT === 'NaN' && $outsideH === 'NaN') {
    $condition = true;
}
if ($insideH === '0' && !file_exists("arduino.connection.inside.lock")) {
    //send notification
    $notifications->sendNotification('Inside_sensor_is_unconnected');
    $lock = fopen("arduino.connection.lock", "w");
    $date = date("Y-m-d H:i:s");
    fwrite($lock, "arduino locked at {$date} becouse inside sensors isn\\'t connected");
    fclose($lock);
} else {
    if (file_exists("arduino.connection.inside.lock")) {