<?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>KRKeegan</title>
	<atom:link href="http://www.krkeegan.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.krkeegan.com</link>
	<description></description>
	<lastBuildDate>Wed, 29 May 2013 17:06:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>A Temperature Controlled Whole House Fan with MisterHouse</title>
		<link>http://www.krkeegan.com/a-temperature-controlled-whole-house-fan-with-misterhouse/</link>
		<comments>http://www.krkeegan.com/a-temperature-controlled-whole-house-fan-with-misterhouse/#comments</comments>
		<pubDate>Sun, 26 May 2013 23:24:35 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=92</guid>
		<description><![CDATA[The main feature of MisterHouse that sets it apart from other home automation systems is the ability to customize practically every aspect of the system.  The following example is a perfect demonstration of this. I recently purchased a whole house &#8230; <a href="http://www.krkeegan.com/a-temperature-controlled-whole-house-fan-with-misterhouse/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft" alt="MisterHouse Web Interface for a Temperature Controlled Whole House Fan" src="http://www.krkeegan.com/wp-content/uploads/2013/05/Capture-196x300.jpg" width="196" height="300" />The main feature of MisterHouse that sets it apart from other home automation systems is the ability to customize practically every aspect of the system.  The following example is a perfect demonstration of this.</p>
<p>I recently purchased a whole house fan, basically a giant fan that sucks hot air out from the highest point in my house. They are great if you live in a climate with cool nights.</p>
<p>The controls for my fan were very basic, an on/off switch and a two-speed setting.</p>
<p>With Misterhouse, I created an &#8220;auto&#8221; mode which will only turn on the fan if both the indoor temperature is above a defined threshold and the outdoor temperature is 5 degrees below the indoor temperature.</p>
<p>This is how I did it.</p>
<p>Starting Materials<br />
- A Fan<br />
- 2 IOLincs, (1 for on/off, 1 for fan speed)<br />
- A MisterHouse enabled indoor temperature sensor (I used my Insteon Thermostat)<br />
- A MisterHouse enabled outdoor temperature sensor (I used data from a neighbor&#8217;s weather station through weatherunderground)</p>
<p>I created the following items in my mht file:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;">GENERIC<span style="color: #339933;">,</span> house_fan<span style="color: #339933;">,</span> HVAC<span style="color: #339933;">|</span>WHF_Group
GENERIC<span style="color: #339933;">,</span> house_fan_temp<span style="color: #339933;">,</span> HVAC<span style="color: #339933;">|</span>WHF_Group
GENERIC<span style="color: #339933;">,</span> house_fan_setpoint<span style="color: #339933;">,</span> HVAC<span style="color: #339933;">|</span>WHF_Group
GENERIC<span style="color: #339933;">,</span> house_fan_ambient<span style="color: #339933;">,</span> HVAC<span style="color: #339933;">|</span>WHF_Group
INSTEON_IOLINC<span style="color: #339933;">,</span> DE<span style="color: #339933;">.</span>AD<span style="color: #339933;">.</span>BE<span style="color: #339933;">:</span>01<span style="color: #339933;">,</span> whf_main<span style="color: #339933;">,</span> HVAC
INSTEON_IOLINC<span style="color: #339933;">,</span> DE<span style="color: #339933;">.</span>AD<span style="color: #339933;">.</span>BE<span style="color: #339933;">:</span>01<span style="color: #339933;">,</span> whf_speed<span style="color: #339933;">,</span> HVAC</pre></td></tr></table></div>

<p>I also had the following items already setup:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$upstairs_thermo_temp</span> <span style="color: #666666; font-style: italic;">#the temperature upstairs</span>
<span style="color: #0000ff;">$w_temp</span> <span style="color: #666666; font-style: italic;">#the outside temperature</span></pre></td></tr></table></div>

<p>First, I set the available states for my generic objects:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$house_fan</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set_states</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'on'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'off'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'auto'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$house_fan_speed</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set_states</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'high'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'low'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$house_fan_temp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set_states</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'cooler'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'warmer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then I tied my generic items to my Insteon Devices:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$house_fan</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">tie_event</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'$whf_main-&gt;set(&quot;on&quot;)'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;on&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$house_fan</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">tie_event</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'$whf_main-&gt;set(&quot;off&quot;)'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;off&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$house_fan_speed</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">tie_event</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'$whf_speed-&gt;set(&quot;on&quot;)'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;high&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$house_fan_speed</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">tie_event</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'$whf_speed-&gt;set(&quot;off&quot;)'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;low&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then I tied my Generic temp item to my Generic setpoint item, and inserted some custom code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$house_fan_temp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">tie_event</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'house_fan_temp_change($state)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">sub</span> house_fan_temp_change <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$state</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;warmer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$house_fan_setpoint</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$house_fan_setpoint</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</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: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;cooler&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$house_fan_setpoint</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$house_fan_setpoint</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>By doing this, I can have a nice cooler and warmer button in the web panel.</p>
<p>Finally, every minute I check to see if the device is in &#8220;auto&#8221; mode and whether or not it should turn on:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$New_Minute</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$house_fan</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'auto'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$upstairs_thermo_temp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$house_fan_setpoint</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
		<span style="color: #009900;">&#40;</span><span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$upstairs_thermo_temp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$w_temp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$whf_main</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'off'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #339933;">::</span><span style="color: #006600;">print_log</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;[a1housefan.pl] Auto: Turning on fan&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #0000ff;">$whf_main</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;on&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$whf_main</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'on'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #339933;">::</span><span style="color: #006600;">print_log</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;[a1housefan.pl] Auto: Turning off fan&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #0000ff;">$whf_main</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;off&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The result, is a temperature controlled whole house fan.  The image above is a screen shot from my web interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/a-temperature-controlled-whole-house-fan-with-misterhouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insteon RemoteLinc 2 Lacks the Heartbeat Feature?</title>
		<link>http://www.krkeegan.com/insteon-remotelinc-2-lacks-the-heartbeat-feature/</link>
		<comments>http://www.krkeegan.com/insteon-remotelinc-2-lacks-the-heartbeat-feature/#comments</comments>
		<pubDate>Fri, 10 May 2013 03:46:00 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Home Automation]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=81</guid>
		<description><![CDATA[A heartbeat is a simple broadcast packet sent at a predetermined interval.  The purpose of the packet is to announce to everyone that the device &#8220;is still alive.&#8221; The Insteon RemoteLinc 2 is a battery powered insteon remote, that remains &#8230; <a href="http://www.krkeegan.com/insteon-remotelinc-2-lacks-the-heartbeat-feature/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class=" wp-image-86 alignleft" alt="" src="http://www.krkeegan.com/wp-content/uploads/2013/05/Remotelinc21.jpg1-300x300.jpg" width="180" height="180" />A heartbeat is a simple broadcast packet sent at a predetermined interval.  The purpose of the packet is to announce to everyone that the device &#8220;is still alive.&#8221;</p>
<p>The Insteon RemoteLinc 2 is a battery powered insteon remote, that remains in a sleep state when it is not sending messages.  In this state the remote does not listen or respond to any packets sent to it.</p>
<p>As a battery operated device, the remotelinc will eventually need to be recharged, and it would be nice to know when a recharge is needed rather than finding out when the device doesn&#8217;t work.  The remotelinc has a command to query the battery level, but this query won&#8217;t work if the device is asleep.</p>
<p>This is where a heartbeat message would be nice.  It would automatically wake up the device at a periodic interval, allowing a battery level request to be sent to the device.</p>
<p>Best I can tell, the Remotelinc heartbeat function has been disabled or not included.  The following settings are supposed to control the hearbeat function:</p>
<table>
<tbody>
<tr>
<td>Awake Interval</td>
<td>Sets the amount of time the Remotelinc remains awake with no activity.</td>
<td>This is editable</td>
</tr>
<tr>
<td>Sleep Interval</td>
<td>Sets the amount of time the Remotelinc remains asleep, before waking up to send a heartbeat message.</td>
<td>The device ACKs my changes, but the settings on the device don&#8217;t change.</td>
</tr>
<tr>
<td>Broadcast Number</td>
<td>Sets the number of heartbeat messages that should be sent every time the sleep interval expires.</td>
<td>The device ACKs my changes, but the settings on the device don&#8217;t change.</td>
</tr>
<tr>
<td>NoIAmAwake Bit</td>
<td>A single bit to disable sending heart beat messages, presumably overrides all of the other settings.</td>
<td>The device ACKs my changes, but the settings on the device don&#8217;t change.</td>
</tr>
</tbody>
</table>
<p>Other users have <a href="http://www.perceptiveautomation.com/userforum/viewtopic.php?f=3&amp;t=9487">reported similar problems</a> over at the Indigo support forum.</p>
<p>As a work around, <a href="http://misterhouse.wikispaces.com/Insteon">Misterhouse </a>will send a battery level request immediately after receiving a message from the RemoteLinc.  The RemoteLinc will stay awake after sending a message for the amount of time specified in Awake Interval, I set mine to 10 seconds. Battery level requests will only be sent if the amount of time since the last battery level response has exceeded a defined threshold.</p>
<p>All of this works well, except for rarely used devices.  It is possible that such a remotelinc could die without there being a chance to query its battery level.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/insteon-remotelinc-2-lacks-the-heartbeat-feature/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insteon All-Link Control Flags</title>
		<link>http://www.krkeegan.com/insteon-all-link-control-flags/</link>
		<comments>http://www.krkeegan.com/insteon-all-link-control-flags/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 05:14:42 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Home Automation]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=72</guid>
		<description><![CDATA[For whatever reason it is difficult to locate the breakdown of the Insteon All-Link Control Flags. Link Control Flags: Bit 7: 1 = Record is in use, 0 = Record is available Bit 6: 1 = Controller (Master) of Device &#8230; <a href="http://www.krkeegan.com/insteon-all-link-control-flags/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For whatever reason it is difficult to locate the breakdown of the Insteon All-Link Control Flags.</p>
<p>Link Control Flags:<br />
Bit 7: 1 = Record is in use, 0 = Record is available<br />
Bit 6: 1 = Controller (Master) of Device ID, 0 = Responder to (Slave of) Device ID<br />
Bit 5: 1 = ACK Required, 0 = No ACK Required (currently always set to 1)<br />
Bit 4: Reserved<br />
Bit 3: Reserved<br />
Bit 2: Reserved<br />
Bit 1: 1 = Record has been used before (‘high-water’ mark)<br />
Bit 0: Unused</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/insteon-all-link-control-flags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insteon All-Link Cleanup Failure Report Documentation Error</title>
		<link>http://www.krkeegan.com/insteon-all-link-cleanup-failure-report-documentation-error/</link>
		<comments>http://www.krkeegan.com/insteon-all-link-cleanup-failure-report-documentation-error/#comments</comments>
		<pubDate>Sat, 16 Feb 2013 05:57:35 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Home Automation]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=66</guid>
		<description><![CDATA[The documentation for the Insteon PLM defines an All-Link Cleanup Failure Report as being 7 bytes long with the 3rd byte being a useless 0&#215;01. In fact, command 0&#215;56 is actually only 6 bytes in length.  The 3rd byte listed &#8230; <a href="http://www.krkeegan.com/insteon-all-link-cleanup-failure-report-documentation-error/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.krkeegan.com/wp-content/uploads/2013/02/all_link.png"><img class="size-medium wp-image-67 alignright" alt="Insteon All Link Cleanup Failure Report" src="http://www.krkeegan.com/wp-content/uploads/2013/02/all_link-300x172.png" width="300" height="172" /></a>The documentation for the Insteon PLM defines an All-Link Cleanup Failure Report as being 7 bytes long with the 3rd byte being a useless 0&#215;01.</p>
<p>In fact, command 0&#215;56 is actually only 6 bytes in length.  The 3rd byte listed in the documentation does not exist.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/insteon-all-link-cleanup-failure-report-documentation-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Get date for nth occurrence of weekday</title>
		<link>http://www.krkeegan.com/php-get-date-for-nth-occurrence-of-weekday/</link>
		<comments>http://www.krkeegan.com/php-get-date-for-nth-occurrence-of-weekday/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 03:09:00 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=13</guid>
		<description><![CDATA[I looked quickly and did not see any code out there to determine the nth occurrence of a specific day of the week in a month.  For example Thanksgiving is the 4th Thursday in November.  So I designed the following &#8230; <a href="http://www.krkeegan.com/php-get-date-for-nth-occurrence-of-weekday/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I looked quickly and did not see any code out there to determine the nth occurrence of a specific day of the week in a month.  For example Thanksgiving is the 4th Thursday in November.  So I designed the following</p>
<pre>&lt;?php
$year = 2012; 
//Pick your year
$interval = 4; 
//Week number, in this case the 4th week
$dayofweek = 4; 
//Day of week 0=Sun, 1=Mon. . .
$month = 11; 
//Month 1=Jan, 2=Feb

$firstday = jddayofweek(gregoriantojd($month, 1, $year), 0);
if($firstday &lt;= $dayofweek){
  $date = (($interval * 7)-6) + ($dayofweek - $firstday);
}else{
  $date = (($interval * 7)-1) + (6 - $firstday);
}
echo date("n/j/Y", mktime(0, 0, 0, $month, $date, $year));
?&gt;</pre>
<p>It looks a little messy, but it works perfectly.</p>
<p>&nbsp;</p>
<p><strong>UPDATE:</strong></p>
<p>So apparently as bad as this looks it works too:</p>
<p><span id="more-13"></span></p>
<pre>echo date("n/j/Y", strtotime("3 weeks thursday",mktime(0,0,0,11,1,$year)));</pre>
<p>But I can&#8217;t get it to work correctly for the 1st Thursday in November.  Also I have seen a few comments that strtotime is significantly slower than other functions.</p>
<p>Another user on php.net posted the following, it is a significantly cleaner version of my code:</p>
<pre>&lt;?php

function get_day( $describer, $weekday, $reference_date ) {
   //$reference_date format = m-Y    $d = explode('-',$reference_date);
   switch ($describer) {
        case 'first':  
$offset = get_day_offset($reference_date, $weekday); 
break;
        case 'second': 
$offset = get_day_offset($reference_date, $weekday) + 7; 
break;
        case 'third':  
$offset = get_day_offset($reference_date, $weekday) + 14;
break;
        case 'fourth': 
$offset = get_day_offset($reference_date, $weekday) + 21; 
break;
        case 'last':
$reference_date = ($d[0]+1).'-'.($d[1]); 
$d = explode('-',$reference_date);
$offset = get_day_offset($reference_date, $weekday) - 7;
break;
    }
    $r = mktime( 0, 0, 0, $d[0], 1+$offset, $d[1] );
    return $r;  //returns timestamp format}

function get_day_offset( $anchor , $target ) {  
//$anchor format = m-Y
    $ts = explode('-',$anchor);
    $ts = mktime(0,0,0,$ts[0],'01',$ts[1]);
    $anchor = date("w",$ts);
    $target = strtolower($target);
    $days = array( 'sunday'=&gt;0, 'monday'=&gt;1, 'tuesday'=&gt;2, 'wednesday'=&gt;3, 'thursday'=&gt;4, 'friday'=&gt;5, 'saturday'=&gt;6 );
    $offset = $days[$target] - $anchor;
    if ($offset&lt;0) $offset+=7;
    return $offset;  //returns 0-6 for use in get_day()
;}
       $date1 = get_day("second", "saturday", "12-2007");$date2 = get_day("last", "friday", "11-2007");
echo "Second Saturday of December, 2007: ".date("m-d-Y", $date1)."&lt;br&gt;";
echo "Last Friday of November, 2007: ".date("m-d-Y", $date2)."&lt;br&gt;";
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/php-get-date-for-nth-occurrence-of-weekday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Google Talk with Roundcube</title>
		<link>http://www.krkeegan.com/integrating-google-talk-with-roundcube/</link>
		<comments>http://www.krkeegan.com/integrating-google-talk-with-roundcube/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 04:23:00 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=12</guid>
		<description><![CDATA[Sorry I don&#8217;t have much time at the moment to write up a whole entry about this, but I am very excited about this. I am a big fan of roundcube but I have always wanted the ability to integrate &#8230; <a href="http://www.krkeegan.com/integrating-google-talk-with-roundcube/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>
<div style="width: 110px;" class="serendipity_imageComment_left">
<div class="serendipity_imageComment_img"><a href="/uploads/roundcubewithgtalk.JPG" class="serendipity_image_link"><!-- s9ymdb:98 --><img height="86" width="110" src="/uploads/roundcubewithgtalk.serendipityThumb.JPG" /></a></div>
</div>
<p>Sorry I don&#8217;t have much time at the moment to write up a whole entry about this, but I am very excited about this.</p>
<p>I am a big fan of roundcube but I have always wanted the ability to integrate some instant messaging into it.  Well google finally released a gtalk gadget that allows you to integrate gtalk/gchat into any page you want.  Although, google has done a very poor job of announcing this and I don&#8217;t think most people know about it.</p>
<p>Anyways, it is a very simple single line &lt;iframe&gt; code.  I just quickly added it to the roundcube template and made a few changes to the CSS code and it works perfectly.</p>
<p>Click the image above to see a larger screen shot.  I will write up the code for this later when I have some free time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/integrating-google-talk-with-roundcube/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Resurrect Procmail and Spamassassin on Dreamhost</title>
		<link>http://www.krkeegan.com/how-to-resurrect-procmail-and-spamassassin-on-dreamhost/</link>
		<comments>http://www.krkeegan.com/how-to-resurrect-procmail-and-spamassassin-on-dreamhost/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 21:39:18 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=38</guid>
		<description><![CDATA[Admittedly I have been very annoyed with Dreamhost since they announced that users would no longer be able to use procmail. How to get procmail Back After reading the most recent entry I realized that it is possible to still &#8230; <a href="http://www.krkeegan.com/how-to-resurrect-procmail-and-spamassassin-on-dreamhost/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a class="serendipity_image_link" href="/uploads/dreamhost_procmail.gif"><!-- s9ymdb:95 --><img style="border: 0px none; float: left; padding-left: 5px; padding-right: 5px;" src="/uploads/dreamhost_procmail.serendipityThumb.gif" alt="" width="78" height="110" /></a>Admittedly I have been very annoyed with Dreamhost since <a href="http://krkeegan.com/archives/84-Dreamhost-Removes-Procmail.html">they announced</a> that users would no longer be able to use procmail.</p>
<p><strong>How to get procmail Back</strong></p>
<p>After reading the most recent entry I realized that it is possible to still use both procmail and spamassassin.  However, this solution is not elegant.</p>
<p>Currently Dreamhost has a rudimentary <a href="http://wiki.dreamhost.com/Mail_Control_Panel#Keyword_Filter">Mail Filter system</a> that is accessible by all mail users.  This system is due to be <a href="http://blog.dreamhost.com/2008/05/23/what-web-hosting-is-for/#comment-95733">upgraded soon</a>.  Dreamhost also allows regular shell users to access and run <a href="http://wiki.dreamhost.com/Procmail">procmail</a> as well as spamassassin.  In fact, shell users can install their own custom install of <a href="http://wiki.dreamhost.com/SpamAssassin">spamassassin</a>.  Lastly, shell users can also receive email, although there is no imap or pop service for this mail.</p>
<p><span id="more-38"></span></p>
<div>
<strong> The Process</strong></div>
<p>Using the above features it is possible to run a spamassassin setup that seems identical to the end user.  It works by forwarding your email all over the place.  First, your email is received by a mail account, this mail account has access to the rudimentary keyword filter.  The mail filter looks for an X-Scanned header to see if this email has already run through the procmail system.  Second, if the message has not been run through the procmail system it is forwarded to a user shell account.  Third, the user shell account receives the email and runs it through procmail and spamassassin.  During the process the procmail script adds the X-Scanned header, the procmail script can also add an X-Sort header if necessary.  Fourth, the last recipe in the procmail script forwards the email back to the mail account.  Finally, the mail account filters the email again, this time seeing the X-Scanned header and places it in your inbox.</p>
<p>The following is a flow chart that describes the process:<br />
<!-- s9ymdb:95 --><a class="serendipity_image_link" href="/uploads/dreamhost_procmail.gif"><!-- s9ymdb:95 --><img style="border: 0px none; float: left; padding-left: 5px; padding-right: 5px;" src="/uploads/dreamhost_procmail.serendipityThumb.gif" alt="" width="78" height="110" /></a></p>
<p>As noted, the setup requires a mail account and a shell account.  Also this scheme receives your email 3 times in order to accomplish the process:<br />
1. The Mail Account receives incoming email<br />
2. The Shell Account receives the mail forwarded from the Mail Account<br />
3. The Mail Account receives the mail after it has be processed by the Shell account.</p>
<p>To me this seems to put more strain on the servers than was on them before using the old setup.  But if this is what they prefer than so be it.</p>
<p><strong>Downsides</strong></p>
<p>This is obviously less than ideal, and will likely slow down the delivery of mail slightly, but in the end you will still be able to process email using spamassassin and procmail.</p>
<p>We still have to wait for Dreamhost to update the keyword filter.  Currently you would have to alter the subject or the body in order to process your mail.  As I said earlier, I would imagine that Dreamhost will update the filter very soon.</p>
<p><strong>Upside</strong></p>
<p>There is one upside to this system.  Using this method you could create a single shell account to handle all of your spamassassin work, including work for any user whether on your domain or not.  This would allow you to tweak global SA settings for all users.</p>
<p>This would be accomplished by setting procmail to forward the email back to which ever mail account sent it the email in the first place.  Theoretically you could filter and process any mail account this way, even accounts that are not hosted by dreamhost, as long as they can filter by message headers.  A feature that most cPanel accounts have accessible to them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/how-to-resurrect-procmail-and-spamassassin-on-dreamhost/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bug in BlackBerry Repeat Rule, MONTH_OF_YEAR Deincrements 1 Month</title>
		<link>http://www.krkeegan.com/bug-in-blackberry-repeat-rule-month_of_year-deincrements-1-month/</link>
		<comments>http://www.krkeegan.com/bug-in-blackberry-repeat-rule-month_of_year-deincrements-1-month/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 16:22:15 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=36</guid>
		<description><![CDATA[I have noticed a bug in javax.microedition.pim.RepeatRule, when I tried to set a an event to repeat every second sunday of may I would get an event that repeated every second sunday of april. I determined that this was being &#8230; <a href="http://www.krkeegan.com/bug-in-blackberry-repeat-rule-month_of_year-deincrements-1-month/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><!-- s9ymdb:94 --><img width="110" height="21" src="/uploads/Blackberry_logo.serendipityThumb.gif" style="border: 0px none ; float: left; padding-left: 5px; padding-right: 5px;" />I have noticed a bug in <font size="-1" face="arial,sans-serif" color="#000000">javax.microedition.pim.RepeatRule</font>, when I tried to set a an event to repeat every second sunday of may I would get an event that repeated every second sunday of april.  I determined that this was being caused by MONTH_OF_YEAR being deincremented by 1 month after the event was committed.  </p>
<p>I worked around the problem by setting the value one month forward.  However obviously, this does not work for december.  I tried increasing the value of the MONTH_OF_YEAR setting, however java balks at any unknown value.  Currently I am unable to set an event to occur on the second sunday in december.  If anyone figures out a work around I would be greatful. </p>
<p>RIM has recognized that this is a bug, but who knows when the bug will be fixed.  I attached a copy of the email I received from RIM:</p>
<p><span id="more-36"></span></p>
<pre id="line1">To: Kevin Keegan<br />Subject: Re: Bug in javax.microedition.pim.RepeatRule ;<br /> RQST00004960139<br />------------------------------------------<br /><br />Hello Kevin,<br /><br />Thank you for contacting BlackBerry Application Development<br />Support!<br /><br />I have been able to reproduce your issue with the RepeatRule <br />class and have forwarded the issue to our development team <br />for further investigation.<br /><br />Thank you for bringing this to our attention.<br /><br />Regards,<br /><br />Gordon<br />Software Engineering Consultant<br />Research In Motion Limited<br />Email: devsupport@rim.com <br />Web: www.blackberrydeveloper.com</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/bug-in-blackberry-repeat-rule-month_of_year-deincrements-1-month/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved Funambol Blackberry Plugin</title>
		<link>http://www.krkeegan.com/improved-funambol-blackberry-plugin/</link>
		<comments>http://www.krkeegan.com/improved-funambol-blackberry-plugin/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 00:39:15 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=35</guid>
		<description><![CDATA[As promised I made significant improvements to the Funambol Blackberry Client, while the improvements are geared towards better functionality with ScheduleWorld.com, they should benefit individuals who use other SyncML servers as well. The Improvements in 3.0.8.4 include: Ignore milliseconds in &#8230; <a href="http://www.krkeegan.com/improved-funambol-blackberry-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><!-- s9ymdb:93 --><img width="80" height="100" src="/uploads/logo1.serendipityThumb.png" style="border: 0px none ; float: left; padding-left: 5px; padding-right: 5px;" />
<p>As promised I made significant improvements to the Funambol Blackberry Client, while the improvements are geared towards better functionality with ScheduleWorld.com, they should benefit individuals who use other SyncML servers as well.</p>
<p>The Improvements in 3.0.8.4 include:</p>
<ul>
<li><code>Ignore milliseconds in date, fixes duplication on<br />
slowsync</code></li>
<li><code>Properly display entities such as quotes and ampersands</code></li>
<li><code>Allday events now show up on week and month view</code></li>
<li><code>Multiday Allday events are no longer short one day</code></li>
<li><code>All day events no longer duplicate on SlowSync</code></li>
<li><code> Accept basic ISO 8061 dates</code></li>
<li><code>Fixed error message that popped up whenever sending an email</code></li>
<li><code>Removed configuration section relating to email since Schedule World does not support email</code></li>
<li><code>Altered default settings in configuration to match Schedule World settings</code></li>
<li><code>Added AutoSync Feature - The client will query the server for changes every X hours.</code></li>
</ul>
<p><span id="more-35"></span></p>
<p>You can download a copy of Funambol-SW or view the source code at <a href="http://funambol-sw.krkeegan.com">Funambol Blackberry Plugin Schedule World Edition</a>.</p>
<p>I am not a great Java programer so most of these changes were pretty simple.  I would like to add support for tasks and possibly notes as well, but with my limited skill I may never get around to this.</p>
<p>Because of my limited time and skill with Java I am not offering a whole lot of support for this.  But if you are having issues feel free to post your issue on <a href="http://www.scheduleworld.com/jforum/forums/show/10.page">ScheduleWorld Forums</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/improved-funambol-blackberry-plugin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fix for Sending Email with Funambol and Schedule World</title>
		<link>http://www.krkeegan.com/fix-for-sending-email-with-funambol-and-schedule-world/</link>
		<comments>http://www.krkeegan.com/fix-for-sending-email-with-funambol-and-schedule-world/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 06:06:26 +0000</pubDate>
		<dc:creator>krkeegan</dc:creator>
				<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krkeegan.com/?p=33</guid>
		<description><![CDATA[Those of us without a Blackberry Enterprise Server cannot automatically synchronize our calendar and contacts with our PC without directly pluging the Blackberry directly into the PC with a USB cable. This is where Funambol and ScheduleWorld come in. ScheduleWorld &#8230; <a href="http://www.krkeegan.com/fix-for-sending-email-with-funambol-and-schedule-world/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><!-- s9ymdb:92 --><img width="55" height="110" style="border: 0px none ; float: left; padding-left: 5px; padding-right: 5px;" src="/uploads/8100.serendipityThumb.jpg" />
<p>Those of us without a Blackberry Enterprise Server cannot automatically synchronize our calendar and contacts with our PC without directly pluging the Blackberry directly into the PC with a USB cable.  This is where Funambol and ScheduleWorld come in.  ScheduleWorld is a SyncML server, basically a Calendar and Contacts server.  Funambol is an open source SyncML client for the blackberry.  By using both of these programs you can sync your calendar and contacts to your PC over the air, without directly connecting your Blackberry to your PC.  There are numerous tutorials for how to set this sytem up so I won&#8217;t waste your time discussing it here.</p>
<p>However, the Funambol ScheduleWorld setup has had one main issue for over a year.  The problem stems from  the fact that Funambol also allows for the synchronization of email while ScheduleWorld does not. Funambol allows users to unselect mail from synchronization.  But even with mail unchecked Funambol still does some check of the mail which causes an error.  Currently users will get the following error when sending an email:  </p>
<p><span class="postbody">
<pre>Sorry you can't synchronize &quot;mail&quot;, because the name of <br />the Remote Mail in the Funambol configuration panel <br />mismatches the corresponding name on the server.</pre>
<p></span><span class="postbody"></span></p>
</p>
<p>Users then had to select &quot;resend&quot; to force their email to send.  Needless to say the whole process was very annoying.  Funambol is an open source project so I decided to take a look.</p>
<p><span id="more-33"></span></p>
<p>Funambol is written entirely in Java, a language I have only moderate experience with.  After reading the code for about an hour I found a sendMessage function that looked like it could be causing the problem.  For some reason this function does not check if mail is configured for synchronization.  Therefore all I needed to add was a simple conditional statement to check for the syncMail setting.  The result is as follows:</p>
<div style="overflow: scroll; visibility: visible; width: 500px; height: 450px; position: relative; left: 0px; top: 0px;">
<pre>    public boolean sendMessage(Message msg) {<br />        try {<br />            <font color="#00cc00">if (Configuration.syncMail) {</font><br /><font color="#000066">                StaticDataHelper.log(&quot;Persistent store: &quot; + PersistentStore.getSynchObject());<br />                StaticDataHelper.log(&quot;Number of objects in storage: &quot; + String.valueOf(Memory.getPersistentStats().getObjectCount()));<br /><br />                msg.setStatus(Message.Status.TX_PENDING, 0);<br />                // Reset the draft flag in case it was a sent draft<br />                msg.setFlag(Message.Flag.SAVED_THEN_ORPHANED, false);<br /><br />                //bug fix 1113<br />                if (inSynchronize) {<br />                    StaticDataHelper.log(&quot;[INFO]sendMessages: another sync in progress...&quot;);<br />                    // FIXME: what to say to the user? Wait for the sync to stop?<br />                    return false;<br />                }<br /><br />                new Thread() {<br />                    public void run() {<br />                        inSynchronize = true;<br />                        try {<br />                            // Send the message<br />                            synchronizeMail();      // FIXME: synchronize(SYNC_MAIL)?<br />                            // Move it to SENT if successful<br />                            synchronizeMail();<br />                        }<br />                        //catch (Exception e) {<br />                        catch (Throwable e) {<br /><br />                            Log.error(&quot;[LOG]Exception in SyncClient.sendMessage: &quot; + e.toString());<br /><br />                            alert(e.getMessage());<br /><br />                            // TODO: set the message status to TX_ERROR<br /><br />                        }<br />                        finally {<br />                            inSynchronize = false;<br />                        }<br />                    }<br />                }.start();</font><br />            <font color="#00ff00">}</font><br />        }<br />        finally {<br />            /*<br />             * FIXME: check if this statement<br />             * is reached before the thread<br />             * above is started<br />             */<br />            setMailListener();<br />        }<br />        return false;<br />    }</pre>
</div>
<p>I added the lines in green and indented the lines in blue.</p>
<p>I tested this solution using the Blackberry simulator included with JDE and it appears to work perfectly.  However, you can never be sure how well a simulator really emulates the real product.  Currently I am just waiting for a Signature Key, that I purchased from Blackberry for $20.  Once I receive this key I will be able to sign the code and install it on my Blackberry.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.krkeegan.com/fix-for-sending-email-with-funambol-and-schedule-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
