-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from JoshuaCarroll/development
Development
- Loading branch information
Showing
6 changed files
with
206 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
include 'variables.php'; | ||
header("access-control-allow-origin: *"); | ||
|
||
$con = new mysqli($databaseAddress,$databaseUsername,$databasePassword,$databaseSchema); | ||
|
||
// Check connection | ||
if (mysqli_connect_errno()) { | ||
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | ||
} | ||
|
||
$url = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?softwaretype=Raspberry Pi Weather Station Dashboard&"; | ||
|
||
$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=" . convertKilometersToMiles($row["WIND_SPEED"]) . "&"; | ||
$url .= "windgustmph=" . convertKilometersToMiles($row["WIND_GUST_SPEED"]) . "&"; | ||
$url .= "humidity=" . $row["HUMIDITY"] . "&"; | ||
$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"] . "&"; | ||
} | ||
|
||
$result->close(); | ||
$con->close(); | ||
|
||
$url = str_replace(" ", "%20", $url); | ||
|
||
echo file_get_contents($url); | ||
|
||
// =============================================================== | ||
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; | ||
} | ||
|
||
function convertmillimetersToInches($mm) { | ||
$inches = $mm * 0.039370; | ||
return $inches; | ||
} | ||
|
||
|
||
?> |