From 72173077a9a3050c33a0bb70cdfb3819f85db852 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Thu, 14 Jul 2016 01:08:11 -0500 Subject: [PATCH 01/26] First try.. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This definitely won’t work. It’s a mix of PHP, JavaScript and pseudo-code written at 1 AM. --- current.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/current.php b/current.php index 2b5d0cc..ddf9daa 100644 --- a/current.php +++ b/current.php @@ -142,4 +142,46 @@ function convertMillibarsToInches($millibars) { return $inches; } +function calculateHeatIndex($relativeHumidity, $airTemperature) { + $airTemperature = convertCelsiusToFahrenheit($airTemperature); + + if ($relativeHumidity > 100){ + $relativeHumidity = 100; + } + else if ($relativeHumidity < 0) { + $relativeHumidity = 0; + } + + if ($airTemperature <= 40.0) { + $hi = $airTemperature; + } + else { + $hitemp = 61.0+(($airTemperature-68.0)*1.2)+($relativeHumidity*0.094); + $fptemp = $airTemperature; + $hifinal = 0.5*($fptemp+$hitemp); + + if ($hifinal > 79.0) { + $hi = -42.379+2.04901523*$airTemperature+10.14333127*$relativeHumidity-0.22475541*$airTemperature*$relativeHumidity-6.83783*(Math.pow(10, -3))*(Math.pow($airTemperature, 2))-5.481717*(Math.pow(10, -2))*(Math.pow($relativeHumidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow($airTemperature, 2))*$relativeHumidity+8.5282*(Math.pow(10, -4))*$airTemperature*(Math.pow($relativeHumidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow($airTemperature, 2))*(Math.pow($relativeHumidity,2)); + + if (($relativeHumidity <= 13) && ($airTemperature >= 80.0) && ($airTemperature <= 112.0)) { + $adj1 = (13.0-$relativeHumidity)/4.0; + $adj2 = Math.sqrt((17.0-Math.abs($airTemperature-95.0))/17.0); + $adj = $adj1 * $adj2; + $hi = $hi - $adj; + } + else if (($relativeHumidity > 85.0) && ($airTemperature >= 80.0) && ($airTemperature <= 87.0)) { + $adj1 = ($relativeHumidity-85.0)/10.0; + $adj2 = (87.0-$airTemperature)/5.0; + $adj = $adj1 * $adj2; + $hi = $hi + $adj; + } + } + else { + $hi = $hifinal; + } + } + + return $hi; +} + ?> From af2995b3730ca43f1e2039704c19d08f828a2bf2 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Thu, 14 Jul 2016 13:40:46 -0500 Subject: [PATCH 02/26] Second attempt at "feels like" --- current.php | 150 +++++++++++++++++++++++++++------------------------- 1 file changed, 78 insertions(+), 72 deletions(-) diff --git a/current.php b/current.php index ddf9daa..05a9294 100644 --- a/current.php +++ b/current.php @@ -23,58 +23,64 @@ $numberOfRows = 0; while($row = mysqli_fetch_array($result)) { // Rows - $numberOfRows++; + $numberOfRows++; if ($numberOfRows > 1) { echo ", "; } - echo "\r\n\t\t\"Observation" . $numberOfRows . "\" : {"; - - for ($i = 0; $i < $fieldcount; $i++) { // Columns - $fieldName = $fields[$i]; - $fieldValue = $row[$i]; - + echo "\r\n\t\t\"Observation" . $numberOfRows . "\" : {"; - if (strpos($fieldName, "_TEMPERATURE")) { - if ($showMetricAndCelsiusMeasurements) { - echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . "° C\","; + for ($i = 0; $i < $fieldcount; $i++) { // Columns + $fieldName = $fields[$i]; + $fieldValue = $row[$i]; + + if (strpos($fieldName, "_TEMPERATURE")) { + if ($showMetricAndCelsiusMeasurements) { + echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . "° C\","; + } + else { + $fieldValue = convertCelsiusToFahrenheit($fieldValue); + echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . "° F\","; + } } - else { - $fieldValue = convertCelsiusToFahrenheit($fieldValue); - echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . "° F\","; - } - } - - if (strpos($fieldName, "_SPEED")) { - if ($showMetricAndCelsiusMeasurements) { - echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " Km/H\","; + + if (strpos($fieldName, "_SPEED")) { + if ($showMetricAndCelsiusMeasurements) { + echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " Km/H\","; + } + else { + $fieldValue = convertKilometersToMiles($fieldValue); + echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " MPH\","; + } } - else { - $fieldValue = convertKilometersToMiles($fieldValue); - echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " MPH\","; + + if (strpos($fieldName, "_PRESSURE")) { + if ($showPressureInMillibars) { + echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " mb\","; + } + else { + $fieldValue = convertMillibarsToInches($fieldValue); + echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " in\","; + } } + + echo "\r\n\t\t\t\"" . $fieldName . "\" : " . "\"" . $fieldValue . "\""; + + //if ($i+1 < $fieldcount) { + echo ","; + //} } - if (strpos($fieldName, "_PRESSURE")) { - if ($showPressureInMillibars) { - echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " mb\","; - } - else { - $fieldValue = convertMillibarsToInches($fieldValue); - echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . " in\","; - } + $feelsLike = calculateFeelsLike($result[0]["AMBIENT_TEMPERATURE"], $result[0]["HUMIDITY"], $result[0]["WIND_SPEED"]); + if (!$showMetricAndCelsiusMeasurements) { + $feelsLike = convertCelsiusToFahrenheit($feelsLike); } + echo "\r\n\t\t\t\"FEELS_LIKE\" : " . "\"" . $feelsLike . "\""; - echo "\r\n\t\t\t\"" . $fieldName . "\" : " . "\"" . $fieldValue . "\""; - - if ($i+1 < $fieldcount) { - echo ","; - } - } - - echo "\r\n\t\t}"; + echo "\r\n\t\t}"; } + $result->close(); $con->next_result(); } @@ -137,51 +143,51 @@ function convertCelsiusToFahrenheit($celsiusDegrees) { return $F; } +function convertFahrenheitToCelsius($fahrenheitDegrees) { + $C = ($fahrenheitDegrees - 32) * 5 / 9; + return $C; +} + function convertMillibarsToInches($millibars) { $inches = $millibars * 0.0295301; return $inches; } -function calculateHeatIndex($relativeHumidity, $airTemperature) { - $airTemperature = convertCelsiusToFahrenheit($airTemperature); +function calculateFeelsLike($temperature, $humidity, $windSpeed) { + $tempF = convertCelsiusToFahrenheit($temperature); + $windMPH = convertKilometersToMiles($windSpeed); - if ($relativeHumidity > 100){ - $relativeHumidity = 100; - } - else if ($relativeHumidity < 0) { - $relativeHumidity = 0; + // Calculate Heat Index based on temperature in F and relative humidity (65 = 65%) + if ($tempF > 79 && $rh > 39) { + $feelsLike = -42.379 + 2.04901523 * $tempF + 10.14333127 * $humidity - 0.22475541 * $tempF * $humidity; + $feelsLike += -0.00683783 * pow($tempF, 2) - 0.05481717 * pow($humidity, 2); + $feelsLike += 0.00122874 * pow($tempF, 2) * $humidity + 0.00085282 * $tempF * pow($humidity, 2); + $feelsLike += -0.00000199 * pow($tempF, 2) * pow($humidity, 2); + $feelsLike = round($feelsLike); } - - if ($airTemperature <= 40.0) { - $hi = $airTemperature; + elseif (($tempF < 51) && ($windMPH > 3)) { + $feelsLike = 35.74 + 0.6215 * $tempF - 35.75 * pow($windMPH, 0.16) + 0.4275 * $tempF * pow($windMPH, 0.16); + $feelsLike = round($feelsLike); } else { - $hitemp = 61.0+(($airTemperature-68.0)*1.2)+($relativeHumidity*0.094); - $fptemp = $airTemperature; - $hifinal = 0.5*($fptemp+$hitemp); - - if ($hifinal > 79.0) { - $hi = -42.379+2.04901523*$airTemperature+10.14333127*$relativeHumidity-0.22475541*$airTemperature*$relativeHumidity-6.83783*(Math.pow(10, -3))*(Math.pow($airTemperature, 2))-5.481717*(Math.pow(10, -2))*(Math.pow($relativeHumidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow($airTemperature, 2))*$relativeHumidity+8.5282*(Math.pow(10, -4))*$airTemperature*(Math.pow($relativeHumidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow($airTemperature, 2))*(Math.pow($relativeHumidity,2)); - - if (($relativeHumidity <= 13) && ($airTemperature >= 80.0) && ($airTemperature <= 112.0)) { - $adj1 = (13.0-$relativeHumidity)/4.0; - $adj2 = Math.sqrt((17.0-Math.abs($airTemperature-95.0))/17.0); - $adj = $adj1 * $adj2; - $hi = $hi - $adj; - } - else if (($relativeHumidity > 85.0) && ($airTemperature >= 80.0) && ($airTemperature <= 87.0)) { - $adj1 = ($relativeHumidity-85.0)/10.0; - $adj2 = (87.0-$airTemperature)/5.0; - $adj = $adj1 * $adj2; - $hi = $hi + $adj; - } - } - else { - $hi = $hifinal; - } + $feelsLike = $tempF; } - return $hi; + return $feelsLike; +} + +// Calculate Wind Chill Temperature based on temperature in F and wind speed in miles per hour +function get_wind_chill($tempF, &$wxInfo) { + if ($tempF < 51 && $wxInfo['WIND'] != 'calm') { + $pieces = explode(' ', $wxInfo['WIND']); + $windspeed = (integer) $pieces[2]; // wind speed must be in miles per hour + if ($windspeed > 3) { + $chillF = 35.74 + 0.6215 * $tempF - 35.75 * pow($windspeed, 0.16) + 0.4275 * $tempF * pow($windspeed, 0.16); + $chillF = round($chillF); + $chillC = round(($chillF - 32) / 1.8); + $wxInfo['WIND CHILL'] = "$chillF°F ($chillC°C)"; + } + } } ?> From 29511ae1017f7d7d9048e3d2881d719d615c1c20 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Thu, 14 Jul 2016 14:04:53 -0500 Subject: [PATCH 03/26] Another lazy commit for debugging --- current.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/current.php b/current.php index 05a9294..ec5666a 100644 --- a/current.php +++ b/current.php @@ -31,10 +31,18 @@ echo "\r\n\t\t\"Observation" . $numberOfRows . "\" : {"; + if ($numberOfRows == 1) { + $feelsLike = calculateFeelsLike($result[0]["AMBIENT_TEMPERATURE"], $result[0]["HUMIDITY"], $result[0]["WIND_SPEED"]); + if (!$showMetricAndCelsiusMeasurements) { + $feelsLike = convertCelsiusToFahrenheit($feelsLike); + } + echo "\r\n\t\t\t\"FEELS_LIKE\" : " . "\"" . $feelsLike . "\","; + } + for ($i = 0; $i < $fieldcount; $i++) { // Columns $fieldName = $fields[$i]; $fieldValue = $row[$i]; - + if (strpos($fieldName, "_TEMPERATURE")) { if ($showMetricAndCelsiusMeasurements) { echo "\r\n\t\t\t\"" . $fieldName . "_STRING\" : " . "\"" . $fieldValue . "° C\","; @@ -67,16 +75,10 @@ echo "\r\n\t\t\t\"" . $fieldName . "\" : " . "\"" . $fieldValue . "\""; - //if ($i+1 < $fieldcount) { + if ($i+1 < $fieldcount) { echo ","; - //} - } - - $feelsLike = calculateFeelsLike($result[0]["AMBIENT_TEMPERATURE"], $result[0]["HUMIDITY"], $result[0]["WIND_SPEED"]); - if (!$showMetricAndCelsiusMeasurements) { - $feelsLike = convertCelsiusToFahrenheit($feelsLike); + } } - echo "\r\n\t\t\t\"FEELS_LIKE\" : " . "\"" . $feelsLike . "\""; echo "\r\n\t\t}"; } From 9889011fcd2920caa15e80434cd3bbdf6077c35b Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Thu, 14 Jul 2016 14:06:18 -0500 Subject: [PATCH 04/26] Cannot use object of type mysqli_result as array --- current.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/current.php b/current.php index ec5666a..a255e75 100644 --- a/current.php +++ b/current.php @@ -32,7 +32,7 @@ echo "\r\n\t\t\"Observation" . $numberOfRows . "\" : {"; if ($numberOfRows == 1) { - $feelsLike = calculateFeelsLike($result[0]["AMBIENT_TEMPERATURE"], $result[0]["HUMIDITY"], $result[0]["WIND_SPEED"]); + $feelsLike = calculateFeelsLike($row["AMBIENT_TEMPERATURE"], $row["HUMIDITY"], $row["WIND_SPEED"]); if (!$showMetricAndCelsiusMeasurements) { $feelsLike = convertCelsiusToFahrenheit($feelsLike); } From 3ee6a6d4e2471b94c602e680fa3353c4daa85ab0 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Thu, 14 Jul 2016 14:08:59 -0500 Subject: [PATCH 05/26] Fixed reference to undefined variable --- current.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/current.php b/current.php index a255e75..4c84a14 100644 --- a/current.php +++ b/current.php @@ -160,7 +160,7 @@ function calculateFeelsLike($temperature, $humidity, $windSpeed) { $windMPH = convertKilometersToMiles($windSpeed); // Calculate Heat Index based on temperature in F and relative humidity (65 = 65%) - if ($tempF > 79 && $rh > 39) { + if ($tempF > 79 && $humidity > 39) { $feelsLike = -42.379 + 2.04901523 * $tempF + 10.14333127 * $humidity - 0.22475541 * $tempF * $humidity; $feelsLike += -0.00683783 * pow($tempF, 2) - 0.05481717 * pow($humidity, 2); $feelsLike += 0.00122874 * pow($tempF, 2) * $humidity + 0.00085282 * $tempF * pow($humidity, 2); @@ -175,7 +175,7 @@ function calculateFeelsLike($temperature, $humidity, $windSpeed) { $feelsLike = $tempF; } - return $feelsLike; + return convertFahrenheitToCelsius($feelsLike); } // Calculate Wind Chill Temperature based on temperature in F and wind speed in miles per hour From 33dc9f019ce89aeccce344d6c5e81a221c6c1ed5 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Fri, 15 Jul 2016 17:44:36 -0500 Subject: [PATCH 06/26] Added variable for database schema --- current.php | 2 +- variables.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/current.php b/current.php index 4c84a14..59e1732 100644 --- a/current.php +++ b/current.php @@ -2,7 +2,7 @@ include 'variables.php'; header('content-type: application/json; charset=utf-8'); header("access-control-allow-origin: *"); -$con = new mysqli($databaseAddress,$databaseUsername,$databasePassword,'weather'); +$con = new mysqli($databaseAddress,$databaseUsername,$databasePassword, $databaseSchema); // Check connection if (mysqli_connect_errno()) { diff --git a/variables.php b/variables.php index ca34b9f..c78c4fe 100644 --- a/variables.php +++ b/variables.php @@ -4,6 +4,7 @@ $databaseAddress = '127.0.0.1'; $databaseUsername = 'root'; $databasePassword = 'tiger'; +$databaseSchema = 'weather'; // ___ Preferences _____________________________________________________ // These settings only change the display. Does not effect the values stored in the database. From e793de9e18fe6a303e3bf79954615fc493608532 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Fri, 15 Jul 2016 17:45:02 -0500 Subject: [PATCH 07/26] Initial draft of Weather Underground API hook --- wunderground-api.php | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 wunderground-api.php diff --git a/wunderground-api.php b/wunderground-api.php new file mode 100644 index 0000000..a7685d0 --- /dev/null +++ b/wunderground-api.php @@ -0,0 +1,74 @@ += DATEADD(HOUR, -1, GETDATE()) INTO @rainPastHour; + +SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW()) INTO @rainSinceMidnight; + +SELECT WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, @rainPastHour, @rainSinceMidnight, AIR_PRESSURE, GROUND_TEMPERATURE FROM WEATHER + + +*/ + +echo "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC%20Raspberry%20Pi%20Wx%20Dashboard&"; + +$sql = "SELECT SUM(Rainfall) as rainPastHour FROM WEATHER_MEASUREMENT WHERE created >= DATEADD(HOUR, -1, GETDATE());"; +$result = mysql_query($sql); +$value = mysql_fetch_object($result); +$rainPastHour = $value->rainPastHour; +echo "rainin=" . $rainPastHour . "&"; + + +$sql = "SELECT SUM(Rainfall) as rainSinceMidnight FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW());"; +$result = mysql_query($sql); +$value = mysql_fetch_object($result); +$rainSinceMidnight = $value->rainSinceMidnight; +echo "dailyrainin=" . $rainSinceMidnight . "&"; + +$result = $con->query('SELECT WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE FROM WEATHER_MEASUREMENT ORDER BY CREATED DESC LIMIT 1'); + +if ($result->num_rows > 0) { + $row = mysqli_fetch_array($result); + + echo "winddir=" . $row["WIND_DIRECTION"] . "&"; + echo "windspeedmph=" . $row["WIND_SPEED"] . "&"; + echo "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; + echo "humidity=" . $row["HUMIDITY"] . "&"; + echo "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; + echo "baromin=" . $row["AIR_PRESSURE"] . "&"; + echo "soiltempf " . $row["GROUND_TEMPERATURE"] . "&"; + + $result->close(); + $con->next_result(); +} + +$result->close(); +mysqli_close($con); + +// =============================================================== +function convertKilometersToMiles($kilometers) { + $miles = $kilometers * 0.621371; + return $miles; +} + +function convertCelsiusToFahrenheit($celsiusDegrees) { + $F = ((($celsiusDegrees * 9) / 5) + 32); + return $F; +} + +function convertMillibarsToInches($millibars) { + $inches = $millibars * 0.0295301; + return $inches; +} + + +?> From 26741f12598750ac473ebeae468199a6133840fd Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Fri, 15 Jul 2016 22:37:31 -0500 Subject: [PATCH 08/26] Fixed SQL reference error --- wunderground-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index a7685d0..5a279a8 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -22,14 +22,14 @@ echo "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC%20Raspberry%20Pi%20Wx%20Dashboard&"; $sql = "SELECT SUM(Rainfall) as rainPastHour FROM WEATHER_MEASUREMENT WHERE created >= DATEADD(HOUR, -1, GETDATE());"; -$result = mysql_query($sql); +$result = $con->query($sql); $value = mysql_fetch_object($result); $rainPastHour = $value->rainPastHour; echo "rainin=" . $rainPastHour . "&"; $sql = "SELECT SUM(Rainfall) as rainSinceMidnight FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW());"; -$result = mysql_query($sql); +$result = $con->query($sql); $value = mysql_fetch_object($result); $rainSinceMidnight = $value->rainSinceMidnight; echo "dailyrainin=" . $rainSinceMidnight . "&"; From 8f1de62571445b85132abdcdedeef03acdd347f7 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Fri, 15 Jul 2016 23:53:54 -0500 Subject: [PATCH 09/26] Created GETWUNDERGROUNDDATA stored procedure --- CREATE-SP.sql | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CREATE-SP.sql b/CREATE-SP.sql index fd7a19d..c58c4d3 100644 --- a/CREATE-SP.sql +++ b/CREATE-SP.sql @@ -1,7 +1,8 @@ -DELIMITER $$ DROP PROCEDURE IF EXISTS GETRECENTOBS; DROP PROCEDURE IF EXISTS GETDAILYRECORDS; +DROP PROCEDURE IF EXISTS GETWUNDERGROUNDDATA; +DELIMITER $$ CREATE PROCEDURE `GETRECENTOBS`() BEGIN (SELECT @@ -66,4 +67,12 @@ BEGIN @stormTotal AS LastStormTotal, @LowSinceMidnight AS LowSinceMidnight, @HighSinceMidnight AS HighSinceMidnight; -END## \ No newline at end of file +END## + +DELIMITER && +CREATE PROCEDURE `GETWUNDERGROUNDDATA`() +BEGIN + SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE_SUB(NOW(),INTERVAL 1 HOUR) INTO @rainPastHour; + SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW()) INTO @rainSinceMidnight; + SELECT WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE, @rainPastHour, @rainSinceMidnight FROM WEATHER_MEASUREMENT ORDER BY created DESC LIMIT 1; +END&& \ No newline at end of file From 827ec3770cf3c7e11a7740feec9d11764d8db42c Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Fri, 15 Jul 2016 23:54:20 -0500 Subject: [PATCH 10/26] Executed GETWUNDERGROUNDDATA stored procedure --- wunderground-api.php | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index 5a279a8..30b3389 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -9,32 +9,9 @@ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } -/* -SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATEADD(HOUR, -1, GETDATE()) INTO @rainPastHour; - -SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW()) INTO @rainSinceMidnight; - -SELECT WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, @rainPastHour, @rainSinceMidnight, AIR_PRESSURE, GROUND_TEMPERATURE FROM WEATHER - - -*/ - echo "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC%20Raspberry%20Pi%20Wx%20Dashboard&"; -$sql = "SELECT SUM(Rainfall) as rainPastHour FROM WEATHER_MEASUREMENT WHERE created >= DATEADD(HOUR, -1, GETDATE());"; -$result = $con->query($sql); -$value = mysql_fetch_object($result); -$rainPastHour = $value->rainPastHour; -echo "rainin=" . $rainPastHour . "&"; - - -$sql = "SELECT SUM(Rainfall) as rainSinceMidnight FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW());"; -$result = $con->query($sql); -$value = mysql_fetch_object($result); -$rainSinceMidnight = $value->rainSinceMidnight; -echo "dailyrainin=" . $rainSinceMidnight . "&"; - -$result = $con->query('SELECT WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE FROM WEATHER_MEASUREMENT ORDER BY CREATED DESC LIMIT 1'); +$result = $con->query('call GETWUNDERGROUNDDATA'); if ($result->num_rows > 0) { $row = mysqli_fetch_array($result); @@ -45,7 +22,9 @@ echo "humidity=" . $row["HUMIDITY"] . "&"; echo "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; echo "baromin=" . $row["AIR_PRESSURE"] . "&"; - echo "soiltempf " . $row["GROUND_TEMPERATURE"] . "&"; + echo "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; + echo "rainin=" . $row["@rainPastHour"] . "&"; + echo "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; $result->close(); $con->next_result(); From 36ab5ddc5aeda8aced641a4929256b17f9c23a88 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 00:04:16 -0500 Subject: [PATCH 11/26] Fixed php syntax error --- wunderground-api.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index 30b3389..4b5282d 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -10,12 +10,10 @@ } echo "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC%20Raspberry%20Pi%20Wx%20Dashboard&"; - $result = $con->query('call GETWUNDERGROUNDDATA'); if ($result->num_rows > 0) { $row = mysqli_fetch_array($result); - echo "winddir=" . $row["WIND_DIRECTION"] . "&"; echo "windspeedmph=" . $row["WIND_SPEED"] . "&"; echo "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; @@ -25,13 +23,10 @@ echo "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; echo "rainin=" . $row["@rainPastHour"] . "&"; echo "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; - - $result->close(); - $con->next_result(); } $result->close(); -mysqli_close($con); +$con->close(); // =============================================================== function convertKilometersToMiles($kilometers) { From 4480e6ef484a2884377a7bdb31fe2666f56194c8 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 00:24:30 -0500 Subject: [PATCH 12/26] Added record time in UTC --- CREATE-SP.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CREATE-SP.sql b/CREATE-SP.sql index c58c4d3..6c6f8c5 100644 --- a/CREATE-SP.sql +++ b/CREATE-SP.sql @@ -74,5 +74,5 @@ CREATE PROCEDURE `GETWUNDERGROUNDDATA`() BEGIN SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE_SUB(NOW(),INTERVAL 1 HOUR) INTO @rainPastHour; SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW()) INTO @rainSinceMidnight; - SELECT WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE, @rainPastHour, @rainSinceMidnight FROM WEATHER_MEASUREMENT ORDER BY created DESC LIMIT 1; + SELECT CONVERT_TZ(CREATED, @@session.time_zone, '+00:00') as CREATEDUTC, WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE, @rainPastHour, @rainSinceMidnight FROM WEATHER_MEASUREMENT ORDER BY created DESC LIMIT 1; END&& \ No newline at end of file From a78aed4a06afe21200814131df2ecf7b63053937 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 00:24:43 -0500 Subject: [PATCH 13/26] Added observation time --- wunderground-api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/wunderground-api.php b/wunderground-api.php index 4b5282d..e64c585 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -14,6 +14,7 @@ if ($result->num_rows > 0) { $row = mysqli_fetch_array($result); + echo "dateutc=" . $row["CREATEDUTC"] . "&"; echo "winddir=" . $row["WIND_DIRECTION"] . "&"; echo "windspeedmph=" . $row["WIND_SPEED"] . "&"; echo "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; From efd01dd42420ccf2ed7a07827fb6e3f9d2e26ea0 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 00:28:14 -0500 Subject: [PATCH 14/26] URL encoded strings --- wunderground-api.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index e64c585..919cb8b 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -9,26 +9,29 @@ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } -echo "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC%20Raspberry%20Pi%20Wx%20Dashboard&"; +$url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC Raspberry Pi Wx Dashboard&"; $result = $con->query('call GETWUNDERGROUNDDATA'); if ($result->num_rows > 0) { $row = mysqli_fetch_array($result); - echo "dateutc=" . $row["CREATEDUTC"] . "&"; - echo "winddir=" . $row["WIND_DIRECTION"] . "&"; - echo "windspeedmph=" . $row["WIND_SPEED"] . "&"; - echo "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; - echo "humidity=" . $row["HUMIDITY"] . "&"; - echo "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; - echo "baromin=" . $row["AIR_PRESSURE"] . "&"; - echo "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; - echo "rainin=" . $row["@rainPastHour"] . "&"; - echo "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; + $url += "dateutc=" . $row["CREATEDUTC"] . "&"; + $url += "winddir=" . $row["WIND_DIRECTION"] . "&"; + $url += "windspeedmph=" . $row["WIND_SPEED"] . "&"; + $url += "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; + $url += "humidity=" . $row["HUMIDITY"] . "&"; + $url += "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; + $url += "baromin=" . $row["AIR_PRESSURE"] . "&"; + $url += "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; + $url += "rainin=" . $row["@rainPastHour"] . "&"; + $url += "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; } $result->close(); $con->close(); +$url = str_replace(" ", "%20", $url); +echo $url; + // =============================================================== function convertKilometersToMiles($kilometers) { $miles = $kilometers * 0.621371; From d7c9c8db822381705d6d4c5f35fafb9a13b29602 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 00:31:59 -0500 Subject: [PATCH 15/26] Debugging --- wunderground-api.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wunderground-api.php b/wunderground-api.php index 919cb8b..47b2f64 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -10,10 +10,11 @@ } $url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC Raspberry Pi Wx Dashboard&"; -$result = $con->query('call GETWUNDERGROUNDDATA'); +$result = $con->query('call GETWUNDERGROUNDDATA'); if ($result->num_rows > 0) { $row = mysqli_fetch_array($result); + $url += "dateutc=" . $row["CREATEDUTC"] . "&"; $url += "winddir=" . $row["WIND_DIRECTION"] . "&"; $url += "windspeedmph=" . $row["WIND_SPEED"] . "&"; @@ -29,6 +30,7 @@ $result->close(); $con->close(); +echo $url . "
"; $url = str_replace(" ", "%20", $url); echo $url; From a36cf742df546e450e97fc5007d78e0e7d38beb2 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 00:52:30 -0500 Subject: [PATCH 16/26] Fixed PHP syntax error --- wunderground-api.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index 47b2f64..14c4b13 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -15,22 +15,21 @@ if ($result->num_rows > 0) { $row = mysqli_fetch_array($result); - $url += "dateutc=" . $row["CREATEDUTC"] . "&"; - $url += "winddir=" . $row["WIND_DIRECTION"] . "&"; - $url += "windspeedmph=" . $row["WIND_SPEED"] . "&"; - $url += "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; - $url += "humidity=" . $row["HUMIDITY"] . "&"; - $url += "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; - $url += "baromin=" . $row["AIR_PRESSURE"] . "&"; - $url += "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; - $url += "rainin=" . $row["@rainPastHour"] . "&"; - $url += "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; + $url .= "dateutc=" . $row["CREATEDUTC"] . "&"; + $url .= "winddir=" . $row["WIND_DIRECTION"] . "&"; + $url .= "windspeedmph=" . $row["WIND_SPEED"] . "&"; + $url .= "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; + $url .= "humidity=" . $row["HUMIDITY"] . "&"; + $url .= "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; + $url .= "baromin=" . $row["AIR_PRESSURE"] . "&"; + $url .= "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; + $url .= "rainin=" . $row["@rainPastHour"] . "&"; + $url .= "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; } $result->close(); $con->close(); -echo $url . "
"; $url = str_replace(" ", "%20", $url); echo $url; From a2346a13008a7a6413d192b0f8940efb496d4317 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 01:34:52 -0500 Subject: [PATCH 17/26] Added settings table definition --- CREATE-SP.sql | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CREATE-SP.sql b/CREATE-SP.sql index 6c6f8c5..ddc90b0 100644 --- a/CREATE-SP.sql +++ b/CREATE-SP.sql @@ -2,6 +2,14 @@ DROP PROCEDURE IF EXISTS GETRECENTOBS; DROP PROCEDURE IF EXISTS GETDAILYRECORDS; DROP PROCEDURE IF EXISTS GETWUNDERGROUNDDATA; +CREATE TABLE IF NOT EXISTS `SETTINGS` ( + `idSETTINGS` int(11) NOT NULL AUTO_INCREMENT, + `NAME` varchar(45) DEFAULT NULL, + `VALUE` varchar(45) DEFAULT NULL, + PRIMARY KEY (`idSETTINGS`), + UNIQUE KEY `NAME_UNIQUE` (`NAME`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; + DELIMITER $$ CREATE PROCEDURE `GETRECENTOBS`() BEGIN @@ -74,5 +82,7 @@ CREATE PROCEDURE `GETWUNDERGROUNDDATA`() BEGIN SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE_SUB(NOW(),INTERVAL 1 HOUR) INTO @rainPastHour; SELECT SUM(Rainfall) FROM WEATHER_MEASUREMENT WHERE created >= DATE(NOW()) INTO @rainSinceMidnight; - SELECT CONVERT_TZ(CREATED, @@session.time_zone, '+00:00') as CREATEDUTC, WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE, @rainPastHour, @rainSinceMidnight FROM WEATHER_MEASUREMENT ORDER BY created DESC LIMIT 1; + SELECT VALUE FROM SETTINGS WHERE NAME = 'WUNDERGROUND_ID' LIMIT 1 INTO @WUNDERGROUND_ID; + SELECT VALUE FROM SETTINGS WHERE NAME = 'WUNDERGROUND_PASSWORD' LIMIT 1 INTO @WUNDERGROUND_PASSWORD; + SELECT CONVERT_TZ(CREATED, @@session.time_zone, '+00:00') as CREATEDUTC, WIND_DIRECTION, WIND_SPEED, WIND_GUST_SPEED, HUMIDITY, AMBIENT_TEMPERATURE, AIR_PRESSURE, GROUND_TEMPERATURE, @rainPastHour, @rainSinceMidnight, @WUNDERGROUND_ID, @WUNDERGROUND_PASSWORD FROM WEATHER_MEASUREMENT ORDER BY created DESC LIMIT 1; END&& \ No newline at end of file From 97983c251ab4d9bc15f29d761c422b5caa02bdcb Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 01:35:23 -0500 Subject: [PATCH 18/26] Added settings from database, call URL --- wunderground-api.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index 14c4b13..09e182e 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -9,7 +9,7 @@ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } -$url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&softwaretype=N5JLC Raspberry Pi Wx Dashboard&"; +$url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?softwaretype=N5JLC Raspberry Pi Wx Dashboard&"; $result = $con->query('call GETWUNDERGROUNDDATA'); if ($result->num_rows > 0) { @@ -25,13 +25,16 @@ $url .= "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; $url .= "rainin=" . $row["@rainPastHour"] . "&"; $url .= "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; + $url .= "id=" . $row["@WUNDERGROUND_ID"] . "&"; + $url .= "password=" . $row["@WUNDERGROUND_PASSWORD"] . "&"; } $result->close(); $con->close(); $url = str_replace(" ", "%20", $url); -echo $url; + +echo file_get_contents($url); // =============================================================== function convertKilometersToMiles($kilometers) { From 6f450943702e66ba2fc8d8e2d162175604654c5e Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 01:37:59 -0500 Subject: [PATCH 19/26] Added debugging --- wunderground-api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/wunderground-api.php b/wunderground-api.php index 09e182e..2a8ef24 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -34,6 +34,7 @@ $url = str_replace(" ", "%20", $url); +echo $url . "
"; echo file_get_contents($url); // =============================================================== From 368753f5b7c07ba1abc15ef4b32161a3fc02a360 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 01:44:28 -0500 Subject: [PATCH 20/26] Apparently case matters --- wunderground-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index 2a8ef24..6774464 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -25,8 +25,8 @@ $url .= "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; $url .= "rainin=" . $row["@rainPastHour"] . "&"; $url .= "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; - $url .= "id=" . $row["@WUNDERGROUND_ID"] . "&"; - $url .= "password=" . $row["@WUNDERGROUND_PASSWORD"] . "&"; + $url .= "ID=" . $row["@WUNDERGROUND_ID"] . "&"; + $url .= "PASSWORD=" . $row["@WUNDERGROUND_PASSWORD"] . "&"; } $result->close(); From d9e5f464b5faf9e5392a81e7de017f84987ff9c9 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 01:45:00 -0500 Subject: [PATCH 21/26] Removed debugging. --- wunderground-api.php | 1 - 1 file changed, 1 deletion(-) diff --git a/wunderground-api.php b/wunderground-api.php index 6774464..db8089a 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -34,7 +34,6 @@ $url = str_replace(" ", "%20", $url); -echo $url . "
"; echo file_get_contents($url); // =============================================================== From 0178e149601478287cb2825d4e5aae51bca0d016 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 01:52:07 -0500 Subject: [PATCH 22/26] Added conversions --- wunderground-api.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/wunderground-api.php b/wunderground-api.php index db8089a..9f522d1 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -17,14 +17,14 @@ $url .= "dateutc=" . $row["CREATEDUTC"] . "&"; $url .= "winddir=" . $row["WIND_DIRECTION"] . "&"; - $url .= "windspeedmph=" . $row["WIND_SPEED"] . "&"; - $url .= "windgustmph=" . $row["WIND_GUST_SPEED"] . "&"; + $url .= "windspeedmph=" . convertKilometersToMiles($row["WIND_SPEED"]) . "&"; + $url .= "windgustmph=" . convertKilometersToMiles($row["WIND_GUST_SPEED"]) . "&"; $url .= "humidity=" . $row["HUMIDITY"] . "&"; - $url .= "tempf=" . $row["AMBIENT_TEMPERATURE"] . "&"; - $url .= "baromin=" . $row["AIR_PRESSURE"] . "&"; - $url .= "soiltempf=" . $row["GROUND_TEMPERATURE"] . "&"; - $url .= "rainin=" . $row["@rainPastHour"] . "&"; - $url .= "dailyrainin=" . $row["@rainSinceMidnight"] . "&"; + $url .= "tempf=" . convertCelsiusToFahrenheit($row["AMBIENT_TEMPERATURE"]) . "&"; + $url .= "baromin=" . convertMillibarsToInches($row["AIR_PRESSURE"]) . "&"; + $url .= "soiltempf=" . convertCelsiusToFahrenheit($row["GROUND_TEMPERATURE"]) . "&"; + $url .= "rainin=" . convertmillimetersToInches($row["@rainPastHour"]) . "&"; + $url .= "dailyrainin=" . convertmillimetersToInches($row["@rainSinceMidnight"]) . "&"; $url .= "ID=" . $row["@WUNDERGROUND_ID"] . "&"; $url .= "PASSWORD=" . $row["@WUNDERGROUND_PASSWORD"] . "&"; } @@ -52,5 +52,10 @@ function convertMillibarsToInches($millibars) { return $inches; } +function convertmillimetersToInches($mm) { + $inches = $mm * 0.039370; + return $inches; +} + ?> From 71aab75fec4772f25d76c1af6caa1e2631195be1 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 02:29:17 -0500 Subject: [PATCH 23/26] Updated README... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated README to include crude instructions for setting up Weather Underground integration. I’ll improve the process later. --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9d74a96..a80d90a 100644 --- a/README.md +++ b/README.md @@ -72,11 +72,23 @@ You should now be in `/var/www/html/dashboard` `ifconfig` - The IP address will be on the second line just after `inet addr:` + The IP address will be on the second line just after `inet addr:`. Enter this IP address into a browser followed by `/dashboard`. For example: -Enter this IP address into a browser followed by `/dashboard`. For example: + `http://192.168.0.X/dashboard` + +### Set up external API's (optional) + +- Weather Underground + -- Populate WUNDERGROUND_ID and WUNDERGROUND_PASSWORD in the Settings table. + -- Open crontab for editing. + + `crontab -e` + + -- Copy this line and paste it into CRON: + + `*/10 * * * * curl http://localhost/dev/wunderground-api.php` - - `http://192.168.0.X/dashboard` + Press `Ctrl O` then `Enter` to save and `Ctrl X` to quit nano. ---------- From 2bf9b57d33d9639c0416ba2a9e97ef2b6a53b99b Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 12:51:43 -0500 Subject: [PATCH 24/26] Added default values for settings table --- CREATE-SP.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CREATE-SP.sql b/CREATE-SP.sql index ddc90b0..98aefe0 100644 --- a/CREATE-SP.sql +++ b/CREATE-SP.sql @@ -2,6 +2,7 @@ DROP PROCEDURE IF EXISTS GETRECENTOBS; DROP PROCEDURE IF EXISTS GETDAILYRECORDS; DROP PROCEDURE IF EXISTS GETWUNDERGROUNDDATA; +-- Create the Settings table if it doesn't exist CREATE TABLE IF NOT EXISTS `SETTINGS` ( `idSETTINGS` int(11) NOT NULL AUTO_INCREMENT, `NAME` varchar(45) DEFAULT NULL, @@ -10,6 +11,13 @@ CREATE TABLE IF NOT EXISTS `SETTINGS` ( UNIQUE KEY `NAME_UNIQUE` (`NAME`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; +-- Add the known settings. This won't add them if they are there because of the Unique key. +INSERT IGNORE INTO SETTINGS (name) VALUE ('WUNDERGROUND_ID'); +INSERT IGNORE INTO SETTINGS (name) VALUE ('WUNDERGROUND_PASSWORD'); +INSERT IGNORE INTO SETTINGS (name) VALUE ('showMetricAndCelsiusMeasurements'); +INSERT IGNORE INTO SETTINGS (name) VALUE ('showPressureInMillibars'); + +-- Create the stored procedures DELIMITER $$ CREATE PROCEDURE `GETRECENTOBS`() BEGIN From 6a13a7d5e80a8e93ce865685cdbd078f9e5271a5 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sat, 16 Jul 2016 12:52:48 -0500 Subject: [PATCH 25/26] Renamed software to be more generic --- wunderground-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wunderground-api.php b/wunderground-api.php index 9f522d1..f23f54f 100644 --- a/wunderground-api.php +++ b/wunderground-api.php @@ -9,7 +9,7 @@ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } -$url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?softwaretype=N5JLC Raspberry Pi Wx Dashboard&"; +$url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?softwaretype=Raspberry Pi Weather Station Dashboard&"; $result = $con->query('call GETWUNDERGROUNDDATA'); if ($result->num_rows > 0) { From 1f1b7e8a06d81523408724025c05fa3f5cea7d64 Mon Sep 17 00:00:00 2001 From: Joshua Carroll Date: Sun, 17 Jul 2016 01:33:16 -0500 Subject: [PATCH 26/26] Added instructions for API integration --- README-API-WeatherUnderground.md | 23 +++++++++++++++++++++++ README.md | 12 +----------- 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 README-API-WeatherUnderground.md diff --git a/README-API-WeatherUnderground.md b/README-API-WeatherUnderground.md new file mode 100644 index 0000000..901e8ac --- /dev/null +++ b/README-API-WeatherUnderground.md @@ -0,0 +1,23 @@ +Weather Underground API integration +=================================== + +1. Run the SQL statement again. This is written in such a way that it will only add whatever you don't have. + + `mysql -u root -p weather < CREATE-SP.sql` + +2. Add your own values to the settings table. + + ``` + mysql -u root -p weather -e "update SETTINGS set value='YOUR-STATION-ID' where name='WUNDERGROUND_ID'" + mysql -u root -p weather -e "update SETTINGS set value='YOUR-STATION-PASSWORD' where name='WUNDERGROUND_PASSWORD'" + ``` + +3. Open CRONTAB to configure a recurring task. + + `crontab -e` + +4. Set up a CRON job to automatically send data to Weather Underground every 10 minutes. (Change the URL to match your environment.) + + `*/10 * * * * curl http://localhost/dashboard/wunderground-api.php` + +5. Press `Ctrl O` then `Enter` to save and `Ctrl X` to quit nano. \ No newline at end of file diff --git a/README.md b/README.md index a80d90a..cd27fb0 100644 --- a/README.md +++ b/README.md @@ -78,17 +78,7 @@ You should now be in `/var/www/html/dashboard` ### Set up external API's (optional) -- Weather Underground - -- Populate WUNDERGROUND_ID and WUNDERGROUND_PASSWORD in the Settings table. - -- Open crontab for editing. - - `crontab -e` - - -- Copy this line and paste it into CRON: - - `*/10 * * * * curl http://localhost/dev/wunderground-api.php` - - Press `Ctrl O` then `Enter` to save and `Ctrl X` to quit nano. +- Weather Underground: See [README-API-WeatherUnderground.md](README-API-WeatherUnderground.md). ----------