ISO8601 Dates

I had tested my Web site using the latest versions of Firefox (version 9) and IE (version 9) and had no problems.  When I tried to use IE8 I discovered that it’s JavaScript engine doesn’t know how to parse ISO8601 dates.  Upon further research, I learned that a whole lot of browsers will have issues with the date format I chose.  So much for going with a standard.  So tonight I will add code to do the date parsing rather than relying on the browsers JavaScript engine to do it for me.  I’ll post an update later after I implement the fix for this bug.  Until then I apologize for the error message and the incorrect formatting people are seeing.  If you have IE9 or the latest Firefox then you should be OK.

Update: I added code to parse the ISO8601 date format.  Everything appears tp be working correctly, but I don’t have a lot of different browsers to test with.  My mobile browser (Android) works correctly now.  So this bug should be sufficiently squashed.

Confirmed working in:

  • IE9
  • IE8
  • Firefox 9
  • Safari (on iPod)
  • Android browser

Updating Forecast

The revised site has been running for several days now.  Not having as many problems as I expected.  That’s a good thing.  So I decided to add a new feature.  I tend to leave the Web page open for hours at a time and look at the station data periodically, as it updates automatically.  The problem is that the forecast from he NWS is static.  To get ti to update requires clicking on the button to refresh that page.  So I added code to have it update automatically.  My NWS forecast PHP class now can serialize itself to JSON.  I created a new page that returns that JSON data to the browser.  And I added client side Knockout data binding for those fields.  So far so good.

While I was testing the data binding, I learned that I had a bug in my Knockout code.  If I had used proper JavaScript exception handling I would have noticed it earlier.  I was retrieving the data from the server on a schedule, with some data refreshing more frequently than other data.  What I didn’t realize was that Knockout was throwing exceptions when I mapped the data model up until I retrieved all of the fields at least once.  So now I “prime the pump” and retrieve everything once up front.  I had to add that code to all of my Web pages that use Knockout.  Then I added a bit more exception handling code.  I’m not happy with it, but at least I have something there.  I also found a bug in one field that caused it to show as zero most of the time.  So I fixed that one as well.

I also made the mistake of running my pages past a Web page optimization site.  Of course I got called out for having so much JavaScript code.  So I added minify to my Web site.  Minify is PHP code to combine and compress multiple JavaScript files on demand.  That helped my load times out a bit, and the optimizer had one less thing to complain about.  There’s still some more I can do to make the pages load a little bit faster.  So I may still do some more work in that area.

New Site is Live

Just a very quick update.  I just unleashed my latest version of the Web site on the world.  It probably doesn’t look very different, but the code behind the scenes has been heavily revised.  It uses a domain object model implemented in PHP, JSON for AJAX for data transfer, and jQuery and Knockout for the AJAX code.  I will be cleaning up any legacy files left behind on the Web site over the next few days.  Now I just need to keep an eye on everything and make sure it’s updating like I expect it to.  That and make any tweaks I decide I want to make.

Update: I needed to make some minor formatting tweaks.  But otherwise everything is working as expected.

Knockout Update

I’ve spent a lot more time working with jQuery and Knockout.  They both work very well.  I’ve modified almost all of my pages to use them (in my test environment).  I also added a few new features to my mobile Web page. I hope to have all of this ready to be released by the end of this weekend.

While making the changes I learned a few things worth sharing.

1. I have a mobile page at http://www.cloppermillweather.org/mobile.php.  The Knockout code was failing and at first I had a hard time working out why.  Eventually I narrowed it down to displaying dates.  I was able to display dates fine in IE and Firefox, but on the Android browser it failed.  It turns out that the Android browser JavaScript engine doesn’t parse ISO 8601 dates.  I wrote a very basic parser and it now works fine.

2. Splitting up my data into separate models with different update schedules helped to speed up Ajax updates.  This wasn’t unexpected as I’m now transferring the bulk of the data from the server to the browser less often.

3. Trying to parse a full day’s history is too much to try and do on the client within the browser.  I quickly changed that plan to only transfer the history I actually display on the statistics page.  If I choose to add more history fields to that page I’ll need to update my page that transfers the JSON data.  This doesn’t affect my history Web page, as that page is formatted on the server and isn’t updated dynamically.

It’s a Knockout

I’ve spent some more time working with the JavaScript side of the Web recently.  I updated my PHP classes to serialize themselves to JSON.  Then I added Web pages to return that data.  This allows me to easily transfer that data to the client browser and convert ti to JavaScript.  That seems to be working really well.  That also gave me an opportunity to try out jQuery for retrieving the data using Ajax.  jQuery is really overkill for what I use it for, as I only use it to make the Ajax calls, and it can do so much more.  I found an add-in for jQuery that adds timer functionality.  I had started working on creating a timer with multiple observers that could be triggered at different intervals.  But this jQuery plug-in already does what I planned to build.  So I’m giving it a go as well.

So now that I can get the data transferred in a format that’s easy to work with, and can transfer to according to a schedule based on the different types of data, I needed to display it.  That’s where Knockout comes into the picture.  Knockout allows me to define fields in an HTML document and bind them to the data that I retrieve using jQuery.  As part of the data binding process I can define formatting for the data when it’s displayed.  So now I have a clearly defined separation of the data and the rules for formatting the data.  Although both jQuery and Knockout have way more functionality than I need or plan to use, I think I’m going to like working with them.  I just need to make sure I don’t get carried away trying to find ways to use the other features.  That is the danger of using products like these.  I end up looking for a problem to fit the solution I already have.

