-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRosenberg.php
126 lines (109 loc) · 4.42 KB
/
Rosenberg.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once(dirname(__FILE__)).'/MQTTProcessor.php';
require_once(dirname(__FILE__)).'/Database.php';
/**
* Description of Rosenberg
*
* @author ssch
*/
class Rosenberg extends MQTTProcessor {
protected $oInfluxDB;
private $sTopic;
private $iTopicLen;
private $aDataSet;
function __construct(Database $oInfluxDB) {
$this->oInfluxDB = $oInfluxDB;
$this->sTopic = '/weather/rosenberg/';
$this->iTopicLen = strlen($this->sTopic);
$this->aDataSet = array();
}
public function process($topic, $msg) {
$sType = substr($topic, $this->iTopicLen);
switch($sType) {
case 'rxCheckPercent':
case 'interval_minute':
case 'ptr':
case 'outTempBatteryStatus':
case 'delay':
case 'status':
case 'usUnits':
case 'appTemp':
break; //Ignore these
case 'inHumidity': //Final part of dataset
$this->aDataSet[$sType] = $msg;
$this->store();
default:
$this->aDataSet[$sType] = $msg;
}
}
public static function getTemperatureSeries() {
return array(
"dewpoint_C" => array("name" => "outdoor dew point", "defaultOn" => true),
"heatindex_C" => array("name" => "heat index", "defaultOn" => false),
"inDewpoint" => array("name" => "indoor dew point", "defaultOn" => false),
"windchill_C" => array("name" => "wind chill temperature (outdoor)", "defaultOn" => true),
"outTemp_C" => array("name" => "outdoor temperature", "defaultOn" => true),
"inTemp_C" => array("name" => "indoor temperature", "defaultOn" => true)
);
}
public static function getPrecipationSeries() {
return array(
"rain_cm" => array("name" => "rain", "defaultOn" => true),
"rainTotal" => array("name" => "total rain", "defaultOn" => false),
"dayRain_cm" => array("name" => "day rain", "defaultOn" => true),
"rain24_cm" => array("name" => "24h rain", "defaultOn" => true),
"hourRain_cm" => array("name" => "1h rain", "defaultOn" => true),
"rainRate_cm_per_hour" => array("name" => "rain/1h", "defaultOn" => true)
);
}
public static function getBarometerSeries() {
return array(
"pressure_mbar" => array("name" => "pressure", "defaultOn" => true),
"barometer_mbar" => array("name" => "barometer", "defaultOn" => true),
"altimeter_mbar" => array("name" => "altimeter", "defaultOn" => true)
);
}
public static function getHumiditySeries() {
return array(
"outHumidity" => array("name" => "outside humidity", "defaultOn" => true),
"humidex" => array("name" => "humidex", "defaultOn" => false),
"inHumidity" => array("name" => "inside humidity", "defaultOn" => true)
);
}
public static function getWindSeries() {
return array(
"windGust_kph" => array("name" => "wind gust", "defaultOn" => true),
"windSpeed_kph" => array("name" => "wind speed", "defaultOn" => true)
);
}
private function store() {
print "storing rosenberg data:\n";
var_dump($this->aDataSet);
$time = (int)$this->aDataSet['dateTime'] .'s';
unset ($this->aDataSet['dateTime']);
$data = array(
array('tags' => array('station' => 'ternevej 11'),
'fields' => $this->aDataSet,
'time' => $time));
$this->oInfluxDB->insert('rosenberg', $data);
$this->aDataSet = array();
}
public function getData($iStart, $iEnd, $aSeries) {
$sStart = $iStart.'s';
$sEnd = $iEnd.'s';
$sQuery = "SELECT " . implode(", ", $aSeries) . " FROM rosenberg where time >= $sStart and time <= $sEnd";
print $sQuery;
$aResult = $this->oInfluxDB->query($sQuery);
return $aResult;
}
public function getTopics() {
$aTopics = array();
$aTopics["/weather/rosenberg/+"] = $this->getDefaultProcessArgs();
return $aTopics;
}
}