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 4017) - 17 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

Interfacing Cumulus with a CMS-based website

For discussion of DIY weather equipment - sensors, accessories, improvements to existing kit etc
Post Reply
User avatar
kiwi_steve
Posts: 10
Joined: Sun 27 Dec 2009 2:51 am
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
Location: Christchurch, New Zealand

Interfacing Cumulus with a CMS-based website

Post by kiwi_steve »

Hi all, I recently purchased an el-cheapo weatherstation and I've been climbing the learning-curve hill since then. It was for my Dad for Christmas, and the object of the exercise was to enable him to add weather information to his Goldmining and homestay website. Google lead me to Sandaysoft and Cumulus, and I've been tinkering with it since Christmas day on and off, just getting the information I wanted in a way that I wanted it. I've done this the hard way... and that will teach me to not read the documentation :lol: but hey, its a good way to learn.

Essentially I wanted the weather info in the same format as the rest of the site, and while Steve has done a great job of formatting the information I can't just use plain HTML due to the way Drupal (the CMS system I develop in) formats pages. So I needed to pull the info apart and reformat it the way I needed it.

Ideally, the following code would be in a 'module' (clip on application for Drupal), and eventually it probably will be... time and energy permitting... but for now it is effectively some PHP code pulling apart and reformatting some of the information from the realtime.txt file. I'm posting it here for a few reasons, not least of which is that it will be a safe backup of what I have written in case I break and/or lose it in the future :D But also because I believe in open source and sharing knowledge... and this seems like a decent way to help a community that has helped me (with software, ideas and entertainment - reading the forum over the last few weeks).

Note: this code is pretty basic, and the display is not nearly completed... but its a proof of concept and is a springboard for the next level... Also note that I have incorporated a windchill calculation, but I'm not actually using it as yet...

So, here is the code for the page at (and this is a temporary development site - mine, actually) http://steve.dunford.org.nz/weather (and note: you need to have the core-optional PHP evaluation module enabled, and be using the PHP input type in Drupal):

Code: Select all

<?php
/**
 * Script to pull apart the realtime txt file and allow it to be
 * used to show various weather items in Drupal
 */
  $tempFile = "<path to the directory relative to the server root>/realtime.txt";
  $tempContents = fopen($tempFile,'r');
  $realtimeContents = fgets($tempContents,1000);
  $realtime = explode(" ",$realtimeContents);
  $weatherTime = explode(":",$realtime[1]);
  $weatherTime = $weatherTime[0].$weatherTime[1];
  $weatherDate = explode("/",$realtime[0]);
  $weatherMonth = array ("January","February","March","April","May","June","July","August","September","October","November","December");
  $weatherMonthNum = -1 + (int)$weatherDate[1];
 $windKPH = round((1.852 * (double)$realtime[6]),1); //Wind is in Knots, convert to numeral, then KPH, then trim to 1dp
 $tempC = (double)$realtime[2]; //convert temp from string to numeral.
 $windChill=(13.12 + 0.6215 * $tempC - 11.37 * pow($windKPH,0.16) + 0.3965 * $tempC * pow($windKPH,0.16)); //windchill calculation
 $windChill = round($windChill,1); //round to 1dp
 if ($windKPH < 5 || $windKPH > 100 || $tempC < -50 || $tempC > 5) $windChill = 0; //constraints for windchill measurement
?>
<h3>
<?php echo 'Latest update: '.$weatherTime.' hours on the '.((int)$weatherDate[0]);
  if      ($weatherDate[0] == "1" || $weatherDate[0] == "21" || $weatherDate == "31") echo 'st';
  else if ($weatherDate[0] == "2" || $weatherDate[0] == "22") echo 'nd';
  else if ($weatherDate[0] == "3" || $weatherDate[0] == "23") echo 'rd';
  else echo 'th';
  echo ' of '.$weatherMonth[$weatherMonthNum].", 20".$weatherDate[2]; ?>
</h3>
<h4>Naseby, New Zealand - 45°01'47"S  170°08'19"E, Elevation 1968 ft</h4>
<br><br>
<p>Naseby weather, updated every 15 minutes when the local workstation is running</p>
  
<table style="width: 100%; max-width: 700px;">
  <tr style="height: 15px;">
    <td valign="top">Temperature: <?php echo $realtime[2]; ?><sup>o</sup><?php echo $realtime[14]; ?><br>
    Humidity: <?php echo $realtime[3]; ?>%<br>
    Windchill: <?php echo $realtime[24]; ?><sup>o</sup><?php echo $realtime[14]; ?><br>
    Dew Point: <?php echo $realtime[4]; ?><sup>o</sup><?php echo $realtime[14]; ?><br>
    Barometric Pressure: <?php echo $realtime[10].$realtime[15]; ?>
    </td>
    <td width="90px"><img src="/sites/default/files/weather/images/windgauge.png" alt="Wind Speed" title="Wind Speed" class="mceItem" width="95px" height="95px"><br><center>Wind Speed</center></td><td width="90px"><img src="/sites/default/files/weather/images/compass.png" alt="Weather Direction" title="Weather Direction" class="mceItem" width="95px" height="95px"><br><center>Wind Dir.</center></td>
  </tr>
