Please read the posts in the Announcements section about the current status of Cumulus development now that I have retired

Please read this post before posting

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3043 Jan 20 2017. See this post for download

Current conditions, php and MySQL

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

Moderators: daj, TNETWeather

billy
Posts: 31
Joined: Mon Nov 30, 2015 10:54 am
Weather Station: WMR200
Operating System: RPi jessie
Location: Perth, Australia

Current conditions, php and MySQL

Postby billy » Mon Sep 11, 2017 1:47 pm

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: 1548
Joined: Sun Sep 28, 2008 11:54 pm
Weather Station: Davis Vantage Pro 2 w/Envoy USB
Operating System: Windows-8
Location: Komoka, ON Canada
Contact:

Re: Current conditions, php and MySQL

Postby PaulMy » Mon Sep 11, 2017 2:02 pm


User avatar
PaulMy
Posts: 1548
Joined: Sun Sep 28, 2008 11:54 pm
Weather Station: Davis Vantage Pro 2 w/Envoy USB
Operating System: Windows-8
Location: Komoka, ON Canada
Contact:

Re: Current conditions, php and MySQL

Postby PaulMy » Mon Sep 11, 2017 2:15 pm

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";
                  ?>

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

Re: Current conditions, php and MySQL

Postby jlmr731 » Tue Sep 12, 2017 1:19 am

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

billy
Posts: 31
Joined: Mon Nov 30, 2015 10:54 am
Weather Station: WMR200
Operating System: RPi jessie
Location: Perth, Australia

Re: Current conditions, php and MySQL

Postby billy » Tue Sep 12, 2017 2:06 pm

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.


Return to “Web site - General”

Who is online

Users browsing this forum: eboettn and 9 guests