-
Notifications
You must be signed in to change notification settings - Fork 0
/
hopper.php
42 lines (32 loc) · 969 Bytes
/
hopper.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
<?php
//high error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
//collect apis
require('api/yocto_api.php');
require('api/yocto_humidity.php');
require('api/yocto_temperature.php');
require('api/yocto_pressure.php');
//make db available
require('db_connect.php');
YAPI::RegisterHub("callback");
$temp = YTemperature::FirstTemperature()->get_currentValue();
if (is_null($temp)){
die("No temperature sensor found");
}
$press = YPressure::FirstPressure()->get_currentValue();
if (is_null($press)) {
die("No pressure sensor found");
}
$hum = YHumidity::FirstHumidity()->get_currentValue();
if (is_null($hum)) {
die("No humidity sensor found");
}
$now = time();
$stm = $conn->prepare("INSERT INTO data(ts, temp_value, hum_value, press_value) VALUES(?, ?, ?, ?)");
$stm->execute(array($now, $temp, $hum, $press));
die("success!");
//DB Schema:
// 1 table: "data", 5 rows:
// id, time, temp_value, hum_value, press_value
?>