From 490102062602a64bc34e414f8ad0a23038558365 Mon Sep 17 00:00:00 2001
From: mrjones-plip
Date: Mon, 3 Apr 2023 21:58:03 -0700
Subject: [PATCH 1/4] Support pirate weather per #69
---
.gitignore | 1 +
README.md | 19 ++++++++++-------
config.dist.csv | 9 ++++++--
html/ajax.php | 2 +-
html/get_data.php | 53 ++++++++++++++++++++++++++---------------------
html/index.php | 2 +-
html/stats.php | 6 +++---
html/temps.php | 2 +-
8 files changed, 54 insertions(+), 40 deletions(-)
diff --git a/.gitignore b/.gitignore
index ce1dca3..2c39517 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ venv
config.php
config.csv
datadarksky.cache
+forecast.cache
\ No newline at end of file
diff --git a/README.md b/README.md
index 63ca0a3..46bad69 100644
--- a/README.md
+++ b/README.md
@@ -16,11 +16,11 @@ to DIY a weather station.
Goals for this project are:
-* Use cheap hardware (e.g. Rasberry Pi)
+* Use cheap hardware (e.g. Rasberry Pi from 2017)
* Show live weather from local, wireless sensors
* Show time
* Show today's sunset/sunrise times
-* Show weather forecast from [Dark Sky API](https://darksky.net/dev/)
+* Show weather forecast from a forecast API ([Dark Sky](https://darksky.net/dev/) or [Pirate Weather](pirateweather.net/))
## Hardware
@@ -32,7 +32,7 @@ Here's the parts I used and prices at time of publishing (March 2017):
* $43 - [Rasberry Pi 3 Model B and Power Adapter](http://amzn.to/2nklto3)
* $11 - [8GB Micro SD card](http://amzn.to/2nRE9Pt)
-Total for this is $127, so, erm, not that cheap. Ideally you'd have a lot of
+Total for this is $127, so, erm, not _that_ cheap. Ideally you'd have a lot of
parts around you could re-use for this project. As well, you could reduce the price by going with a
3.5" screen ([only $17](http://amzn.to/2mCIxlg)) and Pi B+ ([only $30](http://amzn.to/2n5nioJ))
. For the B+ you'd have to use ethernet or bring your own USB WiFi
@@ -128,7 +128,7 @@ of creating your own config file. Here we see ID 231:
Specifically, your latitude (`lat`),
longitude (`lon`) and labels which you
got in the step above running `rtl_433`. As well, you'll need to sign up for an API key
-on [Dark Sky](https://darksky.net/dev/register) and put that in for the `darksky` value below.
+on [Dark Sky](https://darksky.net/dev/register) or [Pirate Weather](pirateweather.net/) and put that in for the `forecast_api` value below.
If you want static icons instead of
animated ones, set 'animate' to `false` instead of `true` like below. Here's a sample:
```
@@ -137,8 +137,8 @@ animated ones, set 'animate' to `false` instead of `true` like below. Here's a s
lat,31.775554
lon,-81.822436
- # set your darksky API token - should be a 32 char alpa numeric
- darksky,aabbccddeeffgghhiijj112233445566
+ # set your forecast API token - should be a 32 char alpa numeric
+ forecast_api,aabbccddeeffgghhiijj112233445566
# should we show animated icons for forecast? should be "true" or "false"
animate,true
@@ -295,10 +295,10 @@ IP address of your server:
## Development
-Check out this repo, ``cd`` into and start a web server:
+Check out this repo, `cd` into the `html` directory and start a web server:
```
-sudo php -S localhost:8000
+php -S localhost:8000
```
The rtl_433 works great on Ubuntu for desktop/laptop development. Manually kick off the input
@@ -339,6 +339,9 @@ Use your IDE of choice to edit and point your browser at ``localhost:8000``
PRs and Issues welcome!
## Version History
+* 0.10.0 - Apr 3,2023
+ * Support Pirate Weather by default #69
+ * Move to SemVer versioning (MAJOR.MINOR.PATCH)
* 0.9.10 - Jul 20,2020
* Convert to more JSON, less HTML over AJAX calls #89
* Allow big clock mode by clicking time #82
diff --git a/config.dist.csv b/config.dist.csv
index d6a80d5..3eb9f35 100644
--- a/config.dist.csv
+++ b/config.dist.csv
@@ -3,8 +3,13 @@
lat,31.775554
lon,-81.822436
-# set your darksky API token - should be a 32 char alpa numeric
-darksky,aabbccddeeffgghhiijj112233445566
+# set your forecast API token from either Dark Sky or Pirate Weather
+forecast_api_token,aabbccddeeffgghhiijj112233445566
+
+# set your provider for forecasts (must end in an:
+# pirate weather: https://api.pirateweather.net
+# dark sky: https://api.darksky.net
+forecast_api_url,https://api.pirateweather.net
# should we show animated icons for forecast? should be "true" or "false"
animate,true
diff --git a/html/ajax.php b/html/ajax.php
index 99f7c8d..aa9d212 100644
--- a/html/ajax.php
+++ b/html/ajax.php
@@ -6,7 +6,7 @@
$today = date('Y-m-d', time());
$time = date('g:i A', time());
$date = date('D M j', time());
- $forecast = getDarkSkyData();
+ $forecast = getForecastData();
switch ($_GET['content']){
case "forecast":
diff --git a/html/get_data.php b/html/get_data.php
index a3375ca..b610ab9 100644
--- a/html/get_data.php
+++ b/html/get_data.php
@@ -8,7 +8,8 @@ function getValidConfigs(){
return array(
'lat',
'lon',
- 'darksky',
+ 'forecast_api_token',
+ 'forecast_api_url',
'labels',
'animate',
'dataPath',
@@ -68,9 +69,13 @@ function configIsValid($validateApi = false)
$valid['valid'] = false;
$valid['reason'] .= 'Missing required option. ';
}
- if (!isset($YANPIWS['darksky']) || strlen($YANPIWS['darksky']) != 32){
+ if (!isset($YANPIWS['forecast_api_url']) || strlen($YANPIWS['forecast_api_url']) < 10){
$valid['valid'] = false;
- $valid['reason'] .= 'Dark Sky API Key is wrong length or missing. ';
+ $valid['reason'] .= 'Forecast API URL is wrong length or missing. (forecast_api_url
)';
+ }
+ if (!isset($YANPIWS['forecast_api_token']) || strlen($YANPIWS['forecast_api_token']) < 32 || strlen($YANPIWS['forecast_api_token']) > 41){
+ $valid['valid'] = false;
+ $valid['reason'] .= 'Forecast API Key is wrong length or missing. (forecast_api_token
)';
}
if(!isset($YANPIWS['lat'])) {
$valid['valid'] = false;
@@ -121,13 +126,13 @@ function configIsValid($validateApi = false)
$valid['reason'] .= 'DataPath does not exist or is not writable. ';
}
if ($validateApi){
- $http = curl_init(getDarkSkyUrl(true));
+ $http = curl_init(getForecastUrl(true));
curl_setopt($http, CURLOPT_NOBODY , true);
curl_exec($http);
$http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);
if ($http_status != 200){
$valid['valid'] = false;
- $valid['reason'] .= 'Dark Sky API call failed: Either invalid API key or invalid Lat/Long ' .
+ $valid['reason'] .= 'Forecast API call failed: Either invalid API key or invalid Lat/Long ' .
"(status: $http_status). ";
}
}
@@ -300,17 +305,17 @@ function getHumidityHtml($tempLine, $useLabel = false)
}
/**
- * Get the age in human time (sec, min, hour etc) of the dark sky cache
+ * Get the age in human time (sec, min, hour etc) of the Forecast cache
* @param $returnSeconds boolean to return int of seconds if true, otherwise string of human time
*/
function getCacheAge($returnSeconds = false){
global $YANPIWS;
$path = $YANPIWS['dataPath'];
- $darkskytime = filemtime($path . 'darksky.cache');
+ $forecast_cache_time = filemtime($path . 'forecast.cache');
if (!$returnSeconds) {
- return getHumanTime(time() - $darkskytime);
+ return getHumanTime(time() - $forecast_cache_time);
} else {
- return (time() - $darkskytime);
+ return (time() - $forecast_cache_time);
}
}
@@ -367,21 +372,21 @@ function getSunriseHtml($time)
}
/**
- * get data from dark sky. will cache data and refresh it every 10 minutes
+ * get data from Forecast API. will cache data and refresh it every 10 minutes
*
* @return stdClass of either resutls or very lightly populated error object
*/
-function getDarkSkyData()
+function getForecastData()
{
global $YANPIWS;
$path = $YANPIWS['dataPath'];
- $cache = $path . 'darksky.cache';
+ $cache = $path . 'forecast.cache';
$hourAgo = time() - (60*10); // 10 minutes
$data = false;
$configStatus = configIsValid();
if($configStatus['valid'] === true) {
if ((!is_file($cache) || filectime($cache) < $hourAgo)) {
- $http = curl_init(getDarkSkyUrl());
+ $http = curl_init(getForecastUrl());
curl_setopt($http, CURLOPT_RETURNTRANSFER, 1);
$dataFromRemote = curl_exec($http);
$http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);
@@ -406,11 +411,11 @@ function getDarkSkyData()
}
/**
- * Simple wrapper to concat the string for the Dark Sky API endpoint
+ * Simple wrapper to concat the string for the Forecast API endpoint
*
* @return string of URL
*/
-function getDarkSkyUrl($useTestLatLong = false){
+function getForecastUrl($useTestLatLong = false){
global $YANPIWS;
if ($useTestLatLong){
$lat = "31.775554";
@@ -419,13 +424,13 @@ function getDarkSkyUrl($useTestLatLong = false){
$lat = $YANPIWS['lat'];
$lon = $YANPIWS['lon'];
}
- return 'https://api.darksky.net/forecast/' . $YANPIWS['darksky'] . '/' . $lat . ',' . $lon;
+ return $YANPIWS['forecast_api_url'] . '/forecast/' . $YANPIWS['forecast_api_token'] . '/' . $lat . ',' . $lon;
}
/**
- * expects the $data->daily object from getDarkSkyData(), returns $days (default 5) of forecast HTML
+ * expects the $data->daily object from getForecastData(), returns $days (default 5) of forecast HTML
*
- * @param null $daily $data->daily object from getDarkSkyData()
+ * @param null $daily $data->daily object from getForecastData()
* @param int $days how many days of forecast to return
* @return string of HTML
*/
@@ -437,7 +442,7 @@ function getDailyForecastHtml($daily = null, $days = 5)
if ($daily == null) {
// show rain for error
$html .= " ";
- $html .= "No Dark Sky Data for forecast.";
+ $html .= "No Data for forecast.";
} else {
$count = 1;
foreach ($daily->data as $day) {
@@ -468,9 +473,9 @@ function getDailyForecastHtml($daily = null, $days = 5)
}
/**
- * expects the $data->daily object from getDarkSkyData(), returns $days (default 5) of forecast HTML
+ * expects the $data->daily object from getForecastData(), returns $days (default 5) of forecast HTML
*
- * @param null $daily $data->daily object from getDarkSkyData()
+ * @param null $daily $data->daily object from getForecastData()
* @param int $days how many days of forecast to return
* @return string of HTML
*/
@@ -478,7 +483,7 @@ function getDailyForecast($daily = null, $days = 5)
{
$result = array();
if ($daily == null) {
- $result['result'] = "No Dark Sky Data for forecast.";
+ $result['result'] = "No Data for forecast.";
} else {
$count = 1;
@@ -541,9 +546,9 @@ function getHumanTime($s)
/**
- * expects the $data->currently object from getDarkSkyData(), returns windspeed HTML
+ * expects the $data->currently object from getForecastData(), returns windspeed HTML
*
- * @param null $daily $data->currently object from getDarkSkyData()
+ * @param null $daily $data->currently object from getForecastData()
* @return string of HTML
*/
function getCurrentWind($currentlyObject)
diff --git a/html/index.php b/html/index.php
index 8dddd63..c49364d 100644
--- a/html/index.php
+++ b/html/index.php
@@ -3,7 +3,7 @@
require_once 'get_data.php';
getConfig();
-$forecast = getDarkSkyData();
+$forecast = getForecastData();
$status = configIsValid();
$statusHtml = '';
if ($status['valid'] != true) {
diff --git a/html/stats.php b/html/stats.php
index 91519e8..8419b3c 100644
--- a/html/stats.php
+++ b/html/stats.php
@@ -15,7 +15,7 @@
$address = 'NA';
}
-$darkskytime= getCacheAge();
+$cachetime= getCacheAge();
?>
@@ -30,9 +30,9 @@
<- Weather
YANPIS 0.9.10 - Released Jul 26, 2020
- Powered by Dark Sky
+ Powered by Pirate Weather
- Dark Sky Cache Age:
+ Forecast Cache Age:
IP:
diff --git a/html/temps.php b/html/temps.php
index aca0760..0763596 100644
--- a/html/temps.php
+++ b/html/temps.php
@@ -17,7 +17,7 @@
Date: Mon, 3 Apr 2023 22:02:51 -0700
Subject: [PATCH 2/4] fix readme to match config.csv
---
README.md | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 46bad69..e2bd58b 100644
--- a/README.md
+++ b/README.md
@@ -137,8 +137,11 @@ animated ones, set 'animate' to `false` instead of `true` like below. Here's a s
lat,31.775554
lon,-81.822436
- # set your forecast API token - should be a 32 char alpa numeric
- forecast_api,aabbccddeeffgghhiijj112233445566
+ # set your forecast API token - should be a 32-40 char alpha numeric
+ forecast_api_token,aabbccddeeffgghhiijj112233445566
+
+ # set your forecast API URL
+ forecast_api_url,https://api.pirateweather.net
# should we show animated icons for forecast? should be "true" or "false"
animate,true
From d738dce9b16d3a3bec0d0a9e59ecf856f0e3c481 Mon Sep 17 00:00:00 2001
From: mrjones-plip
Date: Mon, 3 Apr 2023 22:21:19 -0700
Subject: [PATCH 3/4] fix version in stats page
---
html/stats.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/html/stats.php b/html/stats.php
index 8419b3c..bbc599d 100644
--- a/html/stats.php
+++ b/html/stats.php
@@ -29,7 +29,7 @@
<- Weather
- YANPIS 0.9.10 - Released Jul 26, 2020
+ YANPIS 0.10.0 - Released Apr 3, 2023
Powered by Pirate Weather
Forecast Cache Age:
From dce41e283f8bf3ae25abee76747cea13609c5f06 Mon Sep 17 00:00:00 2001
From: mrjones-plip
Date: Mon, 3 Apr 2023 22:22:12 -0700
Subject: [PATCH 4/4] fix version how you spell YANPIWS in stats
---
html/stats.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/html/stats.php b/html/stats.php
index bbc599d..b43d986 100644
--- a/html/stats.php
+++ b/html/stats.php
@@ -29,7 +29,7 @@
<- Weather
- YANPIS 0.10.0 - Released Apr 3, 2023
+ YANPIWS 0.10.0 - Released Apr 3, 2023
Powered by Pirate Weather
Forecast Cache Age: