<?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>Matt(hew) Morey &#187; iobridge</title>
	<atom:link href="http://matthewmorey.com/tag/iobridge/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewmorey.com</link>
	<description>...an engineer who surfs, travels, and pretends to know the meaning of life.</description>
	<lastBuildDate>Fri, 17 Jul 2009 22:56:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Code (2 of 2) for @MattsOffice</title>
		<link>http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/</link>
		<comments>http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 21:04:55 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[iobridge]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[soical network]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/?p=164</guid>
		<description><![CDATA[As promised in my earlier post and the follow up post, here is some sample code I&#8217;m using to respond to @MattsOffice mentions. With a version of this code and a Cron job I can respond to any number of specific&#160;commands. This code only illustrates responding to one command, &#8220;light&#8221;, but could easily be extended [...]]]></description>
			<content:encoded><![CDATA[<p>As promised in my <a href="http://matthewmorey.com/projects/introducing-mattsoffice/">earlier post</a>  and the <a href="http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/">follow up post</a>, here is some sample code I&#8217;m using to respond to <a href="http://twitter.com/#search?q=@MattsOffice">@MattsOffice mentions</a>. With a version of this code and a Cron job I can respond to any number of specific&nbsp;commands.</p>
<p>This code only illustrates responding to one command, &#8220;light&#8221;, but could easily be extended as is done with&nbsp;<a href="http://twitter.com/MattsOffice">@MattsOffice</a>.</p>
<pre name="code" class="php">
&lt;?php
include_once('class.twitter.php');// http://code.google.com/p/php-twitter/

$ioBridgeJSONFeedURL = 'http://www.iobridge.com/api/feed/key=XXXXXXXXXXXXXXXXXXXXXX';
$buzzerOnURL = 'http://yourserver.com/iobridge-proxy.php?widget=buzzeron';
$buzzerOffURL = 'http://yourserver.com/iobridge-proxy.php?widget=buzzeroff';

$t = new twitter;
$t-&gt;username = 'twitter_username';
$t-&gt;password = 'twitter_password';

// Read the ID of the last reply
$myFile = "lastreply.txt";
$fileHandle = fopen($myFile, 'r');
$lastReplyID = fgets($fileHandle);
fclose($fileHandle);

// Get the latest unanwsered replies
$data = $t-&gt;getReplies('','',$lastReplyID);

$counter = 1;
if(!empty($data)){
&nbsp;&nbsp;&nbsp;&nbsp;foreach($data as $tweet) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!empty($tweet-&gt;user-&gt;id)){

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Check for valid command
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(stripos($tweet-&gt;text, "light"){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// retrieve data from ioBridge.com
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curl_handle=curl_init();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_URL,$ioBridgeJSONFeedURL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ioBridgeResultsObject = curl_exec($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ioBridgeResultsObject = json_decode($ioBridgeResultsObject);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($curl_handle);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$lightResults = $ioBridgeResultsObject-&gt;{'module'}-&gt;{'channels'}[2]-&gt;{'AnalogInput'};
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updateText = ' @' . $tweet-&gt;user-&gt;screen_name . ' Ambient Light = ' . $lightResults;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If no valid command was found reply with what commands are valid
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$messageText = ' Valid commands are: light, bright, dark, temp, hot, cold, lcd, and/or view';
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updateText = ' @' . $tweet-&gt;user-&gt;screen_name . $messageText;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Send update
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updateData = $t-&gt;update($updateText, $tweet-&gt;id);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Update text file with ID of last reply (first reply of loop)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($counter === 1){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$myFile = "lastreply.txt";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$fileHandle = fopen($myFile, 'w') or die("can't open file");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fwrite($fileHandle, $tweet-&gt;id);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fclose($fileHandle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$counter++;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Sound Buzzer (serves as an audible alert when someone pings @MattsOffice)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curl_handle=curl_init();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_URL,$buzzerOnURL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,5);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$results = curl_exec($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_URL,$buzzerOffURL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$results = curl_exec($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}// if (!empty($tweet-&gt;user-&gt;id)){
&nbsp;&nbsp;&nbsp;&nbsp;}// foreach($data as $tweet) {
}// if(!empty($data)){
else {
&nbsp;&nbsp;&nbsp;&nbsp;echo 'All replies have been responded to.';
}

print '&lt;pre&gt;Twitter says(list of @mentions):'; print_r($data); print '&lt;/pre&gt;';
print '&lt;pre&gt;Twitter says(response to status update):'; print_r($updateData); print '&lt;/pre&gt;';
?&gt;
</pre>
<p>In order to keep track of what @MattsOffice mentions have already been answered, the ID of the last successful reply is saved to a plain text file. A database could also be used but the text file method is much simpler even if it doesn&#8217;t allow&nbsp;logging.</p>
<p>In order for this code to work your server needs the <a href="http://www.iobridge.net/wiki/api/php-widget-control-api">ioBridge PHP Widge Control API</a> and <a href="http://code.google.com/p/php-twitter/">this </a>Twitter&nbsp;library.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Code (1 of 2) for @MattsOffice</title>
		<link>http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/</link>
		<comments>http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 00:59:38 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[iobridge]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[soical network]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/?p=143</guid>
		<description><![CDATA[As promised in my earlier post here is the code that I&#8217;m using to auto-update the MattsOffice Twitter account. With this code and a Cron job I can update the light and temperature conditions of my office automatically at whatever time interval I&#160;choose. ioBridge.com does offer &#8220;Actions&#8221; but none of the current actions allow the [...]]]></description>
			<content:encoded><![CDATA[<p>As promised in my <a href="http://matthewmorey.com/projects/introducing-mattsoffice/">earlier post</a> here is the code that I&#8217;m using to auto-update the <a href="http://twitter.com/MattsOffice">MattsOffice Twitter account</a>. With this code and a Cron job I can update the light and temperature conditions of my office automatically at whatever time interval I&nbsp;choose.</p>
<p><a href="http://www.iobridge.com">ioBridge.com</a> does offer &#8220;Actions&#8221; but none of the current actions allow the trigger to be time based. Once they introduce time as a trigger this code will no longer be&nbsp;needed.</p>
<pre name="code" class="php">
&lt;?php
include_once('class.twitter.php');//http://code.google.com/p/php-twitter/

$ioBridgeJSONFeedURL = 'http://www.iobridge.com/api/feed/key=XXXXXXXXXXXXXXXXXX';

$t = new twitter;
$t-&gt;username = 'twitter_username';
$t-&gt;password = 'twitter_pwd';

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$ioBridgeJSONFeedURL);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$ioBridgeResultsObject = curl_exec($curl_handle);
$ioBridgeResultsObject = json_decode($ioBridgeResultsObject);
curl_close($curl_handle);

if (empty($ioBridgeResultsObject)){
    print "Sorry, something went wrong.";
}
else{
    $data = $t-&gt;update('Temperature = '. $ioBridgeResultsObject-&gt;{'module'}-&gt;{'channels'}[0]-&gt;{'AnalogInput'} . '°F / Ambient Light = ' . $ioBridgeResultsObject-&gt;{'module'}-&gt;{'channels'}[2]-&gt;{'AnalogInput'});
    print '&lt;pre&gt;Twitter says: '; print_r($data); print '&lt;/pre&gt;';
}
?&gt;
</pre>
<p>In a few days I will post the code that parses my Twitter account for <a href="http://twitter.com/#search?q=@MattsOffice">@MattsOffice mentions</a> and responds to them&nbsp;accordingly.</p>
<p>Update: 07/17/09<br />
Second <a href="http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/">post</a> is up with more&nbsp;code </p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Introducing http://twitter.com/MattsOffice</title>
		<link>http://matthewmorey.com/projects/introducing-mattsoffice/</link>
		<comments>http://matthewmorey.com/projects/introducing-mattsoffice/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 02:19:05 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[iobridge]]></category>
		<category><![CDATA[social network]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/?p=104</guid>
		<description><![CDATA[A couple months back I came across IOBridge&#8217;s IO-204 and instantly knew I needed one. I went ahead and bought the device as well as several of their accessory boards. Once everything arrived I started tinkering and was amazed with how easy it was at connecting DIY projects to the&#160;web. Now if only I had [...]]]></description>
			<content:encoded><![CDATA[<p>A couple months back I came across <a href="http://www.iobridge.com/">IOBridge&#8217;s IO-204</a> and instantly knew I needed one. I went ahead and bought the device as well as several of their accessory boards. Once everything arrived I started tinkering and was amazed with how easy it was at connecting DIY projects to the&nbsp;web.</p>
<p>Now if only I had a project to use it&nbsp;with.</p>
<p>Lucky for me one of my graduate courses on computer communications requires a research paper on a &#8220;communications based&#8221; project.  Well actually maybe I&#8217;m not so lucky, who likes to write research papers? The title of the paper is &#8220;Feasibility Study of Home Automation via Social Networks&#8221; and I hope to have it finished by August. Once it is done I will post it&nbsp;here.</p>
<div id="attachment_113" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-113" title="System Diagram" src="http://matthewmorey.com/wp-content/uploads/2009/07/systemdiagram-300x143.jpg" alt="System Diagram" width="300" height="143" /><p class="wp-caption-text">System&nbsp;Diagram</p></div>
<p>The project was inspired by many of the current Twittering household&nbsp;devices.</p>
<ul>
<li><a href="http://twitter.com/mytoaster">http://twitter.com/mytoaster</a></li>
<li><a href="http://twitter.com/EDogFeeder">http://twitter.com/EDogFeeder</a></li>
<li><a href="http://twitter.com/PiMPY3WASH">http://twitter.com/PiMPY3WASH</a></li>
</ul>
<p>The one thing lacking in most of these devices was 2-way communication between Twitter and the device. In all of the examples I could find the device is sending an update to Twitter but is never performing an action based on a Twitter&nbsp;message.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/PVm1VKB43ww&#038;hl=en&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PVm1VKB43ww&#038;hl=en&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>With <a href="http://twitter.com/MattsOffice">http://twitter.com/MattsOffice</a> you can send a command by placing a keyword in a @reply message. Valid keywords are &#8220;light&#8221;, &#8220;bright&#8221;, &#8220;dark&#8221;, &#8220;temp&#8221;, &#8220;hot&#8221;, &#8220;cold&#8221;, &#8220;lcd&#8221;, and &#8220;view&#8221;. For example, to retrieve the temperature of my office I just need to update <a href="http://twitter.com/xzolian">my Twitter status</a> with a simple question like &#8220;@MattsOffice What is the temperature?&#8221;. Here are some more&nbsp;examples:</p>
<blockquote><p>&#8220;@MattsOffice How cold is it?&#8221;&thinsp;&#8211;&thinsp;replies with the current temperature<br />
&#8220;@MattsOffice How bright is it?&#8221;&thinsp;&#8211;&thinsp;replies with the current ambient light reading<br />
&#8220;@MattsOffice lcd test message&#8221;&thinsp;&#8211;&thinsp;outputs &#8220;test message&#8221; to my LCD sitting on my desk<br />
&#8220;@MattsOffice What is the view from your office look like?&#8221;&thinsp;&#8211;&thinsp;uploads a picture taken from my office window to&nbsp;<a href="http://twitpic.com">TwitPic.com</a></p></blockquote>
<p>Multiple commands can be posted&nbsp;together:</p>
<blockquote><p>&#8220;@MattsOffice temp bright view&#8221;&thinsp;&#8211;&thinsp;replies with the current temperature, brightness, and post a&nbsp;picture</p></blockquote>
<p>I can also turn off or on my desk light by updating my status with &#8220;@MattsOffice light on&#8221; or &#8220;@MattsOffice light off&#8221;. To prevent my light from turning off when I don&#8217;t want it to be off I have disable this feature for everyone but myself (i.e. it only works if @xzolian ask to turn the light on or&nbsp;off).</p>
<p>Go <a href="http://twitter.com/MattsOffice">try it out</a>! Let me know if there are any bugs. Look for a follow up post on how I made all this work and some example&nbsp;code.</p>
<p>Update: 07/15/2009<br />
The first part of the code can be found&nbsp;<a href="http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/">here</a>.</p>
<p>Update: 07/17/09<br />
Second <a href="http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/">post</a> is up with more code. This post was updated with Youtube&nbsp;video. </p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/introducing-mattsoffice/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
	</channel>
</rss>