</table>
<p>Note: The weather station is a typical Chinese wireless model, available from many sources here in NZ and abroad - often referred to as the WS1083 and/or Fine Offset model.  The back end weather software is Cumulus by <a href="http://www.sandaysoft.com" target="_blank">Sandaysoft</a> with some custom PHP software written by <a href="http://www.essentialtech.co.nz" target="_blank">Essential Technology</a> to format the information to suit the site.</p> 
<p>&nbsp;</p><ul><li><span style="font-size: x-small;">The wind speed needle shows the current snapshot of the wind speed, as read from the  weather station. The green arc shows the current ten-minute average wind speed,  and the red arc shows the recent highest gust (in the last ten minutes).</span></li><li><span style="font-size: x-small;">The wind direction indicator shows the current snapshot of the wind speed, as  read from the weather station, with a red pointer; it also shows the average  wind direction over the last ten minutes, with a blue pointer (Note that when the wind speed is low, the wind direction can be quite erratic and unreliable)/</span></li></ul>
I hope this helps someone, and I hope its ok to be using the realtime.txt file in this way. I will update this as I get things sorted a bit.

As a side note, with Drupal, a node.tpl.php file could also have been used to do the PHP stuff... and I did this first... but its an ugly way to do it (actually, the current way is ugly too). The proper (and next) way I will do it is using a Drupal module.

regards

Steve
Last edited by kiwi_steve on Mon 04 Jan 2010 4:26 am, edited 1 time in total.
--There are no personal problems that cannot be overcome with the liberal application of high explosive--
User avatar
kiwi_steve
Posts: 10
Joined: Sun 27 Dec 2009 2:51 am
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
Location: Christchurch, New Zealand

Re: Interfacing Cumulus with a CMS-based website

Post by kiwi_steve »

Oh, just a note on running Cumulus. My dad has a Vista PC... and I don't much like Vista. And it caused me a headache when I tried to add Cumulus to the startup group so that it would load automatically with Windows and start uploading weather information. Vista's lovely UAC kept blocking it and throwing up a question asking if it was really allowed to start.

The way around this is to add it to the Scheduled Programs list (google it for more info). Because you need administrative rights to add a program to the schedule, it assumes anything in the schedule is ok to run, and it just happens. And one of the options for scheduling is "run at logon", so its effectively the same as putting it in the startup group.

Its possible someone else has documented that, but since it was an annoyance I had to deal with and learn from I thought I would put the info here with the rest of my post.

Cheers

Steve
--There are no personal problems that cannot be overcome with the liberal application of high explosive--
gemini06720
Posts: 1700
Joined: Mon 10 Aug 2009 10:16 pm
Weather Station: No weather station
Operating System: No operating system
Location: World...

Re: Interfacing Cumulus with a CMS-based website

Post by gemini06720 »

Steve, the PHP code you supplied is nice, but... ;)

A ready-to-use file containing all the tags produced by Cumulus is available from the Wiki pages: http://wiki.sandaysoft.com/index.php?title=Php_webtags

That file then needs to be processed by Cumulus to produce a PHP file containing all of Cumulus tags.

Then, it would have been just a matter of using an 'include/require' statement to load the file into the Web page and an 'echo' statement to display the value of the tags... ;)

I know, it was more fun starting from scratch and using the 'realtime.txt' file... :twisted:

With the 'realtime.txt', you only have 49 fields/values to play with - with the 'cumuluswebtags.php', you only have 182 fields/values to play with... :roll:
User avatar
kiwi_steve
Posts: 10
Joined: Sun 27 Dec 2009 2:51 am
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
Location: Christchurch, New Zealand

Re: Interfacing Cumulus with a CMS-based website

Post by kiwi_steve »

gemini06720 wrote:I know, it was more fun starting from scratch and using the 'realtime.txt' file... :twisted:
I'm just going to go with that :P

...like I said, if I'd read the instructions I could have saved a lot of time. I'm 6 months into a computer science degree and just learning what I can do with software, so "wheel reinvention" is not a bad thing for me :)

Steve
--There are no personal problems that cannot be overcome with the liberal application of high explosive--
gemini06720
Posts: 1700
Joined: Mon 10 Aug 2009 10:16 pm
Weather Station: No weather station
Operating System: No operating system
Location: World...

Re: Interfacing Cumulus with a CMS-based website

Post by gemini06720 »

kiwi_steve wrote:...like I said, if I'd read the instructions I could have saved a lot of time. I'm 6 months into a computer science degree and just learning what I can do with software, so "wheel reinvention" is not a bad thing for me :)
The best of luck with your classes/degree ... not that you need that much luck with PHP, it is such a great programming language... :)
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Interfacing Cumulus with a CMS-based website

Post by steve »

