Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4018) - 28 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Current conditions, php and MySQL

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
billy
Posts: 255
Joined: Mon 30 Nov 2015 10:54 am
Weather Station: WLL / Davis VP2+
Operating System: RPi bullseye
Location: Gooseberry Hill, Western Australia

Current conditions, php and MySQL

Post by billy »

I am in the process of "upgrading" my website - currently a "standard" Cumulus MX site. Like many others I have been attracted (seduced!) by Mark Crossley's outstanding http://weather.wilmslowastro.com/index.php. What first drew my attention was its historical graphs section which provides many different ways of plotting the data in visually appealing ways and ease interpretation. It seems to me that collecting all these data is an awful waste if they can't easily be analyzed and well-presented! So, I now have a MySQL database and can get these plots (with a couple of exceptions that I will figure out eventually - they require queries to create extra tables other than the 3 standard ones).

Of course in getting to this point I started to appreciate some of the value of having the database and php, albeit without really having any skills in using them - I did write a few web pages just before the turn of the century but that was my previous web production experience! Statistical analysis is more up my alley.

So, it occurred to me that I should be able to use php to update the current conditions on a home/index page and dispense with the html template files (and indeed uploading of json files etc given all the data are already being uploaded to the database). Unsurprisingly, a search of the forum revealed others were way ahead of me on this approach. What I haven't seen (and maybe that is because of my inefficient searching methodology) is any exemplar of how one actually achieves this - at least for dummies like me. There are mentions of php scripts that will insert current Cumulus values into another php script (or at least that is implied) but I can't seem to view them to see how it might work in the Cumulus/MySQL setting. Indeed the Wilmslow index page seems to do this but the php file that presumable inserts the current conditions (I'm guessing it's getIndexPageData.php) does not seem to be available for viewing; it would be great if it was.

So, this is a long-winded way of asking if anyone can help me out here with some guidance? Or am I trying to do something way beyond my competence levels? The answer to that question is undoubtedly yes but I would like to give it a go!
User avatar
PaulMy
Posts: 3777
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: Current conditions, php and MySQL

Post by PaulMy »

Davis Vantage Pro2+
C1 www.komokaweather.com/komokaweather-ca
MX www.komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX www.komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX www. komokaweather.com/cumulusmx4/index.htm

Image
User avatar
PaulMy
Posts: 3777
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: Current conditions, php and MySQL

Post by PaulMy »

And another borrowed from the forum using the WU XML:

Code: Select all

						<h3>Current conditions from Weather Underground XML source
						<a href="https://api.wunderground.com/weatherstation/WXDailyHistory.asp?ID={use your own WU station ID}&format=XML">{use your own WU station ID} </a></h3>
						<?php
							$json_string = file_get_contents("http://api.wunderground.com/api/{to use your own WU API key}/conditions/q/pws:{use your own WU station ID}.json");
							$parsed_json = json_decode($json_string);
							$observation_time = $parsed_json->{'current_observation'}->{'observation_time'};
							$weather = $parsed_json->{'current_observation'}->{'weather'};
							$temperature_string = $parsed_json->{'current_observation'}->{'temperature_string'};
							$wind_kph = $parsed_json->{'current_observation'}->{'wind_kph'};
							$wind_dir = $parsed_json->{'current_observation'}->{'wind_dir'};
							$wind_gust_kph = $parsed_json->{'current_observation'}->{'wind_gust_kph'};
							$wind__gust_kph = $parsed_json->{'current_observation'}->{'wind_gust_kph'};
							$feelslike_string = $parsed_json->{'current_observation'}->{'feelslike_string'};
							$visibility_km = $parsed_json->{'current_observation'}->{'visibility_km'};
							$precip_today_string = $parsed_json->{'current_observation'}->{'precip_today_string'};
							echo "The weather in Komoka, ON Canada ${observation_time} is ${weather} <br /> and the temperature ${temperature_string} with average wind at ${wind_kph} kph from the ${wind_dir} and gusts of ${wind_gust_kph} kph.<br />  The temperature feels like ${feelslike_string}.<br />  The visibility is ${visibility_km} km. and precipitation today is ${precip_today_string} mm.\n";
						?>
Davis Vantage Pro2+
C1 www.komokaweather.com/komokaweather-ca
MX www.komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX www.komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX www. komokaweather.com/cumulusmx4/index.htm

Image
jlmr731
Posts: 225
Joined: Sat 27 Aug 2016 12:11 am
Weather Station: Davis vantage pro 2
Operating System: Debian
Location: Wickliffe, Ohio
Contact:

Re: Current conditions, php and MySQL

Post by jlmr731 »

alot depends on if you want to pull the data right from the database live for your page.
Yes there are many ways to do anything you want. most of my site data is right from the data base other than values that cumulus generates.
You can use php to query data into an array then you can just use php echo to show your values.

here is a little sample this just grabs the latest value for current conditions

Code: Select all

$getinfo = "SELECT * FROM Monthly ORDER BY LogDateTime DESC limit 1";
if ($result = $conn->query($getinfo)) {
	while ($row = $result->fetch_object()) {
	$datetime = $row->LogDateTime;
	$tempcur = $row->Temp;
	$humid = $row->Humidity;
	$press = $row->Pressure;
	$dew = $row->Dewpoint;
	$heatidx = $row->HeatIndex;
	$windchill = $row->WindChill;
###  you can put them all here like this	

then within your page you can call the data its almost like they way cumulus inserts the data

Code: Select all

								<td>Temperature</td>

									<td><?php echo "$tempcur" ?>&nbsp;&#176;F</td>

									<td>Dew&nbsp;point </td>

									<td><?php echo "$dew" ?>&nbsp;&#176;F</td>
guessing this is what your looking to achieve a good site to learn and there are many is w3schools.com they cover a lot there
User avatar
billy
Posts: 255
Joined: Mon 30 Nov 2015 10:54 am
Weather Station: WLL / Davis VP2+
Operating System: RPi bullseye
Location: Gooseberry Hill, Western Australia

Re: Current conditions, php and MySQL

Post by billy »

My apologies for the tardy reply - some unexpected pressing issues have distracted me from pursuing the quest. Thanks for taking the time to provide these suggestions. I will explore them when normality resumes.
Post Reply