Skip to content

Commit

Permalink
Merge pull request #3 from Ths2-9Y-LqJt6/0.3
Browse files Browse the repository at this point in the history
0.3
  • Loading branch information
Ths2-9Y-LqJt6 authored Mar 24, 2017
2 parents 92b1cab + b960902 commit 1ce9e2f
Show file tree
Hide file tree
Showing 13 changed files with 1,204 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
config.php
data
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# YANPIWS
Yet Another Pi Weather Station (YANPIWS) - My explorations in getting a Rasberry Pi showing local time and weather

![](./screenshot.png)
![](./screenshot2.png)

## Background

Expand All @@ -17,9 +17,7 @@ Goals for this project are:
* Show past weather from local, wireless sensors
* Show current time
* Show sunset/sunrise times
* Show moonrise/moonset times
* Show weather forecast from some provider
* Show show current weather from some provider
* Show weather forecast from Dark Sky API https://darksky.net/dev/

## Hardware

Expand Down Expand Up @@ -83,5 +81,6 @@ DATE,ID,TEMP,HUMIDITY
```

## Version History
* 0.3 - Mar 23, 2017 - forecast if you have a darksky API
* 0.2 - Mar 23, 2017 - reading CSV, super basic HTML output
* 0.1 - Mar 22, 2017 - parsing data, writing to CSV, crude readme, no html output
11 changes: 11 additions & 0 deletions config.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$YANPIWS = array();
$YANPIWS['lat'] = 31.775554;
$YANPIWS['lon'] = -81.822436;
$YANPIWS['dataPath'] = './data/';
$YANPIWS['gmt_offset'] = '-8';
$YANPIWS['darksky'] = false;
$YANPIWS['labels'] = array(
'211' => 'Inside',
'109' => 'Outside',
);
148 changes: 148 additions & 0 deletions data/2017-03-23
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,151 @@
2017-03-23 00:19:10,109,56.66,28
2017-03-23 00:19:43,211,72.32,37
2017-03-23 00:19:58,109,56.66,28
2017-03-23 00:20:31,211,72.32,37
2017-03-23 00:20:46,109,56.66,28
2017-03-23 21:26:56,211,75.56,34
2017-03-23 21:27:11,109,64.22,22
2017-03-23 21:27:44,211,75.56,34
2017-03-23 21:27:59,109,64.22,22
2017-03-23 21:28:32,211,75.56,34
2017-03-23 21:28:47,109,64.04,22
2017-03-23 21:29:20,211,75.56,34
2017-03-23 21:29:35,109,64.04,22
2017-03-23 21:30:08,211,75.56,34
2017-03-23 21:30:23,109,64.04,23
2017-03-23 21:30:56,211,75.56,34
2017-03-23 21:31:11,109,64.04,23
2017-03-23 21:31:44,211,75.56,34
2017-03-23 21:31:59,109,63.86,23
2017-03-23 21:32:32,211,75.56,34
2017-03-23 21:32:47,109,63.86,23
2017-03-23 21:33:20,211,75.56,34
2017-03-23 21:33:35,109,63.86,23
2017-03-23 21:34:08,211,75.56,34
2017-03-23 21:34:23,109,63.86,24
2017-03-23 21:34:56,211,75.56,34
2017-03-23 21:35:11,109,63.86,23
2017-03-23 21:35:44,211,75.56,34
2017-03-23 21:35:59,109,63.68,24
2017-03-23 21:36:32,211,75.56,34
2017-03-23 21:37:20,211,75.56,34
2017-03-23 21:37:35,109,63.68,24
2017-03-23 21:38:08,211,75.56,34
2017-03-23 21:38:23,109,63.68,24
2017-03-23 21:38:56,211,75.56,34
2017-03-23 21:39:44,211,75.56,34
2017-03-23 21:39:59,109,63.68,24
2017-03-23 21:40:32,211,75.56,34
2017-03-23 21:41:20,211,75.56,34
2017-03-23 21:41:35,109,63.5,24
2017-03-23 21:42:08,211,75.56,34
2017-03-23 21:42:56,211,75.56,34
2017-03-23 21:43:11,109,63.5,24
2017-03-23 21:43:44,211,75.56,34
2017-03-23 21:43:59,109,63.5,25
2017-03-23 21:44:32,211,75.56,34
2017-03-23 21:44:47,109,63.5,25
2017-03-23 21:45:20,211,75.56,34
2017-03-23 21:45:35,109,63.32,30
2017-03-23 21:46:08,211,75.56,34
2017-03-23 21:46:23,109,63.32,30
2017-03-23 21:46:56,211,75.56,34
2017-03-23 21:47:11,109,63.32,30
2017-03-23 21:47:44,211,75.56,34
2017-03-23 21:47:59,109,63.32,30
2017-03-23 21:48:32,211,75.56,34
2017-03-23 21:48:47,109,63.32,30
2017-03-23 21:49:20,211,75.56,34
2017-03-23 21:49:35,109,63.32,30
2017-03-23 21:50:08,211,75.56,34
2017-03-23 21:50:23,109,63.32,30
2017-03-23 21:50:56,211,75.56,34
2017-03-23 21:51:11,109,63.32,30
2017-03-23 21:51:44,211,75.56,34
2017-03-23 21:51:59,109,63.14,30
2017-03-23 21:52:32,211,75.56,34
2017-03-23 21:52:47,109,63.14,30
2017-03-23 21:53:20,211,75.56,34
2017-03-23 21:53:35,109,63.14,30
2017-03-23 21:54:08,211,75.56,34
2017-03-23 21:54:23,109,63.14,30
2017-03-23 21:54:56,211,75.56,34
2017-03-23 21:55:11,109,63.14,30
2017-03-23 21:55:44,211,75.56,34
2017-03-23 21:55:59,109,62.96,30
2017-03-23 21:56:32,211,75.56,34
2017-03-23 21:56:47,109,62.96,30
2017-03-23 21:57:20,211,75.38,34
2017-03-23 21:57:35,109,62.96,30
2017-03-23 21:58:08,211,75.38,34
2017-03-23 21:58:23,109,62.78,30
2017-03-23 21:58:56,211,75.38,34
2017-03-23 21:59:11,109,62.78,30
2017-03-23 21:59:44,211,75.38,34
2017-03-23 22:00:32,211,75.38,34
2017-03-23 22:01:20,211,75.38,34
2017-03-23 22:02:08,211,75.38,34
2017-03-23 22:02:56,211,75.38,34
2017-03-23 22:03:44,211,75.38,34
2017-03-23 22:04:32,211,75.38,34
2017-03-23 22:04:47,109,62.6,30
2017-03-23 22:05:20,211,75.38,34
2017-03-23 22:06:08,211,75.38,34
2017-03-23 22:06:23,109,62.6,30
2017-03-23 22:06:56,211,75.38,34
2017-03-23 22:07:11,109,62.6,30
2017-03-23 22:07:44,211,75.38,34
2017-03-23 22:07:59,109,62.42,30
2017-03-23 22:08:32,211,75.38,34
2017-03-23 22:08:47,109,62.42,30
2017-03-23 22:09:20,211,75.38,34
2017-03-23 22:09:35,109,62.42,30
2017-03-23 22:10:08,211,75.38,34
2017-03-23 22:10:23,109,62.42,30
2017-03-23 22:10:56,211,75.38,34
2017-03-23 22:11:11,109,62.42,30
2017-03-23 22:11:44,211,75.38,34
2017-03-23 22:11:59,109,62.24,30
2017-03-23 22:12:32,211,75.38,34
2017-03-23 22:12:47,109,62.24,30
2017-03-23 22:13:20,211,75.38,34
2017-03-23 22:13:35,109,62.24,31
2017-03-23 22:14:08,211,75.38,34
2017-03-23 22:14:23,109,62.24,31
2017-03-23 22:14:56,211,75.38,34
2017-03-23 22:15:11,109,62.24,31
2017-03-23 22:15:44,211,75.38,34
2017-03-23 22:15:59,109,62.24,31
2017-03-23 22:16:32,211,75.38,34
2017-03-23 22:16:47,109,62.24,31
2017-03-23 22:17:20,211,75.38,34
2017-03-23 22:17:35,109,62.06,31
2017-03-23 22:18:08,211,75.2,33
2017-03-23 22:18:24,109,62.06,31
2017-03-23 22:18:56,211,75.38,34
2017-03-23 22:19:11,109,62.06,31
2017-03-23 22:19:44,211,75.38,34
2017-03-23 22:19:59,109,62.06,31
2017-03-23 22:20:32,211,75.38,34
2017-03-23 22:20:47,109,61.88,31
2017-03-23 22:21:20,211,75.38,34
2017-03-23 22:21:35,109,62.06,31
2017-03-23 22:22:08,211,75.38,34
2017-03-23 22:22:23,109,61.88,31
2017-03-23 22:22:56,211,75.38,34
2017-03-23 22:23:11,109,61.88,31
2017-03-23 22:23:44,211,75.38,34
2017-03-23 22:24:00,109,61.7,31
2017-03-23 22:24:32,211,75.38,34
2017-03-23 22:24:47,109,61.7,31
2017-03-23 22:25:20,211,75.2,34
2017-03-23 22:26:08,211,75.2,34
2017-03-23 22:26:23,109,61.7,31
2017-03-23 22:26:56,211,75.2,34
2017-03-23 22:27:12,109,61.7,31
2017-03-23 22:27:44,211,75.2,34
2017-03-23 22:27:59,109,61.7,31
2017-03-23 22:28:32,211,75.2,34
2017-03-23 22:29:20,211,75.2,34
2017-03-23 22:30:08,211,75.2,34
2017-03-23 22:30:23,109,61.52,31
81 changes: 81 additions & 0 deletions get_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,85 @@ function getData($file){
} else {
return array();
}
}

function getMostRecentTemp($id, $date = null){
global $YANPIWS;
if ($date == null){
$date = date('Y-m-d', time());
}
$allData = getData($YANPIWS['dataPath'] . $date);
return array_pop($allData[$id]);
}

function getTempHtml($tempLine){
global $YANPIWS;
$key = $tempLine[1];
if (isset($YANPIWS['labels'][$key])){
$label = $YANPIWS['labels'][$key];
} else {
$label = "ID $key";
}
return "<div class='temp'><strong>{$tempLine[2]}°</strong> $label </div>\n";
}

function getSunriseTime(){
global $YANPIWS;
return date(
'g:iA',
date_sunrise(
time(),
SUNFUNCS_RET_TIMESTAMP,
$YANPIWS['lat'],
$YANPIWS['lon'],
90,
$YANPIWS['gmt_offset']
)
);
}
function getSunsetTime(){
global $YANPIWS;
return date(
'g:iA',
date_sunset(
time(),
SUNFUNCS_RET_TIMESTAMP,
$YANPIWS['lat'],
$YANPIWS['lon'],
90,
$YANPIWS['gmt_offset']
)
);
}

function getDarkSkyData(){
global $YANPIWS;
return json_decode(file_get_contents('https://api.darksky.net/forecast/' .
$YANPIWS['darksky'] . '/' . $YANPIWS['lat'] . ',' . $YANPIWS['lon']));
}

function getDailyForecastHtml($daily){
$html = '';
$js = '';
foreach ($daily->data as $day){
$rand = rand(99999,999999999999);
$today = substr(date('D',$day->time),0,1);
$html .= "<div class='forecastday'>";
$html .= $today;
$html .= " <canvas id='$today.$rand' width='32' height='32'></canvas>";
$html .= ' H ' . number_format($day->temperatureMax,0) .'°';
$html .= ' L ' .number_format($day->temperatureMin,0).'°';
$html .= ' ' .number_format($day->windSpeed,0) . 'mph';
$html .= '</div>';

$js .= "skycons.add('$today.$rand', '$day->icon');\n";
}
$html .= "
<script src='skycons/skycons.js'></script>
<script>
var skycons = new Skycons({'color': 'white'});
$js
</script>
";
return $html;
}
32 changes: 19 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@

<link rel="stylesheet" type="text/css" href="styles.css" />
<?php
if(is_file('config.php')){
require_once ("config.php");
} else {
die ('config.php not found :(');
}

require_once ("get_data.php");
$today = date('Y-m-d', time());
$time = date('h:i:s A', time());
$date = date('l jS \of F Y', time());
$date = date('D j, F Y', time());
$allData = getData("./data/" . $today);

$labels = array(
'211' => 'Inside',
'109' => 'Outside',
);

$currentTempHtml = '';
foreach (array_keys($allData) as $key){
$temp = array_pop($allData[$key])[2];
$label = $labels[$key];
$currentTempHtml .= "<strong>{$temp}°</strong> $label <br />\n";
foreach ($YANPIWS['labels'] as $id => $label){
$tempLine = getMostRecentTemp($id);
$currentTempHtml .= getTempHtml($tempLine);
}
$sunrise = 'Sunrise ' . getSunriseTime();
$sunset = 'Sunset ' . getSunsetTime();

$forecast = getDarkSkyData();
$forecastHtml = getDailyForecastHtml($forecast->daily);
?>

<link rel="stylesheet" type="text/css" href="styles.css" />

<p><?php echo $date ?></p>
<p><?php echo $time ?></p>
<p><?php echo $date ?> - <?php echo $time ?></p>
<p style="clear:both;"><?php echo $sunrise ?> - <?php echo $sunset ?></p>
<p><?php echo $currentTempHtml ?></p>
<p style="clear:both;"><?php echo $forecastHtml ?></p>

Binary file removed screenshot.png
Binary file not shown.
Binary file added screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions skycons/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
50 changes: 50 additions & 0 deletions skycons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Skycons
=======

Skycons is a set of ten animated weather glyphs, procedurally generated by
JavaScript using the HTML5 canvas tag. They're easy to use, and pretty
lightweight, so they shouldn't rain on your parade:

<canvas id="icon1" width="128" height="128"></canvas>
<canvas id="icon2" width="128" height="128"></canvas>

<script>
var skycons = new Skycons({"color": "pink"});
// on Android, a nasty hack is needed: {"resizeClear": true}

// you can add a canvas by it's ID...
skycons.add("icon1", Skycons.PARTLY_CLOUDY_DAY);

// ...or by the canvas DOM element itself.
skycons.add(document.getElementById("icon2"), Skycons.RAIN);

// if you're using the Forecast API, you can also supply
// strings: "partly-cloudy-day" or "rain".

// start animation!
skycons.play();

// you can also halt animation with skycons.pause()

// want to change the icon? no problem:
skycons.set("icon1", Skycons.PARTLY_CLOUDY_NIGHT);

// want to remove one altogether? no problem:
skycons.remove("icon2");
</script>

Skycons were designed for [Forecast](http://forecast.io/) by those wacky folks
at The Dark Sky Company, and were heavily inspired by Adam Whitcroft's
excellent [Climacons](http://adamwhitcroft.com/climacons/). The source code has
been [released into the public domain][cc0], so please do with it as you see
fit! ♡

[cc0]: http://creativecommons.org/publicdomain/zero/1.0/

Variants
--------

Several kind folks have made variants of Skycons:

* [Color Skycons](https://github.com/maxdow/skycons) by Maxime Warnier
* [Skycons for Android](https://github.com/torryharris/Skycons) by Torry Harris
Loading

0 comments on commit 1ce9e2f

Please sign in to comment.