<?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>bits4life &#187; perl</title>
	<atom:link href="http://blog.export.be/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.export.be</link>
	<description>Bits and bytes for your daily life.</description>
	<lastBuildDate>Thu, 12 Nov 2009 10:55:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use misterhouse to send SMS messages to your mobile on events.</title>
		<link>http://blog.export.be/2009/11/use-misterhouse-to-send-sms-messages-to-your-mobile-on-events/</link>
		<comments>http://blog.export.be/2009/11/use-misterhouse-to-send-sms-messages-to-your-mobile-on-events/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 12:58:32 +0000</pubDate>
		<dc:creator>nixo</dc:creator>
				<category><![CDATA[misterhouse]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://blog.export.be/?p=252</guid>
		<description><![CDATA[I am using misterhouse to drive my home automation system in my house. One of the things I like is to receive alerts on certain events. For example when it starts raining and one of the windows is left open I like to know.  A good way to receive alerts is via SMS messages on [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="voipbuster" src="http://www.voipbuster.com/images/logo.gif" alt="" width="86" height="52" />I am using misterhouse to drive my home automation system in my house. One of the things I like is to receive alerts on certain events. For example when it starts raining and one of the windows is left open I like to know.  A good way to receive alerts is via SMS messages on my mobile phone.  I started coding so that misterhouse can sent SMS alerts.  In the misterhouse code there was already some code to use a service at www.smsboy.com Because I am using voipbuster for my VOIP needs I changed the code for that.<span id="more-252"></span> Below is the code that creates an Item to use for sending SMS messages .</p>
<p class="textbox">use strict;<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
# SMS module for Misterhouse<br />
# Uses your voipbuster account http://voipbuster.com to send an SMS message to your mobile.<br />
# Originally written by Stuart Grimshaw &lt;stuart@smgsystems.co.uk&gt;<br />
# Changed by Nico Lembrechts for use with voipbuster.com &lt;nicoatyow@gmail.com&gt; http://yow.be<br />
#<br />
# (17/04/2009)<br />
#<br />
# It&#8217;s trivially simple to use, just add the .pm file to either your code<br />
# directory, or the Misterhouse lib directory. Until the module is integrated<br />
# into the next release (and until you upgrade to it) you need to add the<br />
# line:<br />
#<br />
#       use voipbuster_SMS_Item;<br />
#<br />
# somewhere in your code.<br />
#<br />
# To create the object use:<br />
#<br />
#       new voipbuster_SMS_Item(&lt;username&gt;, &lt;password&gt;, &lt;from_telephone_number&gt;, &lt;to_telephone_number&gt;);<br />
#<br />
#       $SMS_voipbuster = new voipbuster_SMS_Item(&#8220;username&#8221;, &#8220;password&#8221;, &#8220;+32161234567&#8243;, &#8220;+324961234567&#8243;);<br />
#<br />
# and to send a message use the line:<br />
#<br />
#       $SMS_voipbuster-&gt;send(&#8220;Window left open and it is raining now.&#8221;);<br />
#<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
package voipbuster_SMS_Item;<br />
use LWP::UserAgent;<br />
my $smsurl = &#8220;https://myaccount.voipbuster.com/clx/sendsms.php?&#8221;;<br />
sub new {<br />
my($class)=shift(@_);<br />
my($self) = {};<br />
$$self{username} = shift(@_);<br />
$$self{password} = shift(@_);<br />
$$self{from} = shift(@_);<br />
$$self{to} = shift(@_);<br />
bless $self, $class;<br />
return $self;<br />
}<br />
sub send {<br />
my($self, $message) = @_;<br />
my $ua = new LWP::UserAgent;<br />
my $req = $smsurl.(&#8220;username=$$self{username}&amp;password=$$self{password}&amp;from=$$self{from}&amp;to=$$self{to}&amp;text=$message &#8212; &#8220;);<br />
my $res = $ua-&gt;get($req);<br />
die &#8220;Error at $req\n &#8220;, $res-&gt;status_line, &#8220;\n Aborting&#8221;<br />
unless $res-&gt;is_success;<br />
}<br />
sub set {<br />
my($self, $voip_user, $voip_pass, $voip_from, $voip_to) = @_;<br />
$$self{username}=$voip_user;<br />
$$self{password}=$voip_pass;<br />
$$self{from}=$voip_from;<br />
$$self{to}=$voip_from;<br />
}</p>
<p>This code is doing the actual work.</p>
<p>In the following code I create an Item</p>
<p class="textbox">use voipbuster_SMS_Item;<br />
# To create the object use:<br />
#<br />
$SMS_Nico = new voipbuster_SMS_Item(&#8220;nicoatyow&#8221;, &#8220;********&#8221;, &#8220;+32496*********&#8221;, &#8220;+324**********&#8221;);<br />
# and to send a message use the line:<br />
#<br />
#$SMS_Nico-&gt;send(&#8220;Mum called your home at 13:15&#8243;) if $New_Minute;</p>
<p>Once the item is created you can use it in all your misterhouse code files. For example with my rain detector :</p>
<p class="textbox">
<p>if ($state = state_changed $rainsensor){<br />
print_log &#8220;Rainsensor is now $state&#8221;;<br />
$SMS_Nico-&gt;send(&#8220;ALARM !! It&#8217;s raining and a window left open. &#8220;) if ($state eq ON) and state $window_open eq ON;<br />
}</p>
<p><img class="alignleft" title="voipbuster" src="http://www.voipbuster.com/images/logo.gif" alt="" width="157" height="96" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.export.be/2009/11/use-misterhouse-to-send-sms-messages-to-your-mobile-on-events/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
