-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathraw.php
executable file
·142 lines (127 loc) · 6 KB
/
raw.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
// This include will generate an array named 'result' with formatted informations about your devices and external modules
require_once( 'inc' . DIRECTORY_SEPARATOR . 'global.inc.php' );
$text_wo_rain = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C and humidity is _humi_%";
$text_wi_rain = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C, humidity is _humi_% and _rain_mm of rain fell in 24h";
$text_wo_rainsensor = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C and humidity is _humi_%. There is no rain sensor.";
$text_wo_rain_wi_wind = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C, humidity is _humi_% and wind is from _windangle_ at _windstrength_km/h";
$text_wi_rain_wi_wind = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C, humidity is _humi_%, wind is from _windangle_ at _windstrength_km/h and _rain_mm of rain fell in 24h";
$text_wo_rainsensor_wi_wind = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C, humidity is _humi_% and wind is from _windangle_° at _windstrength_km/h. There is no rain sensor.";
if ( isset( $_GET['text_wo_rain'] ) ) $text_wo_rain = $_GET['text_wo_rain'];
if ( isset( $_GET['text_wi_rain'] ) ) $text_wi_rain = $_GET['text_wi_rain'];
if ( isset( $_GET['text_wo_rainsensor'] ) ) $text_wo_rainsensor = $_GET['text_wo_rainsensor'];
if ( isset( $_GET['text_wo_rain_wi_wind'] ) ) $text_wo_rain = $_GET['text_wo_rain_wi_wind'];
if ( isset( $_GET['text_wi_rain_wi_wind'] ) ) $text_wi_rain = $_GET['text_wi_rain_wi_wind'];
if ( isset( $_GET['text_wo_rainsensor_wi_wind'] ) ) $text_wo_rainsensor = $_GET['text_wo_rainsensor_wi_wind'];
$display = ( isset( $_GET['a'] ) ) ? (int)$_GET['a'] : 0;
$without_rain_sensor_seconds = ( isset( $_GET['r'] ) ) ? (int)$_GET['r'] : 60*60*24;
$without_rain_sensor_offset = 0;
header('Content-type: text/plain; charset=UTF-8');
// Only parse informations if 'result' is an array
if ( is_array( $result ) )
{
// Only parse informations if 'result' is not empty
if ( count( $result ) > 0 )
{
// Uncomment the line below to see the structure of the 'result' array in your browser
// var_dump($result); die();
// For all devices -> in my case, I have 3 netamos : at home, at office and at my parents home
$idx = -1;
foreach ( $result as $data )
{
$idx++;
if ( $display > 0 )
{
if ( $idx !== $display ) continue;
}
// array 'data' is now just the subpart of the array 'result' for the first device, and the next time for the second, etc... until there is no more device to parse
$device_name = @$data['station'];
// find rain...
$rain = '';
$rain1 = '';
$rain24 = '';
$windangle = '';
$windstrength = '';
$gustangle = '';
$guststrength = '';
if ( isset( $data['m'] ) && is_array( $data['m'] ) )
{
foreach ( $data['m'] as $moduleid => $datam )
{
if ( ( isset( $datam['dashboard']["sum_rain_24"] ) ) || ( isset( $datam['dashboard']["Rain"] ) ) )
{
$without_rain_sensor_offset = time() - (int)@$datam['dashboard']['time_utc'];
$rain24 = @$datam['dashboard']["sum_rain_24"];
$rain1 = @$datam['dashboard']["sum_rain_1"];
$rain = @$datam["misc"]["sum_rain"];
unset( $data['m'][ $moduleid ] );
}
if ( ( isset( $datam['dashboard']["WindStrength"] ) ) )
{
$windangle = @$datam['dashboard']["WindAngle"];
$windstrength = @$datam['dashboard']["WindStrength"];
$gustangle = @$datam['dashboard']["GustAngle"];
$guststrength = @$datam['dashboard']["GustStrength"];
unset( $data['m'][ $moduleid ] );
}
}
}
// get all external modules for the current device
if ( isset( $data['m'] ) && is_array( $data['m'] ) )
{
foreach ( $data['m'] as $moduleid => $datam )
{
// Now 'moduleid' is the unique id of the current external module and 'datam' is an array with all informations about this exteral module
// Uncomment the line below to see the structure of the exteral module array in your browser
//var_dump($datam); die();
// We retrieve all informations in variables
$name = $datam['name'];
$time = $datam['time'];
$temp = $datam['results']['Temperature'];
$humi = $datam['results']['Humidity'];
// you can change the format as you want, all informations are at https://php.net/manual/function.date.php
$human_date = date( 'd.m.Y', $time);
$human_hour = date( 'H:i' , $time);
// Display the text that you want
// \n at the end puts a new line at the end of this one
if ( empty( $windangle ) )
{
if ( $without_rain_sensor_offset < $without_rain_sensor_seconds )
{
$text = ( $rain24 == '' ) ? $text_wo_rain : $text_wi_rain;
}
else
{
$text = $text_wo_rainsensor;
}
}
else
{
if ( $without_rain_sensor_offset < $without_rain_sensor_seconds )
{
$text = ( $rain24 == '' ) ? $text_wo_rain_wi_wind : $text_wi_rain_wi_wind;
}
else
{
$text = $text_wo_rainsensor_wi_wind;
}
}
echo str_replace(
array( '_device_name_' , '_name_' , '_human_date_' , '_human_hour_' , '_temp_' , '_humi_' , '_rain_' , '_rain1_' , '_rain24_' , '_windangle_' , '_windstrength_' , '_gustangle_' , '_guststrength_' ),
array( $device_name , $name , $human_date , $human_hour , $temp , $humi , $rain , $rain1 , $rain24 , $windangle , $windstrength , $gustangle , $guststrength ),
$text
);
echo "\n";
}
}
}
}
else
{
echo __('No device');
}
}
else
{
echo $result->result['error']['message'];
}