<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Spice World! &#187; PHP</title>
	<atom:link href="http://www.cyberspice.org.uk/blog/category/geek/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cyberspice.org.uk/blog</link>
	<description>The life and times of a jet setting software engineer!</description>
	<lastBuildDate>Fri, 23 Jul 2010 10:25:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DPC 2010</title>
		<link>http://www.cyberspice.org.uk/blog/2010/07/15/dpc-2010/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/07/15/dpc-2010/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 21:17:08 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dpc10]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=451</guid>
		<description><![CDATA[A couple of weeks ago I went to the Dutch PHP Conference 2010 and I had an amazing time.  The event was held in Amsterdam at the RAI centre.  The primary sponsor was iBuildings and the entire event was organised by the totally awesome Lornajane.
When DPC 2010 announced the call for papers I [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I went to the Dutch PHP Conference 2010 and I had an amazing time.  The event was held in Amsterdam at the RAI centre.  The primary sponsor was <a href="http://www.ibuildings.nl/">iBuildings</a> and the entire event was organised by the totally awesome <a href="http://www.lornajane.net/">Lornajane</a>.</p>
<p>When DPC 2010 announced the call for papers I submitted both a proposal for a tutorial on PHP extensions and one for a talk on web services.  Both were excepted.  I had proposed both half day and full day versions of the tutorial the organisers chose the full day version.  This turned out to be a lot of work.  Basically I would be talking for 6 hours in four 90 minute slots.<br />
<span id="more-451"></span><br />
The web services talk was to be trailed at the PHP NW group in May.  Unfortunately being stuck in the US due to the Icelandic Volcano and its dust cloud didn&#8217;t give me much time to prepare for it.  However by the time of the group meeting I had a basic talk.  This meant I could devote the rest of the time up to DPC preparing the tutorial.</p>
<p>Since it is still early in my speaking career I don&#8217;t yet have the experience to accurately judge how long a talk will take.  I had never done a tutorial before so I had no experience to base it on.  In the end I came up with a plan where I had some &#8216;optional&#8217; sections which I could add on the end if I ran short.  It was scary to see how much content I required and took me several weeks to prepare in odd evenings.  In the end it came in at over 100 slides together with four example extensions.</p>
<p>I flew to Amsterdam courtesy of KLM&#8217;s direct flight from Leeds Bradford Airport to Schipol.  Since the hotel was right by Amsterdam Centraal train station it was a simple train ride from the airport and a short walk.  After meeting other attendees and speakers in the hotel foyer I headed up to my room to finish preparation for the Friday.  It turned out that I wasn&#8217;t by the station, my room was in a building <strong>over</strong> the station.  It straddled two platforms and a set of tracks.</p>
<p>The following morning I got up early and Lornajane helped me, and others, get to the conference venue.  I was extremely nervous.  This wasn&#8217;t helped by finding out that many of iBuilding&#8217;s own staff would be in my Extensions tutorial.  In the end the day went very quickly.  As usual when I&#8217;m nervous I spoke to quickly.  Luckily I could answer all questions and also had a chance to talk about some side projects.  I finished early so I turned the last session in to a workshop to any who wanted to try their hand at writing an extension.  I was very pleased at how well it had been received.</p>
<p>That evening a whole bunch of us were going to an Indonesian fusion restaurant.  Unfortunately due to our guide getting a little lost and my impractical shoes I arrived tired with sore feet.  The food was great but I wanted to get back to the hotel and sleep.  As I was still nervous about the talk the following day I didn&#8217;t sleep well.  I also had the dilemma of either being too warm or it being too noisy with the trains.</p>
<p>The following morning I woke very tired.  I met with some friends and fellow conference people at breakfast and we all headed off for the first of the two days of conference talks.  It was an awesome Friday keynote from <a href="http://www.two-sdg.demon.co.uk/curbralan/kevlin.html">Kevlin Henney</a>.  I had seen him speak before an PHP NW 2009 and he did not disappoint.  Following talks were equally impressive.  My slot was on after afternoon tea which is always hard work and by then I was tired out.  It was not a great talk.  Although fine for the PHP NW group meeting it was a little basic for an international conference.  I will know for next time.</p>
<p>That evening was the Speakers dinner which was thoroughly enjoyable.  I got to talk to Kevlin and others and since by then I had given all my content I could have a bit of a drink and not worry about having to make it the following morning although since the Saturday keynote was being given by <a href="http://shiflett.org/">Chris Shiflett</a> who I had also seen before and thoroughly enjoyed I was too late to bed so that I could be there on time to see him. </p>
<p>Sunday provided another day of great speakers and talks.  Thoroughly enjoyable.  Then the conference wound down.  Those of us who were staying the Saturday night headed off for pancakes.  Marcus and I got completely lost in Amsterdam due to confusing instructions from Ivo (it was the <em>wrong</em> social he was talking about) and eventually turned up about an hour later than everyone else.  However the pancakes were well worth it.  It was followed by some more drinking and then bed.</p>
<p>Since Lornajane and I live in the same city we were on the same KLM flight back from Amsterdam so we became travel partners.  Sunday was spent mostly hanging out in Amsterdam followed by an unstressed journey to the airport, a couple of beers waiting for our flight, and an uneventful flight home.</p>
<p>DPC 2010 was really good fun.  I learnt a lot, both from the talks and giving the tutorial and the talk.  I met many good friends and made lots of new ones.  Too many to have a check list here.  I&#8217;m now looking forward to my &#8216;home&#8217; conference, PHP NW 2010 in October.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/07/15/dpc-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DPC2010 &#8211; &#8220;PHP Extensions Tutorial&#8221; and &#8220;Web Services For Consumer Devices&#8221;</title>
		<link>http://www.cyberspice.org.uk/blog/2010/06/12/dpc2010-php-extensions-tutorial-and-web-services-for-consumer-devices/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/06/12/dpc2010-php-extensions-tutorial-and-web-services-for-consumer-devices/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 10:20:42 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Talks]]></category>
		<category><![CDATA[dpc10]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=447</guid>
		<description><![CDATA[I am still at the Dutch PHP Conference and very enjoyable it is too.  I have now given my two talks.  The first was an all day session on writing PHP extensions in C.  The second was a regular 45 minute session on Web Services For Consumer Devices.
PHP Extensions
This tutorial covered writing [...]]]></description>
			<content:encoded><![CDATA[<p>I am still at the Dutch PHP Conference and very enjoyable it is too.  I have now given my two talks.  The first was an all day session on writing PHP extensions in C.  The second was a regular 45 minute session on Web Services For Consumer Devices.</p>
<h2>PHP Extensions</h2>
<p>This tutorial covered writing PHP extensions from the very beginning right through to writing objects and classes in C.  I think this went well.  Its a lot for beginners to cover so naturally some people got lost towards the end but I have had some good feedback.  Links to the slides and examples are below.</p>
<div style="margin-left: auto;margin-right: auto">
<table>
<tr>
<td><strong>Slides</strong></td>
<td><a href="http://www.cyberspice.org.uk/downloads/PHPExtensions-Final-20100612.pdf">PHPExtensions-Final-20100612.pdf</a></td>
</tr>
<tr>
<td><strong>Example &#8211; Hello World</strong></td>
<td><a href="http://www.cyberspice.org.uk/downloads/ExtensionTutorial/hello_world-20100612.tgz">hello_world-20100612.tgz</a></td>
</tr>
<tr>
<td><strong>Example &#8211; Hello World (Extended)</strong></td>
<td><a href="http://www.cyberspice.org.uk/downloads/ExtensionTutorial/hello_world-20100612.tgz">hello_world_extended-20100612.tgz</a></td>
</tr>
<tr>
<td><strong>Example &#8211; Memory Stream</strong></td>
<td><a href="http://www.cyberspice.org.uk/downloads/ExtensionTutorial/hello_world-20100612.tgz">memory_stream-20100612.tgz</a></td>
</tr>
<tr>
<td><strong>Framegrab (PECL)</strong></td>
<td><a href="http://pecl.php.net/package/framegrab">http://pecl.php.net/package/framegrab</a></td>
</tr>
</table>
</div>
<h2>Web Services For Consumer Devices</h2>
<p>This talk covered what to consider when writing a service to be used by an application on a consumer devices.  I agree with the commenters who felt it was a little light.  Yes it needs revision before it gets reused.</p>
<p><a href="http://www.cyberspice.org.uk/downloads/ WebServicesForConsumerDevices-20100612.pdf">WebServicesForConsumerDevices-20100612.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/06/12/dpc2010-php-extensions-tutorial-and-web-services-for-consumer-devices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DPC &#8211; Dutch PHP Conference 2010</title>
		<link>http://www.cyberspice.org.uk/blog/2010/04/22/dpc-dutch-php-conference-2010/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/04/22/dpc-dutch-php-conference-2010/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 23:45:12 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Talks]]></category>
		<category><![CDATA[Women In Technology]]></category>
		<category><![CDATA[Amsterdam]]></category>
		<category><![CDATA[DPC]]></category>
		<category><![CDATA[LinkedIn]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=436</guid>
		<description><![CDATA[Rather belatedly I am delighted to announce that I have been accepted to speak at the Dutch PHP Conference in Amsterdam this June.  DPC is the premier European PHP conference and is sponsored by iBuildings.
I will be running a tutorial Writing a PHP extension in C and speaking about Web Sevices for Consumer Devices. [...]]]></description>
			<content:encoded><![CDATA[<p>Rather belatedly I am delighted to announce that I have been accepted to speak at the Dutch PHP Conference in Amsterdam this June.  <a href="http://phpconference.nl/">DPC</a> is the premier European PHP conference and is sponsored by <a href="http://www.ibuildings.com/">iBuildings</a>.</p>
<p>I will be running a tutorial <a href="http://joind.in/talk/view/1523">Writing a PHP extension in C</a> and speaking about <a href="http://joind.in/talk/view/1546">Web Sevices for Consumer Devices</a>.  I look forward to seeing you there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/04/22/dpc-dutch-php-conference-2010/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Capturing still images from video devices in PHP using Framegrab</title>
		<link>http://www.cyberspice.org.uk/blog/2010/02/28/capturing-still-images-from-video-devices-in-php-using-framegrab/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/02/28/capturing-still-images-from-video-devices-in-php-using-framegrab/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 16:10:34 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Framegrab]]></category>
		<category><![CDATA[PECL]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=433</guid>
		<description><![CDATA[I found I had a need to capture and process still video images from video devices using PHP so I wrote the Framegrab PECL extension.  This post introduces the basics of Framegrab.

The framegrab extension is currently only available for Linux although Windows and OS X support will be coming soon.  On Linux the [...]]]></description>
			<content:encoded><![CDATA[<p>I found I had a need to capture and process still video images from video devices using PHP so I wrote the Framegrab PECL extension.  This post introduces the basics of Framegrab.<br />
<span id="more-433"></span><br />
The framegrab extension is currently only available for Linux although Windows and OS X support will be coming soon.  On Linux the extension uses the Video For Linux API version 2.</p>
<p>Framegrab adds two classes to PHP.  <em>FrameGrabDevice</em> represents a video capture device and <em>FrameGrabImage</em> an image captured with a FrameGrabDevice.     </p>
<p>You can create a new <em>FrameGrabDevice</em> for the default video capture device as follows:</p>
<pre>
	$device = new FrameGrabDevice();
</pre>
<p>The extension will iterate through available video devices until it finds one that supports video capture.  A <em>FrameGrabDeviceException</em> will be thrown either if no video devices are available or if the available video devices do not support video capture.</p>
<p>You can supply an argument to the constructor (see below) if you want to initialise a specific video device.  In this case the <em>FrameGrabDeviceException</em> will be thrown if that specific device does not exist or does not support video capture.</p>
<pre>
	$device = new FrameGrabDevice('/dev/video1');
</pre>
<p>Once you have a device you can then grab an image using the <em>grab()</em> method.  The method takes no arguments and returns a <em>FrameGrabImage</em> object or false on error.  As the <em>FrameGrabImage</em> constructor is a protected method you cannot create objects directly using new.</p>
<p>Once you have the image you can either save the image to the file in PNG format or have it returned as a string in PNG format using the writeAsPNG() and toStringAsPNG() methods respectively.  The former takes a filename as the sole argument and returns false on error.  The latter takes no arguments and returns either the PNG data as a string or false on error.</p>
<p>The two objects also support a number of properties.  The code below demonstrates the extension in use.  It returns an image captured from the default video device as a PNG.  The image has capture device and image meta data embedded in it visible in the top left corner of the image.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
try <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get the default frame grabber device.  Throws an exception if a device</span>
	<span style="color: #666666; font-style: italic;">// cannot be found.</span>
	<span style="color: #000088;">$device</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FrameGrabDevice<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Grab am image.</span>
	<span style="color: #000088;">$fgimage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$device</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">grab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fgimage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Create a GD image from a frame grab image</span>
		<span style="color: #000088;">$gdimage</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromstring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toStringAsPNG</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Output data about the image on to the image</span>
		<span style="color: #000088;">$font</span>  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$black</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$fh</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">imagefontheight</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$x</span>     <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span>     <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Device: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$device</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">device</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Card: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$device</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">card</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Width: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Height: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Format: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Bytes per line: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bytes_per_line</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Output the image</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Handle the FrameGrabDevice exception here.</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The extension is available <a href="http://pecl.php.net/package/framegrab">at the PECL site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/02/28/capturing-still-images-from-video-devices-in-php-using-framegrab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Serial IO in PHP using the DIO extension</title>
		<link>http://www.cyberspice.org.uk/blog/2010/02/15/serial-io-in-php-using-the-dio-extension/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/02/15/serial-io-in-php-using-the-dio-extension/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 16:36:03 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DIO]]></category>
		<category><![CDATA[PECL]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=429</guid>
		<description><![CDATA[DIO is the Direct IO extension for PHP.  I recently took over maintaining this extension and have implemented comprehensive stream support for both POSIX and Windows systems.  To demonstrate the use of DIO this post will describe a PHP script that sends an SMS using a USB 3G modem.

To make control of modems [...]]]></description>
			<content:encoded><![CDATA[<p>DIO is the Direct IO extension for PHP.  I recently took over maintaining this extension and have implemented comprehensive stream support for both POSIX and Windows systems.  To demonstrate the use of DIO this post will describe a PHP script that sends an SMS using a USB 3G modem.<br />
<span id="more-429"></span></p>
<p>To make control of modems easier over twenty years ago the Hayes Corporation developed a serial command protocol, the Hayes or AT command set.  Many other modems adopted the protocol and now its a de-facto standard.  Over the years as modem functionality expanded so did the command set.  Now it supports FAX, cell phone address books, SMSes and so on.  The AT command set comprises a set of text based commands terminated with CRLF.  The responses are similarly text strings terminated with CRLF.  Typically the modem responds with &#8220;OK&#8221;, &#8220;ERROR&#8221; or a setting value.</p>
<p>DIO currently provides two stream types <em>raw</em> and <em>serial</em>.  Raw streams provide low level access to operating system devices.  Serial streams provide access to, and abstract, serial ports.  DIO stream support is accessed just like any other PHP streams.  The appropriate URI is <a href="http://uk2.php.net/manual/en/function.fopen.php">fopen</a>ed.  The relevant URIs are:</p>
<pre>
dio.raw://[device]
</pre>
<p>for raw streams and</p>
<pre>
dio.serial://[device]
</pre>
<p>for serials streams.  In both cases [device] is the device name to open.  For example this could be /dev/random for the random device on Linux; or /dev/ttyS0 for a comms port on Linux; or COM1 for a comms port on Windows.  We&#8217;ll be using the later form of the URI as we&#8217;re opening a serial port.  </p>
<p>The example code opens the serial port as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dio.serial:///dev/tty.ZTEUSBATPort_&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r+&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first argument is the device to open.  In this case a serial port to the USB 3G modem connected to my MacBook.  The second is the open mode, in this case read/write.  The third is an optional argument that comprises a flag that indicates whether to search the include path for the file to open.  We don&#8217;t want this.  The final optional argument is a stream context which is a collection of stream specific additional parameters.</p>
<p>A stream context is created using <a href="http://uk2.php.net/manual/en/function.stream-context-create.php">stream_context_create</a>().  The code in the example that creates the context, prior to opening the port, is shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dio'</span> <span style="color: #339933;">=&gt;</span> 
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data_rate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9600</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'data_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'stop_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'parity'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'flow_control'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'is_blocking'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'canonical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first four context options are pretty obvious.  The serial port is being configured for 9600 bits per second, 8 bits per byte with 1 additional stop bit per byte and no parity checking.</p>
<p>The next option disables hardware flow control.  Serial ports are relatively slow so they often have hardware control lines which indicate when there is data ready to be sent and space in the buffer ready to receive data.  My USB modem does not have these so the hardware flow control is disabled.</p>
<p>Next we turn off blocking.  With blocking function calls the operating system waits for data and only returns when it is ready to return the data that was requested i.e. the operating system blocks on the data.  Non-blocking function calls return whether there is data or not.  The POSIX open call also blocks on the state of the Data Carrier Detect (&#8220;DCD&#8221;) hardware control line.  Some modems have this control line and use it to indicate there&#8217;s a carrier signal on the telephone line.  Again since the USB modem does not have this we disable it.</p>
<p>Finally we enable canonical mode.  Canonical IO on POSIX means that the serial port driver will wait for a line of text ending in a newline (or the internal buffer being full) before returning.  If less characters than were entered on the line were requested the driver buffers the data for subsequent reads until the entire line is returned.  In canonical mode you can actually connect a terminal to the serial port as line editing is supported.  Since Windows does not have a canonical mode DIO provides an implementation on top of the Windows driver.  The alternative to canonical mode is byte mode where by DIO waits until the requested number of bytes have been read and returns regardless of whether there are more bytes available.</p>
<p>If all that sounds a little complicated think of it like this.  If you&#8217;re reading strings terminated with a new line use canonical mode otherwise use byte mode.</p>
<p>Remember that blocking was disabled so that opening the serial device did not block.  This isn&#8217;t desirable when actually reading data.  Blocking mode can be re-enabled on an open stream using <a href="http://uk2.php.net/manual/en/function.stream-set-blocking.php">stream_set_blocking</a> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">stream_set_blocking</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Once the serial port has been opened with the appropriate port settings and blocking re-enabled the port can be written and read using the standard <a href="http://uk2.php.net/manual/en/function.fprintf.php">fprintf</a> and <a href="http://uk2.php.net/manual/en/function.fgets.php">fgets</a> PHP functions.</p>
<p>There are two AT commands related to sending an SMS.  The first is &#8220;AT+CMGF=1&#8243; which tells the modem to operate in SMS text mode.  This should respond with &#8220;OK&#8221;.  The second is &#8220;AT+CMGS=&#8221; which is followed by a string comprising a telephone number.  This accepts the text of an SMS which is sent when CTRL-Z is entered.  </p>
<p>There&#8217;s a little bit of additional work in the example as the modem echos data sent to it back to the sender so the PHP code consumes data after a command is sent until it sees the sent command echoed back.  The full example follows.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PHONE_NUMBER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'5551234'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SMS_TEXT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Hello world!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Sends data to the modem
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt; <span style="color: #006699; font-weight: bold;">$string</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$string</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Reads lines from the serial port.  It reads until a non blank line is
 * received then returns it.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// remove carriage returns, line feeds and excess white space</span>
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Waits for OK to be sent back by the modem.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> wait_for_ok<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> get_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&gt; <span style="color: #006699; font-weight: bold;">$response</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;OK&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// MAIN CODE</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the context</span>
<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dio'</span> <span style="color: #339933;">=&gt;</span> 
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data_rate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9600</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'data_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'stop_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'parity'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'flow_control'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'is_blocking'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'canonical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Open the port</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dio.serial:///dev/tty.ZTEUSBATPort_&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r+&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Re-enable blocking</span>
	<span style="color: #990000;">stream_set_blocking</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Set SMS text entry mode</span>
	send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;AT+CMGF=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	wait_for_ok<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Send an SMS</span>
	send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;AT+CMGS=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> PHONE_NUMBER <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> SMS_TEXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Send CTRL-Z to end SMS text entry</span>
	<span style="color: #990000;">fprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">26</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	wait_for_ok<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Close the port</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/02/15/serial-io-in-php-using-the-dio-extension/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP DIO Extension: Looking for beta testers</title>
		<link>http://www.cyberspice.org.uk/blog/2010/02/02/php-dio-extension-looking-for-beta-testers/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/02/02/php-dio-extension-looking-for-beta-testers/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 19:58:20 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[DIO]]></category>
		<category><![CDATA[PECL]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=424</guid>
		<description><![CDATA[A few months ago I had a need to do some serial IO from PHP.  After asking around I found out there was a PHP extension for this but it was unmaintained, unowned and out of date.  To cut a long story short I ended up as the maintainer of said extension and [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I had a need to do some serial IO from PHP.  After asking around I found out there was a PHP extension for this but it was unmaintained, unowned and out of date.  To cut a long story short I ended up as the maintainer of said extension and since them I have been fixing and extending it.</p>
<p>The original DIO API is very basic and POSIX oriented.  Serial support is not very configurable and doesn&#8217;t work at all on Window platforms.  So I have been working on implementing PHP stream extensions that allow you to do raw and serial IO via streams.  Anyway its ready for testing by people other than me on POSIX (Linux, OS X etc) and Windows platforms so I&#8217;m looking for beta testers.</p>
<p><span id="more-424"></span></p>
<h2>Where to get it</h2>
<p>The release candidate is downloadable as a package from:</p>
<p><a href="http://www.cyberspice.org.uk/downloads/dio-0.0.4rc3.tgz">http://www.cyberspice.org.uk/downloads/dio-0.0.4rc3.tgz</a></p>
<p>And directly from SVN at:</p>
<p><a href="http://svn.php.net/repository/pecl/dio/tags/RELEASE_0_0_4RC3">http://svn.php.net/repository/pecl/dio/tags/RELEASE_0_0_4RC3</a></p>
<h2>Documentation</h2>
<p>While I write proper PHP documentation below is a brief over view of how you use DIO.</p>
<h3>Streams</h3>
<p>DIO streams are just PHP streams.  You use <a href="http://www.php.net/manual/en/function.fopen.php">fopen()</a> to open them and <a href="http://www.php.net/manual/en/function.fread.php">fread()</a>, <a href="http://www.php.net/manual/en/function.fwrite.php">fwrite()</a>, <a href="http://www.php.net/manual/en/function.fgets.php">fgets()</a>, <a href="http://www.php.net/manual/en/function.stream-set-blocking.php">stream_set_blocking()</a> etc. There are two DIO streams, dio.raw and dio.serial.  </p>
<p>dio.raw is as it sounds, raw streams.  It uses the low level OS streams such as open(), read(), write(), close() etc. on POSIX and CreateFile(), OpenFile(), ReadFile(), WriteFile(), CloseFile() on Windows.  It does not buffer except the internal PHP buffering.</p>
<p>dio.serial is full serial support.  It allows setting of data rates, data size, stop bits, handshaking and raw/canonical modes etc.</p>
<p>Both stream types support timeouts and blocking/non-blocking use.</p>
<h3>Example code</h3>
<p>Below is a small example that opens a serial port, configuring it with a stream context, and then reads and writes from it before closing it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
	<span style="color: #666666; font-style: italic;">// Create a stream context that configures the serial port</span>
	<span style="color: #666666; font-style: italic;">// And enables canonical input.</span>
	<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dio'</span> <span style="color: #339933;">=&gt;</span> 
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data_rate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">115200</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'data_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'stop_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'parity'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'is_canonical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Are we POSIX or Windows?  POSIX platforms do not have a</span>
	<span style="color: #666666; font-style: italic;">// Standard port naming scheme so it could be /dev/ttyUSB0</span>
	<span style="color: #666666; font-style: italic;">// or some long /dev/tty.serial_port_name_thingy on OSX.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>PATH_SEPARATOR <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dio.serial:///dev/ttyS0&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dio.serial://COM1&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Open the stream for read only and use it.</span>
	<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r+&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Writing to port...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">fprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Hello world<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Reading from port...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Stream context</h3>
<p>DIO uses the stream context to obtain the port configuration settings.  There are settings which are common to all DIO streams and settings which are sub-stream specific.  The common settings are:</p>
<style type="text/css">
th,td { text-align:left; vertical-align:top; }
</style>
<table style="width: 600px; margin: 0 auto">
<tr>
<th>perms</th>
<td>Integer</td>
<td>Sets the file permissions mask when creating a file (POSIX specific, ignored on Windows)</td>
</tr>
<tr>
<th>is_blocking</th>
<td>Boolean</td>
<td>Indicates whether the stream is blocking (true, default) or non blocking (false)</td>
</tr>
<tr>
<th>timeout_secs</th>
<td>Integer</td>
<td>The time to wait for input in seconds before returning.  Also sets the stream non blocking.</td>
</tr>
<tr>
<th>timeout_usecs</th>
<td>Integer</td>
<td>The time to wait for input in micro seconds before returning.  Used in conjunction with timeout_secs.  If omitted but timeout_secs is defined it is assumed to be zero.</td>
</tr>
</table>
<p>Both the blocking setting and the timeout settings can changed after the stream is open using the PHP functions <a href="http://www.php.net/manual/en/function.stream-set-blocking.php">stream_set_blocking()</a> and <a href="http://www.php.net/manual/en/function.stream-set-timeout.php">stream_set_timeout()</a> respectively.</p>
<p>The serial stream has the following additional configuration settings.</p>
<table style="width: 600px; margin: 0 auto">
<tr>
<th>data_rate</th>
<td>Integer</td>
<td>Sets the data rate in bits per second (Not BAUD.  BAUD is symbols per second.  A symbol may include more than one bit)</td>
</tr>
<tr>
<th>data_bits</th>
<td>Integer</td>
<td>Number of bits per byte.  Typically 5, 6, 7 or 8 (default).</td>
</tr>
<tr>
<th>stop_bits</th>
<td>Integer</td>
<td>The number of stop bits. 1 (default), 2 or 3 (1.5 stop bits)</td>
</tr>
<tr>
<th>parity</th>
<td>Integer</td>
<td>The parity checking.  0 (None, default), 1 (Odd), 2 (Even).</td>
</tr>
<tr>
<th>flow_control</th>
<td>Boolean</td>
<td>Enables/disables hardware flow control</td>
</tr>
<tr>
<th>is_canonical</th>
<td>Boolean</td>
<td>Enables canonical input mode.  Canonical input buffers the input until either internal buffer is full or an end of line has been received.  So a read in canonical mode will block until an end of line or file even if more than the requested characters have been read from the remote machine.  </p>
<p>Full canonical mode handles control characters, delete, echoing characters back to the remote machine and so on.  Its basically used to implement a terminal.  DIO doesn&#8217;t have any of the latter other than the buffering. Yet!</td>
</tr>
</table>
<h3>Finally</h3>
<p>So there you are.  Any results, good or bad, are useful.  DIO has error checking and will return useful warnings if you try and feed it silly values.  Logs, PHP versions, etc. would be useful diagnosing issues.  Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/02/02/php-dio-extension-looking-for-beta-testers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building PHP C extensions on Ubuntu 9.10</title>
		<link>http://www.cyberspice.org.uk/blog/2009/12/01/building-php-c-extensions-on-ubuntu-9-10/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/12/01/building-php-c-extensions-on-ubuntu-9-10/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 13:58:28 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=395</guid>
		<description><![CDATA[I have just taken over maintenance of the PECL Direct IO extension as it has been unmaintained for a while.  Naturally the first thing I did before writing any new code was to check out the extension from SVN and try and build it.  Building the source was fine but when I tried [...]]]></description>
			<content:encoded><![CDATA[<p>I have just taken over maintenance of the PECL Direct IO extension as it has been unmaintained for a while.  Naturally the first thing I did before writing any new code was to check out the extension from SVN and try and build it.  Building the source was fine but when I tried <em>make test</em> it failed producing output like the following:</p>
<pre>
PHP Warning:  PHP Startup: Unable to load dynamic library 'modules/gd.so' -
modules/gd.so: cannot open shared object file: No such file or
directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'modules/gd.so' -
modules/gd.so: cannot open shared object file: No such file or
directory in Unknown on line 0
</pre>
<p>The default PHP package on Ubuntu 9.10 is fairly minimalist.  Most extensions are provided as separate packages which include an INI file and a dynamic library.  The dynamic library is stored in:</p>
<pre>
/usr/lib/php5/20060613+lfs
</pre>
<p>And the INI file for each extension is in: </p>
<pre>
/etc/php5/conf.d.
</pre>
<p>The <em>make tests</em> rule in the generated Makefile in the extension you are compiling modifies the path that PHP searches for extensions by to point to the modules directory within the extension source.  So PHP, which is used to run the tests, cannot find the extensions.</p>
<p>I&#8217;ve found the easiest way (if slightly hacky) to fix the <em>make test</em> failure is just to copy the .so files from the PHP5 extension directory in to the modules directory within the extension source.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/12/01/building-php-c-extensions-on-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installing eclipse for multiple programming languages</title>
		<link>http://www.cyberspice.org.uk/blog/2009/11/20/installing_eclipse_for_multiple_programming_languages/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/11/20/installing_eclipse_for_multiple_programming_languages/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 14:39:59 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[CDT]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[JDT]]></category>
		<category><![CDATA[PDT]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=378</guid>
		<description><![CDATA[I can do almost everything I need to do in OS X but just occasionally I need Linux.  So I recently installed a VirtualBox VM running Ubuntu 9.10.  I use Eclipse as my favoured IDE since I can run it on all three of the major OSes and it has good support for [...]]]></description>
			<content:encoded><![CDATA[<p>I can do almost everything I need to do in OS X but just occasionally I need Linux.  So I recently installed a <a href="http://www.virtualbox.org/">VirtualBox</a> VM running <a href="http://www.ubuntu.com/">Ubuntu 9.10</a>.  I use <a href="http://www.eclipse.org/">Eclipse</a> as my favoured IDE since I can run it on all three of the major OSes and it has good support for C, C++ and Java which is what I use mostly for work.  So the next thing for me was to install Eclipse.  This is where things became interesting.<br />
<span id="more-378"></span><br />
My usual technique for installing Java and Eclipse on Linux is to grab the JDK from <a href="http://java.sun.com/">Sun&#8217;s site</a> and Eclipse from the Eclipse site. (Never try to run Eclipse on GNU Java, it just doesn&#8217;t work.)  I did this, installed Java, unpacked Eclipse and ran it.  It just didn&#8217;t seem to run right.  I suspected some Ubuntu 9.10 incompatibility since it was shortly after the release.  So I decided to use the Ubuntu packages for Sun&#8217;s Java and Eclipse.  It worked but the latter was somewhat minimalist.  </p>
<p>I really wanted to run &#8216;proper&#8217; Eclipse as released by Eclipse so it was time to Google for the problem and I found this <a href="http://mou.me.uk/2009/10/31/fixing-eclipse-in-ubuntu-9-10-karmic-koala/">link</a>.  It turns out that there is a bug in Eclipse to do with GTK which will be fixed in the next release.  However you can work around it.  Put the following shell script in to your Eclipse directory and when you run Eclipse using that and not the binary directly its fixed.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">#!/bin/bash
export GDK_NATIVE_WINDOWS=1
/path/to/eclipse/eclipse</pre></div></div>

<p>Anyway that&#8217;s a bit of an aside.  So now the post proper, how do you install Eclipse for multiple languages?  This is what I did.</p>
<h3>Eclipse for C/C++</h3>
<p>Go to <a href="http://www.eclipse.org/downloads">http://www.eclipse.org/downloads</a>, select packages and grab Eclipse IDE for C/C++.  <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?tar">Untar</a> it somewhere suitable like /usr/local.  You will have to be superuser to untar there so use <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?sudo">sudo</a>.</p>
<h3>Java Development Tools</h3>
<p>These come from <a href="http://download.eclipse.org/eclipse/downloads">http://download.eclipse.org/eclipse/downloads</a>.  Scroll down the page until you find &#8216;JDT Runtime Binary&#8217; and select the latest version.  This will download a ZIP file containing all the additional Java classes which provide the Java Development Tools.</p>
<p>Eclipse ZIP files are typically one of two kinds.  Either a collection of files you unzip in the directory where you eclipse directory is or one which that&#8217;s an &#8216;All in 1&#8242; update site.  The latter is a zip file that you can install via the Eclipse IDE itself since it contains the appropriate site.xml file used by the Eclipse installer.</p>
<p>The Eclipse JDT ZIP is not an update site so you will need to unzip in it in the directory you untarred the original files.  I.e. /usr/local.  If there are any clashes (because the file already exists) just select &#8216;N&#8217; meaning don&#8217;t overwrite.  </p>
<p>Once you&#8217;ve unpacked start Eclipse (sudo /path/to/eclipse/eclipse.sh) to ensure it looks sane.  You run it as root until you&#8217;re completely installed so that the extensions are installed for all users.  Hopefully, if all is well, you should see C/C++, CVS and Java projects available in the Projects menu.  Leave Eclipse running.</p>
<h3>DLTK, EMF-XSD and GEF</h3>
<p>DLTK is the Dynamic Languages Toolkit extension; EMF is the Eclipse Modelling Framework extension and GEF is the Graphical Editing Framework.  These form dependencies on the Web Tools and the PHP Development Tools.  Download the &#8216;All in 1&#8242; update sites for these as follows.</p>
<h4>DLTK</h4>
<p>Go to <a href="http://download.eclipse.org/technology/dltk/downloads/">http://download.eclipse.org/technology/dltk/downloads/</a>.  Select &#8216;Stable&#8217; and then the &#8216;All in 1 Update Site&#8217; bundle.  Save the ZIP somewhere sensible.</p>
<h4>EMF-XSD</h4>
<p>Go to <a href="http://www.eclipse.org/modeling/emf/downloads/?project=emf">http://www.eclipse.org/modeling/emf/downloads/?project=emf</a>.  Select the &#8216;All in 1 Update&#8217; bundle and again save it.</p>
<h4>GEF</h4>
<p>Go to <a href="http://www.eclipse.org/gef/downloads/">http://www.eclipse.org/gef/downloads/</a> and select the &#8216;All in 1 Update&#8217; and save it.</p>
<h4>Installing</h4>
<p>In the help menu select &#8216;Install new software&#8217;.  The top right of the dialog that appears is an &#8216;Add&#8217; button which adds a new install site, i.e. a URI from which new software can be installed.  Click on it.</p>
<div style="text-align:center;"><img src="http://www.cyberspice.org.uk/blog/wp-content/uploads/2009/11/AddSitesButton.png" alt="AddSitesButton.png" border="0" width="228" height="178" /></div>
<p>A new dialog appears with two fields.  Type &#8216;DLTK Local&#8217; in the first (&#8216;local&#8217;) field.  This is the short name the install site will be known as locally.  Click on the &#8216;Archive&#8217; button and navigate to the DLTK ZIP file you downloaded.  Select it.  Then click the &#8216;OK&#8217; button in the new site dialog.</p>
<div style="text-align:center;"><img src="http://www.cyberspice.org.uk/blog/wp-content/uploads/2009/11/AddSiteDialog.png" alt="AddSiteDialog.png" border="0" width="561" height="223" /></div>
<p>Now Eclipse will display what software is available from your install site (i.e. the DLTK ZIP file).  If you expand the tree you will see a whole selection of different components.  Some will have &#8216;SDK&#8217; as part of the name.  These components are ones which allow you to develop the Eclipse components themselves.  You don&#8217;t need these if you are using Eclipse to develop regular code so ignore those.  For DLTK I selected the core component and support for Python and Ruby (since I want to learn them at some point).  </p>
<div style="text-align:center;"><img src="http://www.cyberspice.org.uk/blog/wp-content/uploads/2009/11/AvailableSoftware.png" alt="AvailableSoftware.png" border="0" width="437" height="340" /></div>
<p>Click &#8216;Next&#8217;.  All the dependencies should be there.  Eclipse may install additional packages which are dependencies on the one&#8217;s you&#8217;ve selected.  It may also show a licence agreement you need to agree to.  Click through until &#8216;Finish&#8217; is shown.  Click &#8216;Finish&#8217; to install the software.  Eclipse may want to restart at this point, everyone apart from Ubuntu 9.10 users can click &#8216;Restart&#8217; here.  Because of the bug Ubuntu 9.10 users should click &#8216;No&#8217; and exit and restart Eclipse manually using the shell script as described above.</p>
<p>Do the same for the EMF-XSD package and select &#8216;XSD-XL Schema Model, XSD Documentation and XSD Edit&#8217;.  (Probably not all needed but useful).  Install and restart as before.  Add the GEF ZIP to the install sites so that it can be found later but don&#8217;t bother installing anything if you don&#8217;t want to.  This seems to be needed by the Web Tools but I didn&#8217;t want anything from it myself.</p>
<p>You should now have Ruby and Python projects as well as DTD, XSD, etc. projects available in the projects menu.  Quit Eclipse.</p>
<h3>Web Tools Platform</h3>
<p>WTP provides support for developing HTML, JavaScript etc. and is needed by the PHP Developer Tools.  The download site is <a href="http://download.eclipse.org/webtools/downloads/">http://download.eclipse.org/webtools/downloads/</a>.  Select the latest release and then download the web tools platform, wtd, ZIP file.</p>
<p>Like the JDT ZIP this is not an install site so needs to be unpacked in the same directory as you unpacked Eclipse and the JDT ZIP.  You will need to be superuser as before.  Again there may be files that already exist so you have to stop them from being over written.</p>
<p>Restart Eclipse as superuser so that it can update its state.  Now you should have web tools projects available like JavaScript, HTML etc. in the new project menu.</p>
<h3>PHP Developer Tools</h3>
<p>Finally we can install PDT.  You can get the all in one update site from <a href="http://www.eclipse.org/pdt/downloads/">http://www.eclipse.org/pdt/downloads/</a> as a ZIP.  In Eclipse using the &#8216;Install New Software&#8217; dialog add it as an install site, select the PDT tools and install them.  Eclipse will install anything it needs from the other install sites you used earlier.  Finally restart Eclipse one last time.</p>
<p>Yay!  You should have Eclipse installed for a whole bucket load of languages.  Because you installed the plug-ins as superuser they are available for everyone on your system.  Finally, because you don&#8217;t want to have to do this all over again should something go wrong, tar up the entire Eclipse directory and put it somewhere safe.</p>
<div style="text-align:center;"><img src="http://www.cyberspice.org.uk/blog/wp-content/uploads/2009/11/ProjectMenu.png" alt="ProjectMenu.png" border="0" width="344" height="415" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/11/20/installing_eclipse_for_multiple_programming_languages/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Boarduino vivarium temperature monitor</title>
		<link>http://www.cyberspice.org.uk/blog/2009/10/29/boarduino-vivarium-temperature-monitor/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/10/29/boarduino-vivarium-temperature-monitor/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 14:56:01 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[BoArduino]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=336</guid>
		<description><![CDATA[I like snakes.  This weekend I will be collecting my new snake, he&#8217;s a baby Royal Python.  I have been worried about the temperature in the vivarium I will be housing him so I built an ethernet enabled monitoring device to do a science!

]]></description>
			<content:encoded><![CDATA[<p>I like snakes.  This weekend I will be collecting my new snake, he&#8217;s a baby Royal Python.  I have been worried about the temperature in the vivarium I will be housing him so I built an ethernet enabled monitoring device to do a science!</p>
<p><a href="http://www.flickr.com/photos/39013214@N03/4053539738" title="View 'Vivarium Temperature Monitor' on Flickr.com">
<div style="text-align:center;"><img src="http://farm3.static.flickr.com/2501/4053539738_31c7203c09.jpg" alt="Vivarium Temperature Monitor" border="0" width="500@ height="333" /></div>
<p></a></p>
<p><span id="more-336"></span><br />
Its a <a href="http://www.ladyada.net/make/boarduino/">BoArduino</a>, an <a href="http://www.oomlout.co.uk/lcd-display-16-x-2-p-212.html">HD4470 compatible LCD display</a>, a <a href="http://www.saelig.com/BRD/ETH027.htm">WIZ810MJ</a> ethernet module (in an <a href="http://www.nkcelectronics.com/wiznet-wiz810mj-module-to-breadboard-spi-adap.html">adapter board</a>) and some discrete components with a <a href="http://www.oomlout.co.uk/temperature-sensor-tmp36-p-210.html">TMP36</a> for temperature monitoring.  </p>
<p>This is the result set for the last day.  The live graph is <a href="http://www.cyberspice.org.uk/projects/vivmonitor">here</a>.</p>
<p><a href="http://www.flickr.com/photos/39013214@N03/4055151155" title="View 'The Generated Graph' on Flickr.com">
<div style="text-align:center;"><img src="http://farm4.static.flickr.com/3479/4055151155_d13347aafd.jpg" alt="The Generated Graph" border="0" width="500" height="260" /></div>
<p></a></p>
<p>The circuit uses nearly all of the digital pins (it would use them all if the ethernet library supported interrupts).  The LCD is connected using digital pins 3 to 8.  Pins 3 to 6 are the data lines, 7 is the enable pin and 8 is RS.  The ethernet module is connected using digital pins 9 to 13 being Reset, SS, MOSI, MISO and SCLK.  The temperature sensor is connected to Analog pin 0.  It outputs 10mV per degree Celcius with a 500mV offset so that 0C is 500mv, 50C is 1V etc.  The code sketch is below.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Required for the LCD</span>
<span style="color: #339933;">#include &lt;LiquidCrystal.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Required for ethernet</span>
<span style="color: #339933;">#include &lt;Client.h&gt;</span>
<span style="color: #339933;">#include &lt;Ethernet.h&gt;</span>
<span style="color: #339933;">#include &lt;Server.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Required for the IINCHIP macros</span>
<span style="color: #339933;">#include &lt;utility/spi.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The ethernet reset control pin</span>
<span style="color: #993333;">int</span> resetPin  <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// The temperature analog input pin</span>
<span style="color: #993333;">int</span> tempAnPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// String buffer</span>
<span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">256</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Hardcoded MAC, IP and gateway</span>
byte mac<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #208080;">0xDE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xAD</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xBE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xEF</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xFE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xED</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
byte ip<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">140</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
byte gw<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">254</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create an LCD control object.  Doesn't use regular pins as</span>
<span style="color: #666666; font-style: italic;">// we need some of them for the Ethernet SPI.</span>
LiquidCrystal lcd<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Hardcoded server and port</span>
byte svr<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">128</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span>  port  <span style="color: #339933;">=</span> <span style="color: #0000dd;">80</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// A client class for connecting to a remote server to send data</span>
Client client<span style="color: #009900;">&#40;</span>svr<span style="color: #339933;">,</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Writes a byte to a register in the W5100 chip used by the 
 * WIZ810MJ ethernet board. 
 *
 * @param addr The address in the W5100 controller to write.
 * @param data The byte to write.
 */</span>
<span style="color: #993333;">void</span> writeByte<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> addr<span style="color: #339933;">,</span> byte data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  IINCHIP_ISR_DISABLE<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  IINCHIP_SpiInit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  IINCHIP_CSoff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  IINCHIP_SpiSendData<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xf0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  IINCHIP_SpiSendData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>addr <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xff00</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  IINCHIP_SpiSendData<span style="color: #009900;">&#40;</span>addr <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xff</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  IINCHIP_SpiSendData<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  IINCHIP_CSon<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  IINCHIP_ISR_ENABLE<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The four IP addres bytes (we're not IP6 compatible here)</span>
byte ip0<span style="color: #339933;">,</span> ip1<span style="color: #339933;">,</span> ip2<span style="color: #339933;">,</span> ip3<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Initialise the hardware
 */</span>
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Reset the ethernet board</span>
  pinMode<span style="color: #009900;">&#40;</span>resetPin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>resetPin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 1ms</span>
  digitalWrite<span style="color: #009900;">&#40;</span>resetPin<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 1ms</span>
  digitalWrite<span style="color: #009900;">&#40;</span>resetPin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
  <span style="color: #666666; font-style: italic;">// Start ethernet</span>
  Ethernet.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span>mac<span style="color: #339933;">,</span> ip<span style="color: #339933;">,</span> gw<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Enable ping.  Useful for debugging.</span>
  writeByte<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0000</span><span style="color: #339933;">,</span> <span style="color: #208080;">0x00</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Read the IP address (Check to see its working right) </span>
  ip0 <span style="color: #339933;">=</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x000f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ip1 <span style="color: #339933;">=</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0010</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ip2 <span style="color: #339933;">=</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0011</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ip3 <span style="color: #339933;">=</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0012</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Form the output string (Adds about a K to the code size)</span>
  sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%d.%d.%d.%d&quot;</span><span style="color: #339933;">,</span> ip0<span style="color: #339933;">,</span> ip1<span style="color: #339933;">,</span> ip2<span style="color: #339933;">,</span> ip3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Display it</span>
  lcd.<span style="color: #202020;">home</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">#ifdef DEBUG</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#endif</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The value of the temperature analog pin</span>
<span style="color: #993333;">int</span> tempAnValue<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The temperature</span>
<span style="color: #993333;">int</span> temperature<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The temperature components;</span>
<span style="color: #993333;">int</span> tempInt<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> tempFrac<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// A counter for sychronization.  Allows server to work out if a</span>
<span style="color: #666666; font-style: italic;">// 'packet' is missing</span>
<span style="color: #993333;">int</span> count <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Main processing thread
 */</span>
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Read the temperature</span>
  tempAnValue <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>tempAnPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Fixed point math to calculate the temperature (multiply then divide</span>
  <span style="color: #666666; font-style: italic;">// to reduce rounding issues) Gives temperature in 100ths of degree C</span>
  <span style="color: #666666; font-style: italic;">// 5000 millivolts is the maximum voltage</span>
  <span style="color: #666666; font-style: italic;">// 1024 is the maximum ADC value</span>
  <span style="color: #666666; font-style: italic;">// 500mv is 0 degrees C</span>
  temperature <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>tempAnValue <span style="color: #339933;">*</span> <span style="color: #0000dd;">50000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">1024</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">5000</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Since we're only going to report to 1 decimal place, add 5 for correct</span>
  <span style="color: #666666; font-style: italic;">// rounding</span>
  tempInt  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>temperature <span style="color: #339933;">+</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">;</span>
  tempFrac <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>temperature <span style="color: #339933;">+</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Form the output string</span>
  sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Temp: %d.%d C&quot;</span><span style="color: #339933;">,</span> tempInt<span style="color: #339933;">,</span> tempFrac<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Display it</span>
  lcd.<span style="color: #202020;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">#ifdef DEBUG</span>
<span style="color: #009900;">&#123;</span>
    sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> 
            <span style="color: #ff0000;">&quot;HEAD /newtemp.php?count=%d&amp;temp=%d.%d HTTP/1.1&quot;</span><span style="color: #339933;">,</span> 
            count<span style="color: #339933;">,</span> tempInt<span style="color: #339933;">,</span> tempFrac<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Host: my.host.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Connection: close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#ifndef NO_ETHERNET</span>
  <span style="color: #666666; font-style: italic;">// Send to server</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// If connected send the packet count and temperature</span>
    sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> 
            <span style="color: #ff0000;">&quot;HEAD /newtemp.php?count=%d&amp;temp=%d.%d HTTP/1.1&quot;</span><span style="color: #339933;">,</span> 
            count<span style="color: #339933;">,</span> tempInt<span style="color: #339933;">,</span> tempFrac<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Host: my.host.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Connection: close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #202020;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// If failed sad face</span>
    lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; :-(&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#endif</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Update packet counter</span>
  count<span style="color: #339933;">++;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Sleep for a minute</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">60000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A couple of things to note are:</p>
<ul>
<li>I use integer math.  avrgcc, the compiler, supports floats but its just more efficient and requires less memory to use fixed point integer math when its just one or two values you need to represent.</li>
<li>I use a count value sent with each data packet so that if one goes missing you can tell,  Currently the code at the other end doesn&#8217;t use it though.</li>
<li>I send a HEAD request with a query string containing the values.  My request is not technically valid HTTP but the server doesn&#8217;t have a problem.  A HEAD request returns the headers for a request but no body.  Since I&#8217;m ignoring the whole response anyway I don&#8217;t need the body!
</li>
<p>The script on the web server that receives the data is below.  It is very simple PHP.  Since PHP doesn&#8217;t support HEAD requests directly in its super-globals (watch this space <img src='http://www.cyberspice.org.uk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I process the query string by hand.  As I know the format of the data since I control the client I&#8217;m not worried about URL decoding the data.  It writes three values (the time in seconds since the UNIX epoch, the packet count and the temperature), colon separated, as a line to a text file.  It returns nothing.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'HEAD'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$keyval</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$keyval</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$keyval</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/path/to/tempdata.txt'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'a+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temp'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Another script generates a graph as a PNG file based on the data.  This code is below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WIDTH'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HEIGHT'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">520</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FONT'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the temperature data</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/tempdata.txt&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$keyval</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$keyval</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span>        <span style="color: #339933;">=</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$keyval</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span>       <span style="color: #339933;">=</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$keyval</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$keyval</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the number of data points</span>
<span style="color: #000088;">$datapoints</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Lines are chronological</span>
<span style="color: #000088;">$mintime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$maxtime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$datapoints</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Temperatures need to be processed.</span>
<span style="color: #000088;">$mintemp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$maxtemp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$datapoint</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$mintemp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mintemp</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$datapoint</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span> ? 
	           <span style="color: #000088;">$mintemp</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$datapoint</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$maxtemp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$maxtemp</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$datapoint</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span> ? 
	           <span style="color: #000088;">$maxtemp</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$datapoint</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the axis dimensions.  Round up and down to the nearest</span>
<span style="color: #666666; font-style: italic;">// degree C and hour.</span>
<span style="color: #000088;">$lowtime</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mintime</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hightime</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$maxtime</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$difftime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hightime</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$lowtime</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$lowtemp</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mintemp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hightemp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$maxtemp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$difftemp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hightemp</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$lowtemp</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the image</span>
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreate</span><span style="color: #009900;">&#40;</span>WIDTH<span style="color: #339933;">,</span> HEIGHT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$background</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$black</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$red</span>        <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blue</span>       <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Draw the axes</span>
	<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">485</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">480</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">980</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">480</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">980</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">480</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">980</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">485</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$difftime</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">960</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$difftime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">480</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">483</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$difftemp</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">480</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">460</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$difftemp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">17</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Draw the labels</span>
	<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> FONT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">490</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;H:i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lowtime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> FONT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">970</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">490</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;H:i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hightime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagestringup</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> FONT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">485</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lowtemp</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'C'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagestringup</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> FONT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hightemp</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'C'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Draw the points</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Position of the first point</span>
	<span style="color: #000088;">$prevx</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$lowtime</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">960</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$difftime</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$prevy</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$lowtemp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">460</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$difftemp</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Draw line from previous point to current point</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$datapoints</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$lowtime</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">960</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$difftime</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'temperature'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$lowtemp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">460</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$difftemp</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imageline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prevx</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">480</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$prevy</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">480</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$red</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$prevx</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$prevy</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$y</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Finally time and date stamp</span>
	<span style="color: #000088;">$generated</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Generated: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> 
	            FONT<span style="color: #339933;">,</span>
	            WIDTH <span style="color: #339933;">-</span> <span style="color: #cc66cc;">15</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagefontwidth</span><span style="color: #009900;">&#40;</span>FONT<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$generated</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	            HEIGHT <span style="color: #339933;">-</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> 
	            <span style="color: #000088;">$generated</span><span style="color: #339933;">,</span>
	            <span style="color: #000088;">$blue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Output the image</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Destroy it</span>
	<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This was a fun little project and as can be seen from the snap shot of the graph changing the bulb significantly changes the maximum temperature of the vivarium.  I will be running with the smaller wattage bulb.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/10/29/boarduino-vivarium-temperature-monitor/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PHP NW and the Decorator Pattern</title>
		<link>http://www.cyberspice.org.uk/blog/2009/09/09/php-nw-and-the-decorator-pattern/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/09/09/php-nw-and-the-decorator-pattern/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:43:08 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Women In Technology]]></category>
		<category><![CDATA[PHP NW]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=281</guid>
		<description><![CDATA[The first Tuesday of the month is the PHP NW meeting in Manchester.  This month I was the warm act for PHP celebrity Derick Rethans.  Due to traffic issues Lornajane and Derick were late so I gave my talk first.  It was one in a series of talks on Design Patterns being [...]]]></description>
			<content:encoded><![CDATA[<p>The first Tuesday of the month is the PHP NW meeting in Manchester.  This month I was the warm act for PHP celebrity <a href="http://derickrethans.nl/">Derick Rethans</a>.  Due to traffic issues Lornajane and Derick were late so I gave my talk first.  It was one in a series of talks on <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)">Design Patterns</a> being given by various members of the group.  Mine was on the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">Decorator Pattern</a>.  The slides from the talk are available for <a href="http://www.cyberspice.org.uk/downloads/DecoratorPattern.pdf">download</a>.</p>
<p>Derick&#8217;s very interesting talk was on <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a> in a PHP environment.  Derick is the author of <a href="http://www.xdebug.org/">XDebug</a> and an expert in PHP QA.  It covered the concepts behind Test Driven Development and why it both improves code quality and makes code development more efficient over the long term.  It covered the use of <a href="http://www.phpunit.de/">PHPUnit</a>, XDebug and <a href="http://cruisecontrol.sourceforge.net/">CruiseControl</a>.  As a fan of quality reusable code this is a great way to develop.</p>
<p>Next month is the <a href="http://conference.phpnw.org.uk/phpnw09/">PHP NW 2009 Conference</a> held in Manchester.  The you can see Derick and some of other great European PHP conference speakers doing their thing.  Its fantastic value for money and you get a year&#8217;s subscription to <a href="http://www.phparch.com/">PHP Architect Magazine</a> too.  Bargain!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/09/09/php-nw-and-the-decorator-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