kiwi_steve wrote:Oh, just a note on running Cumulus. My dad has a Vista PC... and I don't much like Vista. And it caused me a headache when I tried to add Cumulus to the startup group so that it would load automatically with Windows and start uploading weather information. Vista's lovely UAC kept blocking it and throwing up a question asking if it was really allowed to start.

The way around this is to add it to the Scheduled Programs list (google it for more info). Because you need administrative rights to add a program to the schedule, it assumes anything in the schedule is ok to run, and it just happens. And one of the options for scheduling is "run at logon", so its effectively the same as putting it in the startup group.
Thanks for that, Steve, I wasn't aware of it. I'll add it to the FAQ about getting Cumulus to run at startup.

If it's possible for your Dad to upgrade to Windows 7, I would recommend it. It's really "Vista Fixed". It has a number of improvements over Vista that make it easier to work with. I have to say I like it and prefer it to XP.
Steve
gemini06720
Posts: 1700
Joined: Mon 10 Aug 2009 10:16 pm
Weather Station: No weather station
Operating System: No operating system
Location: World...

Re: Interfacing Cumulus with a CMS-based website

Post by gemini06720 »

steve wrote:If it's possible for your Dad to upgrade to Windows 7, I would recommend it. It's really "Vista Fixed". It has a number of improvements over Vista that make it easier to work with. I have to say I like it and prefer it to XP.
Indeed, I support Steve's claims 100% - Windows 7 is so much sturdier than Windows XP and probably a great improvement over Vista... :o
User avatar
Super-T
Posts: 890
Joined: Tue 09 Sep 2008 3:37 am
Weather Station: wh-1081
Operating System: Weather Laptop - Windows 10 Pro
Location: Auckland, New Zealand
Contact:

Re: Interfacing Cumulus with a CMS-based website

Post by Super-T »

KiwiSteve

You may need to look at your pressure setup in the desktop console as it appears to be way out at present. The console is situated quite high in Naseby and needs to allow for the height to give the relative pressure.

Looks like a nice place to move to on retirement.....low humidity compared to Auck :-)

Kiwi T
User avatar
kiwi_steve
Posts: 10
Joined: Sun 27 Dec 2009 2:51 am
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
Location: Christchurch, New Zealand

Re: Interfacing Cumulus with a CMS-based website

Post by kiwi_steve »

gemini06720 wrote:
steve wrote:If it's possible for your Dad to upgrade to Windows 7, I would recommend it. It's really "Vista Fixed". It has a number of improvements over Vista that make it easier to work with. I have to say I like it and prefer it to XP.
Indeed, I support Steve's claims 100% - Windows 7 is so much sturdier than Windows XP and probably a great improvement over Vista... :o
Yep, I've been running 7 since it came out in beta. At a tech launch by Microsoft here in NZ they let slip that many of the tech support team here had ditched XP, stepped over Vista and were running the RC of 7 in-house... that says something. Its solid (although I've managed to break it a couple of times... but hey, no M$ OS has ever been perfect, especially before the first SP is released... although I believe the RC was nearly release-ready and the release version could almost be considered SP1... They've almost nailed it this time... I'm using Ubuntu less and less since I got 7 installed. Dad, however, is quite happy with Vista so the several hundred dollar upgrade it just isn't worth it to him.
Super-T wrote:KiwiSteve

You may need to look at your pressure setup in the desktop console as it appears to be way out at present. The console is situated quite high in Naseby and needs to allow for the height to give the relative pressure.

Looks like a nice place to move to on retirement.....low humidity compared to Auck :-)

Kiwi T
It possibly is - I set it up from a pilot friends fancypants all-singing-and-dancing watch based on the altitude... but it will probably need tweaking. I think Dad is going to contact the local airstrip manager for a more accurate figure...

And yes, I've lived in Auckland, and Naseby... and I know which one I prefer :)

Steve
--There are no personal problems that cannot be overcome with the liberal application of high explosive--
User avatar
kiwi_steve
Posts: 10
Joined: Sun 27 Dec 2009 2:51 am
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
Location: Christchurch, New Zealand

Re: Interfacing Cumulus with a CMS-based website

Post by kiwi_steve »

gemini06720 wrote:
kiwi_steve wrote:...like I said, if I'd read the instructions I could have saved a lot of time. I'm 6 months into a computer science degree and just learning what I can do with software, so "wheel reinvention" is not a bad thing for me :)
The best of luck with your classes/degree ... not that you need that much luck with PHP, it is such a great programming language... :)
I've been learning in Java, but PHP seems very similar - and since nearly everything in Drupal involves PHP I've picked it up through osmosis of working with the CMS so much... And I do like it... some things are way easier to do in PHP than Java... rounding for example...

This coming year I'll be doing C, C++, C#, more Java, Visual Basic (as part of an intro to databases) - although MySQL would be more useful to me, and a bit of Python which I am really looking forward to 8-)

I've also got a background in electronics (air force trained), although I've done little with that over the last few years so I've forgotten most of it... but its been interesting reading the sunlight detector thread...

Steve
--There are no personal problems that cannot be overcome with the liberal application of high explosive--
Post Reply