Skip to content

Commit

Permalink
version 0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
potsky committed Aug 31, 2014
1 parent abcc95e commit 7383487
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Just copy the project directory on your server and configure it.
## Change log

- **0.5.5**

- Add GET parameter `a` in `raw.php`
- Add `rain1` and `rain24` values for GET messages in `raw.php`

- **0.5.4**

- Add `rain_sum_1` and `rain_sum_24` values
Expand Down Expand Up @@ -78,10 +83,12 @@ You can now specify 2 custom messages in the url when :

Here are the distinct available parameters :

- <http://xxx/raw.php> : english default messages
- <http://xxx/raw.php?a=1> : display all weather stations
- <http://xxx/raw.php> : english default messages and display all weather stations
- <http://xxx/raw.php?a=1> : english default messages and display only the first weather station
- <http://xxx/raw.php?a=2> : english default messages and display only the second weather station
- <http://xxx/raw.php?text_wo_rain=Temperature is _temp_°C> : message without rain gauge
- <http://xxx/raw.php?text_wi_rain=Temperature is _temp_°C and rain is _rain_> : message with rain gauge
- <http://xxx/raw.php?text_wi_rain=...&text_wo_rain=...> : messages for both cases (rain and no rain)

Available parameters in your message are :

Expand All @@ -91,7 +98,9 @@ Available parameters in your message are :
- `_human_hour_`
- `_temp_`
- `_humi_`
- `_rain_`
- `_rain_` : rain since the beginning of the day (or week or month if you have change the module scale parameter)
- `_rain1_` : rain for 1 hour
- `_rain24_` : rain for 24 hours

## More...

Expand Down
28 changes: 19 additions & 9 deletions raw.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
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_wi_rain = "In external module '_device_name_:_name_', on _human_date_ at _human_hour_, temperature is _temp_°C, humidity is _humi_% and _rain24_mm of rain fell in 24h";

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'];

$display = ( isset( $_GET['a'] ) ) ? (int)$_GET['a'] : 0;

header('Content-type: text/plain; charset=UTF-8');

// Only parse informations if 'result' is an array
Expand All @@ -45,17 +47,28 @@
// 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 = '';
$rain = '';
$rain1 = '';
$rain24 = '';
if ( isset( $data['m'] ) && is_array( $data['m'] ) ) {
foreach ( $data['m'] as $moduleid => $datam ) {
if ( isset( $datam['dashboard']["sum_rain_24"] ) ) {
$rain = $datam['dashboard']["sum_rain_24"];
$rain24 = $datam['dashboard']["sum_rain_24"];
$rain1 = $datam['dashboard']["sum_rain_1"];
$rain = $datam["misc"]["sum_rain"];
unset( $data['m'][ $moduleid ] );
}
}
}
Expand All @@ -82,14 +95,11 @@
// Display the text that you want
// \n at the end puts a new line at the end of this one
echo str_replace(
array( '_device_name_' , '_name_' , '_human_date_' , '_human_hour_' , '_temp_' , '_humi_' , '_rain_' ),
array( $device_name , $name , $human_date , $human_hour , $temp , $humi , $rain ),
( $rain == '' ) ? $text_wo_rain : $text_wi_rain
array( '_device_name_' , '_name_' , '_human_date_' , '_human_hour_' , '_temp_' , '_humi_' , '_rain_' , '_rain1_' , '_rain24_' ),
array( $device_name , $name , $human_date , $human_hour , $temp , $humi , $rain , $rain1 , $rain24 ),
( $rain24 == '' ) ? $text_wo_rain : $text_wi_rain
);
echo "\n";

// Stop the script here to avoid looping to the next devices and the next external modules (foreach loops)
if ( ! isset( $_GET['a'] ) ) die();
}
}
}
Expand Down

0 comments on commit 7383487

Please sign in to comment.