<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Dariel Marlow]]></title>
  <link href="http://dmarlow.github.io/atom.xml" rel="self"/>
  <link href="http://dmarlow.github.io/"/>
  <updated>2014-11-05T19:36:27+00:00</updated>
  <id>http://dmarlow.github.io/</id>
  <author>
    <name><![CDATA[]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  
  <entry>
    <title type="html"><![CDATA[SMSCMD Gets a Redesign]]></title>
    <link href="http://dmarlow.github.io/2014/11/new-site-redesign.html"/>
    <updated>2014-11-05T00:00:00+00:00</updated>
    <id>http://dmarlow.github.io/2014/11/new-site-redesign</id>
    <content type="html"><![CDATA[<p>I&#39;m pleased to announce that <a href="http://www.getsmscmd.com">SMSCMD</a> gets a new, fresh look. We also decided to go with a new domain, getsmscmd.com. The old domain is still active and available at smscmd.net. I think it looks a million time better than before. Props to <a href="https://twitter.com/joncalmus">joncalmus</a>.</p>

<p>- Dariel Marlow</p>
]]></content>
  </entry>
  
  
  
  <entry>
    <title type="html"><![CDATA[Moved to a New Blog]]></title>
    <link href="http://dmarlow.github.io/2014/07/moved-to-a-new-blog.html"/>
    <updated>2014-07-22T00:00:00+00:00</updated>
    <id>http://dmarlow.github.io/2014/07/moved-to-a-new-blog</id>
    <content type="html"><![CDATA[<p>Well, that didn&#39;t last very long. The moment I tried adding a Gist like so on my old blog,</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">&lt;script src=&quot;https://gist.github.com/dmarlow/2ea49c00ebc2e4e8e951.js&quot;&gt;&lt;/script&gt;
</code></pre></div>
<p>and I wasn&#39;t able to upload, was the moment I realized I needed something a little more &quot;fresh&quot;.</p>

<p>And now here we are. Migration was painless since I only had three articles. I wish hosting images were a bit easier, but I&#39;m satisfied. I basically copied David Ebbo&#39;s site (after running into his <a href="http://blog.davidebbo.com/2014/01/moving-to-github-pages.html">article</a> on moving to GitHub Pages).</p>

<p>- Dariel Marlow</p>
]]></content>
  </entry>
  
  
  
  <entry>
    <title type="html"><![CDATA[Creating a Simple SMS App - HackerNews (hn)]]></title>
    <link href="http://dmarlow.github.io/2014/07/creating-a-simple-sms-app-hackernews-hn.html"/>
    <updated>2014-07-21T00:00:00+00:00</updated>
    <id>http://dmarlow.github.io/2014/07/creating-a-simple-sms-app-hackernews-hn</id>
    <content type="html"><![CDATA[<p>As I was sitting around I wondered what the top post in HackerNews was. Sure, I could have installed one of hundreds, or thousands, of apps or news readers. I could have even fired up my mobile browser or navigated via a bookmark. However, I wanted to see what it&#39;d take to create an SMS wrapper around HN. Why? More like, why not?!</p>

<h2>Here it Goes</h2>

<p>First things first, I create an SMS app on <a href="http://www.smscmd.net/">SMSCMD</a> like <a href="/2014/07/sms-enabling-your-app-or-device.html">this blog post</a> describes. I basically support these types of commands:</p>

<ul>
<li>hn top [1-3] - ex: <em>hn top</em> or <em>hn top 2</em></li>
<li>hn new [1-3] - ex: <em>hn new</em> or <em>hn new 3</em></li>
</ul>

<p>If the count is omitted, only one result is returned. Try it now, send a HackerNews command (<em>hn top</em>) to <em>+13109064555</em>.</p>

<p>The body parsing and HN news fetching is basically all there is. Here&#39;s my regular expression to parse the command (I actually don&#39;t receive the text &quot;hn&quot; as that&#39;s the SMS app name and is forwarded to that handler):</p>

<script src="https://gist.github.com/dmarlow/2ea49c00ebc2e4e8e951.js"></script>

<p>I use <a href="https://github.com/neilkennedy/HackerSharp/">HackerSharp</a> to fetch the HackerNews articles. This is what my MQTT message received handler looks like:</p>

<script src="https://gist.github.com/dmarlow/9b584475b025c2bc277a.js"></script>

<p>That&#39;s all there is to it. The only special sauce there is shortening URLs so I don&#39;t waste precious SMS space and <em>&quot;x.Title.Head(30)&quot;</em> (it gets the first 30 characters and adds ellipsis if needed). Here&#39;s what I got when I sent <em>hn top</em> when writing this.</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">MiniLock - File encryption...
http://goo.gl/7XRRKB
76 pts - poolpool | 25 comments
</code></pre></div>
<p>- Dariel Marlow</p>
]]></content>
  </entry>
  
  
  
  <entry>
    <title type="html"><![CDATA[Handling a Breakup]]></title>
    <link href="http://dmarlow.github.io/2014/07/handling-a-breakup.html"/>
    <updated>2014-07-18T00:00:00+00:00</updated>
    <id>http://dmarlow.github.io/2014/07/handling-a-breakup</id>
    <content type="html"><![CDATA[<p>Let&#39;s face it, everything must come to an end. Even that MQTT connection of yours will eventually <del>break up with you</del> disconnect. In the world of MQTT, the client connects to the server. So, in the event of an inevitable disconnect, what should your client do? Grab some ice-cream and hunker down in bed waiting for the server to come crawling back? No, it&#39;s got to go out into the world and figure things out. So, how should it do it?</p>

<h2>The Solution</h2>

<p>The answer is: well, it depends. What sort of client are you? One who is power/CPU constrained or not? One who crumbles at the sight of a disconnection? Here are some strategies for handling disconnection.</p>

<h3>Naive Reconnect</h3>

<p>We could do something like this:</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">Create client
Register callbacks

TryConnect:
  Loop forever
    If not connected
      Connect
    Sleep X

TryConnect() // Attempt connection
</code></pre></div>
<p>That loop forever step could be a in its own thread, but there are still issues with this. First, we will check every X time interval and needlessly spin the CPU and use resources. Even in a power/CPU rich environment, this isn&#39;t the most ideal.</p>

<h3>Self-Aware Reconnect</h3>

<p>After some introspection and self-awareness, we reach the conclusion that we can do better. How about this:</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">Create client
Register callbacks

OnDisconnect Callback:
  TryConnect()

TryConnect:
  Loop while not connected
    Connect
    Sleep X

TryConnect() // Attempt connection
</code></pre></div>
<p>That&#39;s slightly better. We don&#39;t needlessly check unless we have to. We only loop when we&#39;re trying to connect. We use the disconnect callback handler to worry about connecting. This is essentially what&#39;s in the Sms2Mqtt GitHub repo.</p>

<h3>Zenful</h3>

<p>If we&#39;re a power/CPU critical, and packet conscious, app/device, we may need to take better care of how we do things. Spinning endlessly while trying to connect is a noble goal, but we can kill ourselves trying. We should probably introduce some sort of exponential back-off. This allows us to try to connect, and if the server isn&#39;t answering our calls, we don&#39;t want to seem overly eager, or desperate. It might give the wrong impression and we&#39;ll just get exhausted.</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">Create client
Register callbacks

OnDisconnect Callback:
  TryConnect()

TryConnect:
  Interval = X
  Loop while not connected
    Interval = Min(Interval * 2, Limit)
    Connect
    Sleep Interval

TryConnect() // Attempt connection
</code></pre></div>
<p>I think this gets me to a happy place. My client spends CPU cycles more efficiently and takes a break when it can&#39;t connect. I think a perfectly valid interval to begin with is 1 second. From there, it jumps up to 2, 4, 8, 16, 32, then 64 seconds (where I&#39;d place the limit).</p>

<p>Until next time,</p>

<p>- Dariel Marlow</p>
]]></content>
  </entry>
  
  
  
  <entry>
    <title type="html"><![CDATA[SMS Enabling Your App/Device]]></title>
    <link href="http://dmarlow.github.io/2014/07/sms-enabling-your-app-or-device.html"/>
    <updated>2014-07-17T00:00:00+00:00</updated>
    <id>http://dmarlow.github.io/2014/07/sms-enabling-your-app-or-device</id>
    <content type="html"><![CDATA[<p>I recently wrote a small app for my brother-in-law. It&#39;s a simple console app that drives selenium to automate a web browser. Great, it works and it works pretty well. It sits there day and night doing its thing. Soon thereafter, my brother in law asked me to tweak it, to turn it off, to pause it or change some behavior. After thinking about this, I realized there must be a better way! I didn&#39;t want to write an app, wait for it to be published, then get him to install it. Let alone writing multiple versions to put into multiple app stores should he change phones. The next alternative was to make a web interface for it. I thought that it seemed a bit heavy. Plus, I would have to open a firewall port and add security. It just didn&#39;t feel right. Then, I realized that he already has something that can communicate with the app, his phone. Why not send a text message and control the app directly? So that&#39;s exactly what I decided to build and make available to others as well.</p>

<h2>Introducing SMSCMD</h2>

<p><a href="http://www.smscmd.net/">SMSCMD</a> allows you to control your app (or Arduino/Raspberry Pi/Gadgeteer/etc. device) remotely via SMS. It&#39;s super easy to setup. There&#39;s a free version that&#39;s more than capable of handling simple things that don&#39;t need attention ever day.</p>

<h2>How it Works</h2>

<p>It&#39;s basically an MQTT server that can take requests via SMS. I use Twilio to capture SMS messages via HTTP, then I dump those into MQTT.</p>

<p><img src="/images/2014-07/1_visio_lg.png" alt="image"></p>

<h2>Getting Started</h2>

<p>Still with me? Great! First, you need to create an SMS app on SMSCMD to begin the process. </p>

<p>Names must be unique. The SMS Password can be left blank. This is an added level of control most users probably won&#39;t need or use. Specify your MQTT username and password. This is what you&#39;ll use to connect to the MQTT server.</p>

<p><img src="/images/2014-07/1_add_lg.png" alt="image"></p>

<p>There&#39;s a section that shows the connection information:
Server: q.smscmd.net
Port: 1883
Client ID: weather-app
Use the username and password specified
Sub topic: weather-app/cmds
Pub topic: weather-app/reply</p>

<p>When you click on the connection example, you&#39;re shown this:</p>

<script src="https://gist.github.com/dmarlow/4784d2080db9c7a51590.js"></script>

<p>It&#39;s basically a &quot;ready to copy &amp; paste&quot; python version. A C# version is available on <a href="https://github.com/dmarlow/Sms2Mqtt/blob/master/src/Sms2Mqtt/Program.cs">GitHub</a>.</p>

<p>Finally, there&#39;s a section to configure what you want your app/device to receive. Depending on your plan, you can choose only the phone numbers that are allowed to send commands. You can test things out before hitting &quot;Add&quot; as well.</p>

<p><img src="/images/2014-07/1_add2_lg.png" alt="image"></p>

<h2>Responding to a Command</h2>

<p>You&#39;ll notice in both examples (Python and C#) that there&#39;s something in the handler for when command, or message, arrives to reply. The format is important. You must reply and specify the command ID you received. This is to ensure things are sent back to the proper source. Both examples are basically an echo application; it responds back the same thing it received.</p>

<script src="https://gist.github.com/dmarlow/fe4bdc40cfb36c178048.js"></script>

<p>The reply should be send to &quot;<command name>/reply&quot; topic. The format must be an object with the command ID and body properties. { &quot;cmdId&quot;: <whatever was sent>, &quot;body&quot;: <whatever you wish to send back to the sender via SMS> }.</p>

<p>That JSON object needs to be serialized and encoded into bytes (depending on your MQTT client). In C# it looks like this:</p>

<script src="https://gist.github.com/dmarlow/25b4ae6b93b9eac45d66.js"></script>

<p><img src="/images/2014-07/1_home_lg.png" alt="image"></p>

<p>I&#39;ll leave it up to you to find out what happens when you send something the site doesn&#39;t understand.</p>

<p>Thanks for reading!</p>

<p>- Dariel Marlow</p>
]]></content>
  </entry>
  
  
</feed>