I’ve done a fair bit of prototyping using these products in my development environment.  First it took me a while to get used to the way Knockout  and jQuery work.  Once I got the basics working, I started looking at scheduling the Ajax calls from the client to the server.  Finally, I experimented with ways to format the data for display on the Web pages.  I feel like I have all of those items working, as well as a plan on how best to integrate this into my existing Web pages.  I still have a lot of work to complete, as well as testing.  The sad part is that the Web pages will probably look exactly the same after I finish the conversion.  But I learned some new techniques, the design is better from a purist point of view, and the site will hopefully be easier to maintain..

Happy New Year

First off, I want to wish everybody a Happy New Year.  Hope your holidays were good.

I haven’t posted for a while and I thought it was time for an update.  I’ve refactored all of my PHP code into classes so that it will be more object oriented.  I created a test page to test every method of every class and got that working.  Then I modified all of the pages to use the new classes, and to ensure that everything is properly separated, with the data in the PHP code and all formatting controlled by the Web pages.  That is now completed and working n my test environment.

All my Ajax code is currently developed by me, but I’ve been looking at some open source libraries, mainly Knockout and jQuery.  Knockout is for data binding so that I can define fields on the Web pages and bind them to JavaScript classes that hold the data.  I already have a framework in place that does this, but I’m looking into whether it is worth the effort to move to this open source Knockout framework.  The same goes for jQuery.  I could use it to send Ajax requests to the server in place of the code I already use.  If I do decide to switch, now would be the best time as I plan to revise my JavaScript object model to match my PHP and Java code.

Another issue I need to tackle is how to transfer the data from the PHP server code to the JavaScript client code.  Currently I send an XML document with all the fields required by the user interface.  I plan to divide this up into separate classes the same as my weather station software, as the classes are updated at different intervals.  This would save on server round trips to pass data that I know hasn’t changed.  I may also choose to use JSON to encode the data rather than XML.  This will make things much easier on the client side.

I’ll continue working and post another update soon.

It’s Raining, It’s Pouring

It rained last night and this morning, which gave me an opportunity to check my rain gauge readings and ensure my gauge is working better.  I didn’t get the crazy (and impossible) readings I had before, with things like several hundred inches of rain.  This time I measured .72 inches last night and .09 inches this morning.  Looking on Weather Underground at neighboring stations this looks pretty reasonable.  So hopefully the gauge is working as expected.

I’ve been restructuring my PHP server code to be more object oriented.  It now matches my old Java code pretty closely.  I don’t really know when (or even if) I will deliver this new code to production.  I’ll probably also update my JavaScript code to match as well.  Then I can use the same internal data representation for each implementation (Java, PHP, and JavaScript).  That should help make maintenance a little easier.  It will also allow me to remove any translations I was doing between the different implementations, even if they weren’t difficult.

Rain Gauge Retry

I spent some time looking at my rain gauge today.  I took it apart and sealed every place I could find with clear silicone and liquid electrical tape.  I poured water through the gauge and watched for any leaks.  To be honest I couldn’t really find any problems other than the fact that a spider had made the inside of the gauge its’ new home.  After sealing and testing (and shooing away the spider) I buttoned everything back up.  I re-enabled the gauge in my software configuration and watched the readings.  So far no errors, but it hasn’t rained yet.  Rain is in the forecast for later this week so I’ll wait until then and see how the gauge does.  Hopefully all will be well.

I also learned that I need to add some more error checking to my ftp scripts that copy the weather data to my ISP.  I found quite a few of them had hung and were still running.  I ran a quick command to find and kill all of them at once.  I may schedule that command to run periodically using cron, but I see that as a band-aid type of fix.  I really need to fix the ftp scripts instead.  Oh well, I didn’t want to run out of things to do, did I?

New Template

I decided it was time for a fresh look for the weather Web site.  I had been experimenting with a new CSS template I had gotten from a CSS Templates Web site.  The template looked pretty clean, but I wasn’t certain I wanted to use it since it was intended for a blog site.  But after working with it for a while the look and feel started to grow on me.  So I built a new site on my development sever and worked out the kinks.

Yesterday I promoted the new site to cloppermillweather.org.  All the pages except one validate as XHTML 1.0 strict.  The remaining page that fails validation embeds some HTML I get from a news feed that isn’t compliant.  I haven’t decided whether to back off from strict to transitional for that page, edit the HTML using PHP to make it conform, or remove that data entirely.  I’ll probably make my decision and implement the fix later today.

While I was at it, I made a few minor tweaks to the AJAX code to make the UI a little nicer and to make maintenance easier.  One nice UI feature I added is to update the Webcam thumbnail image.  I still have plans to completely restructure the site folder structure and modify the PHP code to make it more object oriented.  I’ve started on it, but it will be a lot of work and will take some time still.  That and I still need to fix the rain gauge.  Still more to come.

Testing 1…2…3

I’ve been toying withe the idea of using a new template for my Web site.  I’ve done some work and created several new pages, but they’re on my production Web site intermingled with my current pages.  I really needed to set up a test environment for my Web site that will allow me to test changes before I deploy them to cloppermillweather.org. This means setting up a Linux server with Apache, PHP, SSH, and SFTP.  Luckily I had a spare computer around that would fit the bill just fine.  I installed Centos Linux on it, enabled the services I needed, and added the necessary software.  I’m also planning to add database software, either Postgres or MySQL, so I can test saving my weather data in a database and generating reports and graphs from that database.

I got everything set up and working, and installed my Web site on the server.  I did have to track down one bug in my PHP code which didn’t show up in production but did cause a problem on my test server.  Just needed to add a simple typecast to float in one of my functions and all was well.  So now I have a test site to work with along with a new version of Linux I haven’t used before.

My rain gauge is still disabled due to the problematic readings I was getting from it.  I’m not entirely sure when I will get around to looking at it, as the weather is getting pretty cold and wet, I need to spend some time with my family, and this is the busiest time of year at my job.  So it may take a while before I get back to it.