<?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; soical network</title>
	<atom:link href="http://matthewmorey.com/tag/soical-network/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>
	</channel>
</rss>
