Sandaysoft

Support forum for Cumulus weather station software
It is currently Mon May 20, 2013 4:05 pm
Please click here before posting. Help me to help you!
Useful Links: Cumulus FAQ • Enhancement requests • Wiki (documentation)
Please put your approximate location into your profile
Add your web site to the Cumulus user map
Vantage Pro2 users with firmware 3.00 should upgrade to fw 3.12 and Cumulus 1.9.4

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 4:14 am 
Offline
User avatar

Joined: Sun Dec 27, 2009 2:51 am
Posts: 10
Location: Christchurch, New Zealand
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
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:
<?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

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


Last edited by kiwi_steve on Mon Jan 04, 2010 4:26 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 4:22 am 
Offline
User avatar

Joined: Sun Dec 27, 2009 2:51 am
Posts: 10
Location: Christchurch, New Zealand
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
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--


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 5:56 am 
Offline

Joined: Mon Aug 10, 2009 10:16 pm
Posts: 1797
Location: World...
Weather Station: No weather station
Operating System: No operating system
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:


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 6:00 am 
Offline
User avatar

Joined: Sun Dec 27, 2009 2:51 am
Posts: 10
Location: Christchurch, New Zealand
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
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--


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 6:30 am 
Offline

Joined: Mon Aug 10, 2009 10:16 pm
Posts: 1797
Location: World...
Weather Station: No weather station
Operating System: No operating system
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... :)


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 9:17 am 
Offline
Site Admin
User avatar

Joined: Mon Jun 02, 2008 6:49 pm
Posts: 17558
Location: Sanday, Orkney
Weather Station: Davis VP2
Operating System: Windows Home Server 2011
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
Sanday Weather
----------------------------------------------------------------------------------------------------------------------------------
Like Cumulus and want to support it? Please donate! Image


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 10:16 am 
Offline

Joined: Mon Aug 10, 2009 10:16 pm
Posts: 1797
Location: World...
Weather Station: No weather station
Operating System: No operating system
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


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Mon Jan 04, 2010 10:20 pm 
Offline
User avatar

Joined: Tue Sep 09, 2008 3:37 am
Posts: 696
Location: Auckland, New Zealand
Weather Station: wh-1081
Operating System: Weather Laptop - Windows 7 Pro
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

_________________
Terry Wiltshire
http://www.janter.co.nz/weather/index.htm
Image


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Tue Jan 05, 2010 7:15 am 
Offline
User avatar

Joined: Sun Dec 27, 2009 2:51 am
Posts: 10
Location: Christchurch, New Zealand
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
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--


Top
 Profile  
 
 Post subject: Re: Interfacing Cumulus with a CMS-based website
PostPosted: Tue Jan 05, 2010 7:22 am 
Offline
User avatar

Joined: Sun Dec 27, 2009 2:51 am
Posts: 10
Location: Christchurch, New Zealand
Weather Station: Chinese budget special USB thing
Operating System: Windows Vista SP1
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--


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group