<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Brian on Medium]]></title>
        <description><![CDATA[Stories by Brian on Medium]]></description>
        <link>https://medium.com/@_i3d?source=rss-b4b74e67ec30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NAhoKBsmYzHdjgAZ.jpeg</url>
            <title>Stories by Brian on Medium</title>
            <link>https://medium.com/@_i3d?source=rss-b4b74e67ec30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:54:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_i3d/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker and compiled code]]></title>
            <link>https://medium.com/@_i3d/docker-and-compiled-code-613a65624dd4?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/613a65624dd4</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Sun, 11 Sep 2016 07:21:42 GMT</pubDate>
            <atom:updated>2016-09-12T20:21:39.355Z</atom:updated>
            <content:encoded><![CDATA[<h4>Developing compiled code in a synchronized, isolated, version-controlled build environment with Docker</h4><h3>Interpreted Code</h3><p>Most examples I’ve come across involving Docker demonstrate how to build and run web applications. Since web apps are often written in interpreted languages (e.g. Ruby, Python, JavaScript), there is no traditional “build” step to compile any code. The code you write is the code you run. You don’t need to worry about development environments, because they are inherently the same as the production environment.</p><h4>Web app development with Docker</h4><ol><li>Write app code (js, py, rb).</li><li>Build an image by copying code into a pre-made base image.</li><li>Add other missing pieces (e.g. database, web server).</li><li>Ship it and repeat.</li></ol><p>Any Dockerfile for this type of project is versioned along side the code. Code merges mean everyone gets the new environment. The development environment is the same thing shipped to production. Everything is gravy.</p><h3>Compiled Code</h3><p>Compiled code is different, in that it has an additional build step between the above step 1 and step 2, one that produce binaries from source code. Such an app requires an operating system and a toolchain to compile, but very little beyond the executable binary to run.</p><p>This is of course where the Docker web app paradigm breaks down, because the build environment is <strong>not</strong> the same as the runtime environment.</p><p>Go is one such compiled language, and the examples I have seen for building or distributing Go code seem to follow either a web app pattern or a minimalist pattern:</p><h4>Web app style</h4><ol><li>Write app code (go).</li><li>Build an image by copying code into a pre-made base image. <br>a) <em>Compile code during image build with a RUN command.</em></li><li>Add other missing pieces (e.g. database, web server).</li><li>Ship it and repeat.</li></ol><p>The problem here is that the resulting image in production is an entire build environment, including operating system, toolchain, and source code. Does your 1 MB app really need a 500 MB image to run? Or perhaps more importantly, what if your source code is proprietary or distribution is restricted by law? Just run another step to delete it?</p><h4>Minimalist approach</h4><ol><li>Write app code (go).</li><li><em>Compile app code on host machine.</em></li><li>Build an image by copying binaries into a <strong>bare-bones</strong> base image.</li><li>Add other missing pieces (e.g. database, web server).</li><li>Ship it and repeat.</li></ol><p>This approach is much more sane, in that we’ve separated the development environment from the runtime environment. Except, the approach totally ignores the host of new problems it introduces:</p><ul><li><strong>Synchronization of dependencies<br></strong>If the environment is distributed (per developer’s computer), then dependencies need to be kept in sync and versioned. One developer cannot be compiling with Go 1.5 while another uses Go 1.7. You could solve this by making everyone work on the same machine…</li><li><strong>Isolation of environments</strong><br>…but, if the environment is shared, changes to the environment will be propagated to all developers during development before code has been merged, which can lead to conflicts or unexpected build failures. There’s also the potential for a sysadmin hurdle, where developers need to ask the sysadmin to install packages for them.</li><li><strong>Environment versions</strong><br>Even if you manage to <em>synchronize dependencies</em> and <em>isolate development environments</em>, how will the development environment itself be versioned? The environment changes over time just as the code does. Will developers be able to work on old releases quickly and easily to run, debug, and patch bugs, long after the release’s dependencies have changed? Version 1.0 might be built with Go version 1.6 while Version 3.0 is several years down the road and building with an incompatible Go 2.0.</li></ul><p>I’ve developed an approach that aims to keep developers in sync with one another, while giving them with the isolation and autonomy needed to rapidly prototype and develop new code, all while version controlling the build environment so that a <em>git checkout version-1.0; build </em>is the only step necessary to leverage the old build environment and compile.</p><h4>Containerizing your build before your app</h4><p>In order to isolate environments, each developer will need to compile code within a Docker container, which is based upon a Dockerfile that is version controlled with the source code.</p><p>Developers are free to add or modify dependencies within their local copy of the environment, even if the host machine is shared. Eventually, those changes will be merged to the the master branch for other developers to use, and as long as developers are launching builds on an image from their their commit point, all development environments are kept in sync.</p><p>The tricky part is of course to make it seamless for the developer to run a container from the right image without any effort, no matter the revision (going back or forward in commit history). The basic idea is to:</p><ol><li>Checkout a commit</li><li>Pull or Build a docker image</li><li>Compile</li><li>If changes are made to the Dockerfile environment, restart from 2</li></ol><p>Before you compile, hash your Dockerfile, and try to pull an image tagged with the hash of your Dockerfile from the Docker hub.</p><pre><strong>you@host$ </strong>DOCKERFILE_HASH=($(sha256sum dockerfiles/Dockerfile))<strong><br>you@host$</strong> docker pull myproj:$DOCKERFILE_HASH</pre><p>If it doesn’t exist on the hub, build the image yourself and tag it with the hash.</p><pre><strong>you@host$</strong> docker build -t myproj:$DOCKERFILE_HASH dockerfiles/</pre><p>Invoke a container that mounts your source code, sets up a user and permissions, and sets the working directory to the root of your source code. Make sure to have the build artifacts be written to a volume accessible by the host machine as well. Compile.</p><pre><strong>you@host$</strong> docker run -it \<br>              -u $(id -u):$(id -g) \<br>              -v $GIT_ROOT:/mnt/src \<br>              -w /mnt/src \<br>              foo/first-build \<br>              /bin/bash<br><strong>I have no name!@1a61b316c4de$</strong> make</pre><p>If the compilation succeeds, your tests pass, and you’re ready to merge back into master, push your image to the hub and merge.</p><pre><strong>you@host$</strong> docker push myrepo:$DOCKERFILE_HASH<br><strong>you@host$ </strong>git merge feature/foo</pre><p>Now, repeat! (Wrapper scripts can help to automate the <em>hash</em> and <em>pull/build</em> steps, while the <em>push</em> step should be done by an automated CI system like Jenkins).</p><p>You should now be compiling your code on an image built by your CI system pulled from the hub. The image will be an identical copy for everyone in the project. If a new package is installed, the CI system should build, test, and push a new image to the hub, and after a git merge, a brand new environment will be available as well for the next checkout.</p><p>If you go back in time and checkout the previous commit, by repeating the above steps, you’ll be back to your previous build environment.</p><p>From here, you can easily copy the output of your build into a new Docker image and distribute that if you’d like without shipping the whole build environment. Or, just send binaries.</p><p><strong>Note: </strong>Regardless of whether you’re able to pull images (the golden standard for identical environments) or you end up needing to rebuild the images yourself, you should make every effort possible to keep your build as reproducible as possible. That means…</p><ul><li>Version your packages</li><li>Mirror repositories (debian, pip, etc)</li><li>Mirror source code dependencies if possible (from github, etc)</li><li>Mirror the base Docker image in Docker hub if possible</li></ul><p>If you’re working with compiled code and trying to figure out how to leverage Docker with your build, I hope you found this helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=613a65624dd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Year’s Resolutions - A Post Mortem]]></title>
            <link>https://medium.com/@_i3d/new-year-s-resolutions-a-post-mortem-326916b28b9?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/326916b28b9</guid>
            <category><![CDATA[new-years-resolutions]]></category>
            <category><![CDATA[goals]]></category>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Thu, 31 Dec 2015 03:42:49 GMT</pubDate>
            <atom:updated>2015-12-31T03:42:49.067Z</atom:updated>
            <content:encoded><![CDATA[<p>I had 5 things on my list last year. I managed to achieve two of them. 40% success rate. What happened?</p><h4>Write at least once a week via blog or journal</h4><p>Failed. I didn’t even write in my travel journal when I went traveling, which is a new low. This one gets bumped to the 2016 list.</p><h4>Travel somewhere and feel less in my box</h4><p>Crushed it. Some places I went this year:</p><ul><li>Kauai, Hawaii</li><li>Whistler, BC</li><li>Silverton/Durango, CO</li><li>Sonora, CA</li><li>Portland, OR</li><li>New York (Utica, NYC, Long Island)</li><li>Lima/Arequipa/Cusco, Peru</li><li>All over Washington State (Vantage, Snoqualmie Pass, Mazama, Mt. Baker, Stevens Pass, Leavenworth, Olympic Coast, Central and North Cascades, Issaquah Alps, to name a few destinations)</li></ul><h4>Cook more / Eat out less</h4><p>Failed. This probably needs more thought. I should set a goal to cook some number of times per week, or bring my homemade lunches to work, etc. Bump to next year.</p><h4>Invest in my relationships</h4><p>Mostly failed. This one has got to go on top of the list for next year, and less abstractly. It’s not as simple as “travel somewhere” — I can literally travel anywhere and that one is checked off.</p><p>This one takes very deliberate and persistent effort in a variety of ways. There are people in my life that deserve more from me. I will be thinking more about how to successfully define and achieve this goal next year. Back on the list.</p><h4>Run a half marathon and do it under 2 hours</h4><p>1:42 @ 2015 Seattle Marathon</p><p>Not terrible but not great. For failed goals, they well be reevaluated and reset. I’ve got some good ideas to add for next year.</p><p>Goodbye to an amazing 2015, and see you soon for another incredible chapter in 2016.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=326916b28b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exit Row 20, United Airlines 757–200]]></title>
            <link>https://medium.com/@_i3d/exit-row-20-united-airlines-757-200-b3403b763b82?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3403b763b82</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[airlines]]></category>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Mon, 28 Dec 2015 00:13:25 GMT</pubDate>
            <atom:updated>2015-12-28T00:24:03.158Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VlNd_rz8ewbEbTAbJ4LMeA.jpeg" /></figure><p>Today, I flew United Airlines on a red-eye flight from Seattle to Newark. The plane was a pretty new 757–200. Unfortunately, due to the unavailability of any economy seats, I was forced to upgrade to a premium seat, and I ended up choosing the exit row because it offered extended legroom. Rookie mistake.</p><p>After having taken that flight, I can say with near certainty that exit row 20 is the worst row on the plane (it’s least in the running for worst with the very last row). <strong>Don’t do it.</strong></p><h4>Reasons to like exit row 20</h4><ul><li>Ample legroom. At least twice as much as normal, if not more.</li></ul><h4>Reasons not to like exit row 20</h4><ul><li>The seat does not recline</li><li>Sitting down feels like leaning forward</li><li>Using a neck pillow for sleeping is impossible, because the pillow between your body and the seat means you are literally leaning forward</li><li>The wall and door next to the window seat are not recessed like the rest of the plane. Leaning against it to rest means leaning upright. In other words, there is no lean at all.</li><li>The door handle drips water onto the seat</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hqZOpXe7DOwGgtffVjIYA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzQ2kO53JwCmGOa_rf51pA.jpeg" /></figure><ul><li>The row in front of you, 12 (not an exit row) <strong>does</strong> recline</li><li>The row behind you, 21 (<em>also an exit row</em>) <strong>does</strong> recline, AND has a recessed panel window seat side</li><li>Despite all of the above, United still charges a premium to sit in row 20</li></ul><h4>The takeaway</h4><p><strong>Never</strong> sit in exit row 20 on a United Airlines 757–200. Try 21. Better yet, <a href="http://www.seatguru.com/">double check your seat choice</a> before you go!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3403b763b82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Greenwave/TCP Connected Lightbulb Update [Updated]]]></title>
            <link>https://medium.com/@_i3d/greenwave-tcp-connected-lightbulb-update-4f76fd42f21f?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f76fd42f21f</guid>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Sat, 24 Jan 2015 07:53:23 GMT</pubDate>
            <atom:updated>2015-01-27T00:53:01.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXQmIOTC-b1AZcbBG0MVyQ.jpeg" /><figcaption>It’s not a back door when it’s a front door… The red light indicates that this gateway cannot access the internet. And that’s the way I like it.</figcaption></figure><h3>Greenwave/TCP Connected Lightbulb Update [Updated!]</h3><h4>Update, January 26th</h4><ul><li>The firmware update started for a few consumers around October, but was widely pushed out (<em>without user consent, I’d like to note</em>) to everyone beginning January 23rd, 2015.</li><li>I’ve updated <a href="http://github.com/therivenman/pygop">pygop</a> (python) based on <a href="http://home.stockmopar.com/updated-connected-by-tcp-api/">recommendations</a> by the guys who develop <a href="https://www.npmjs.com/package/connectedbytcp">connectedbytcp</a> (node.js) to now support the HTTPS-only gateway</li><li>Root access is still gone, gone, gone.</li></ul><p><strong>Final thoughts</strong>: Unless you really want remote access of your lights, I recommend that you block the gateway from accessing the internet. Who knows what these guys (or anyone else, for that matter) will do in the future?</p><p>I am personally not happy about them pushing updates without notifying anyone, and I’m not happy about them not having a terms of use or terms of service agreement which would have alerted me to such a possibility. This is the tip of the iceberg for the internet of things. Do you really own your own stuff anymore?</p><p>Welcome to the <a href="http://techcrunch.com/2014/10/11/the-internet-of-someone-elses-things/">internet of someone else’s things</a>.</p><h4>Original Post</h4><p>By the looks of things, someone decided to push a firmware update shortly after I started posting my findings (around the end of October 2014).</p><p>The update, version 3.0.74, has had the following effects:</p><ul><li>https only now, web interface removed (not sure if scripting still works)</li><li>sshd isn’t starting up at boot</li><li>UART pins have been silenced, and I think boot delay is 0 (no more kernel init hijacking with uboot)</li></ul><p>The system can only be used through the app or physical remote now. No more 3rd party integration or hacking around until another workaround is found.</p><p>Looks like we were having too much fun for TCP or Greenwave’s liking. If you are lucky enough to have a device which has not been updated at this point, I’d take it off the network and start blocking your gateway from phoning home.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f76fd42f21f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scripts to automate a Greenwave sunrise]]></title>
            <link>https://medium.com/@_i3d/scripts-to-automate-a-greenwave-sunrise-919efff42083?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/919efff42083</guid>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Mon, 20 Oct 2014 06:46:28 GMT</pubDate>
            <atom:updated>2014-10-22T15:51:40.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*DuQVFpNbdmnsqlP4EjDXGw.jpeg" /></figure><h2>Scripts to automate a Greenwave sunrise, AND MORE!</h2><p>Waking up is hard to do.</p><p>I’ve previously mentioned that you can control your bulbs using HTTP POST and GET requests to your gateway, but yesterday someone asked me on Twitter to share my scripts for controlling the bulbs. So here they are!</p><blockquote><a href="https://gist.github.com/bdunlay/b9efaf729cbcacff3d76"><em>Toggle</em></a><em> | </em><a href="https://gist.github.com/bdunlay/335b4c8f63095372606c"><em>Dim</em></a><em> | </em><a href="https://gist.github.com/bdunlay/2f30972faacc9e1bfc32"><em>Sunrise</em></a></blockquote><p>You can take these scripts and put them (all together) in any directory you’d like. <em>Please note that Sunrise requires Toggle and Dim to work! </em>To get yourself up and running, follow these simple steps:</p><ol><li>Set permissions so they can be executed (e.g. chmod 777 sunrise.sh)</li><li><a href="http://lighting.local/gwr/gop.php?cmd=GWRBatch&amp;data=&lt;gwrcmds&gt;&lt;gwrcmd&gt;&lt;gcmd&gt;RoomGetCarousel&lt;/gcmd&gt;&lt;gdata&gt;&lt;gip&gt;&lt;version&gt;1&lt;/version&gt;&lt;token&gt;1234567890&lt;/token&gt;&lt;fields&gt;name,image,imageurl,control,power,product,class,realtype,status&lt;/fields&gt;&lt;/gip&gt;&lt;/gdata&gt;&lt;/gwrcmd&gt;&lt;/gwrcmds&gt;&amp;fmt=xml">Get the device ID from your gateway</a> of the bulb that you would like to control and set it in the dim.sh and toggle.sh scripts so they know which bulb to talk to.</li><li>Add the directory where your scripts live to the PATH assignment in the sunrise.sh script</li><li>Command your bulbs on-demand, or set up a cron task to automate the job like I have. The example entry below turns on beginning at 7:35 AM and brightens to 100% gradually over a 10 minute period:</li></ol><p>35 7 * * * /bin/sh /Users/_i3d/Documents/fakesunrise.sh 10</p><h3>Future Development</h3><p>These scripts could be easily expanded to handle multiple bulbs, and I will likely update that code once I get some side lamps for my bed. If you take on that task, or have any other improvement suggestions, please let me know.</p><p>I’m currently looking at setting up a scheduling server on a WiFi enabled CC3200 Texas Instruments Launchpad that I have. That will allow me to control the light bulbs individually (clicking one physical button would move a “cursor” around, selecting each bulb, or all bulbs, while the other physical button will toggle and dim). I was also planning to set up some way to easily configure the schedule — current ideas are floating around a Twitter-based protocol for command and control.</p><p>Let me know if you do anything with these scripts or if you come up with your own methods for interacting with these bulbs!</p><p><strong><em>Edit post-publishing</em></strong><em>: I’ve found and am contributing to a python library called </em><a href="https://github.com/therivenman/pygop/"><em>pygop</em></a><em>. If you like Python then you’ll like this. Currently there’s no sunrise / gradual dimming capabilities, but it has some other cool stuff like bulb/room identification. Check it out, more to come!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=919efff42083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sniffing IPv6 traffic to the Greenwave Reality Bulb Network]]></title>
            <link>https://medium.com/@_i3d/sniffing-ipv6-traffic-to-the-greenwave-reality-bulb-network-58760f3d0505?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/58760f3d0505</guid>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Sun, 12 Oct 2014 05:27:19 GMT</pubDate>
            <atom:updated>2014-10-12T05:50:28.717Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rqDPgA-dxFcisq4F-PVbpA.png" /><figcaption>Network trace for the Greenwave Reality / TCP Connected light bulb network.</figcaption></figure><p>How to see what’s going on behind the scenes.</p><h3>Network Stack and Topology</h3><p>In order to sniff the network, we need to understand the stack and topology for a simple JenNet-IP (JIP) network, as provided by NXP’s <a href="http://www.nxp.com/documents/user_manual/JN-UG-3080.pdf">documentation</a>. Then we can see how it maps to the solution Greenwave has provided.</p><p>I’ve also written a step-by-step TL;DR at the bottom if you want to just jump right in.</p><h4>NXP Reference Design</h4><p>This reference design is what NXP provides as a sample design. On the left is an application stack residing on a large network (Local Area Network or Internet). The center is the gateway, which sits at the edge of the LAN and the Wireless Personal Area Network. On the right, the WPAN is the network of nodes (bulbs).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*YKgDUO-atvcL4MkyXm3CJw.png" /></figure><p>The border-route translates IPv4 commands into IPv6, and sends that traffic across the WPAN network. According to the documentation, the WPAN interface could be implemented in separate hardware from the border router, attached by a serial connection (e.g. USB).</p><h4>Greenwave Implementation</h4><p>The product being sold is close, but not exactly the same as the reference design. Here’s what the high level connections look like at home.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5tXxudfGZeHRkTGcIPfSzQ.jpeg" /></figure><p>From left to right, we have the LAN/WAN device (controlling the network from the internet). The gateway is in communication with Greenwave servers on the internet (that, as an aside, happen to run on Amazon AWS) so that the network can be controlled from anywhere in the world. Per the <a href="http://go.tcpi.com/Connected_Privacy">TCP privacy policy</a>, apparently they collect information about usage, room names, and more.</p><p>In the center/right, we have the Gateway. The WiFi router is the connection to devices on internet/local area network, and it is plugged directly into the gateway via ethernet. One distinction, however, is that the phone and laptop in this setup do not run a native JIP stack with the Greenwave application. They are actually communicating with an HTTP server that runs on the gateway, which if you reference the picture up above, is the application layer on the left of the blue box.</p><p>Finally, on the right, we have the 802.15.4 interface and the bulbs, which make up our WPAN network.</p><p>Notice that we don’t use a serial connection for the WAN/LAN — WPAN connection. In fact, everything is implemented in one box, so most of the right within the blue box is irrelevant. Also, since I don’t have iOS or Android, I can’t presently use the Greenwave servers to communicate, so my communications are wholly using the LAN.</p><p>The left side of the network is a management application, from the internet or from a remote place on the network. The center is the gateway. The right is the lightbulb.</p><p>The internet side of things is mostly irrelevant for us — I think this is more applicable with multiple gateways that can be controlled remotely, and natively (you see it is running the application layer directly on it).</p><p>Likewise, the right side of the blue diagram is mostly irrelevant too — the gateway implements everything from application to 802.15.4 radio, and there is no serial connection between devices (say a router to a dongle). Further inspecting the running daemons on the Greenwave server, it’s easy to see that the 6loWPANd service communicates directly to the 802.15.4 interface. Here’s a simplified architecture that is much closer to what we have. It’s probably not 100% accurate, but it’s close enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*UaLGahmFkeeEFFnTKbQ1KQ.png" /></figure><h3>Sniffing Traffic</h3><p>What you sniff depends on what you want to learn about. In earlier posts, I have written about HTTP POST and HTTP GET commands which the iOS and Android applications utilize to control the bulb network. There are more than I have written about, but without any devices running either of those operating systems, I’m unable to generate or observe those commands. Regardless, the best place to sniff that traffic is somewhere along the WLAN Device -&gt; Border-Router connection, and that should be fairly trivial for anyone who knows how to use Wireshark.</p><p>What is a little more interesting to me is the traffic being sent directly to the bulbs. Why sniff these packets though? The protocols observed could be used to generate a new application layer without using official APIs. Or they could be used to spoof traffic on the network, either at the gateway or wirelessly using an 802.15.4 radio. The network could also be expanded with new devices beyond light bulbs.</p><h4>What and Where to Sniff</h4><p>We could monitor the traffic coming in over the ethernet cable to the gateway. But, the <em>eth0</em> interface will only give network traffic destined for, or originating from the HTTP server, and will not contain any of the IPv6 traffic of the WPAN network.</p><p>We could monitor the data being sent to the RX/TX pins of the 802.15.4 radio. Or we could even try to set up another 802.15.4 radio to receive this traffic. But that traffic is likely to be encrypted, and frankly, there’s an easier way.</p><p>As we know, the WPAN runs on IPv6. All of the commands we send the gateway are IPv4. Somewhere inside of the gateway, commands are being translated from IPv4 to IPv6 — and this is the exact point we intend to observe.</p><p><strong>ifconfig</strong> shows us three interfaces. <em>eth0</em>, <em>lo</em>, and <em>tun0</em>.</p><ul><li><em>eth0</em> is our ethernet interface from the router.</li><li><em>lo</em> is the loopback interface.</li><li><em>tun0</em> is a <a href="http://en.wikipedia.org/wiki/TUN/TAP">virtual network interface</a> in the kernel which connects with user space applications. This is what we want.</li></ul><p>Interface parameters report that it is not in <a href="https://en.wikipedia.org/wiki/Promiscuous_mode">promiscuous mode</a> by default. We’ll need to turn on promiscuous mode if we intend to sniff the traffic with the command <strong>ifconfig tun0 promisc</strong>. It can likewise be turned off with <strong>ifconfig tun0 -promisc. </strong>A second inspection of the interface parameters should reveal PROMISC when it is turned on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*qFTsz5-JWF11TCoCeG3Dig.png" /><figcaption>PROMISC indicates that the interface is configured for promiscuous mode.</figcaption></figure><h4>How to Sniff</h4><p>With knowledge of the gateway’s hardware, it should be fairly obvious that we don’t want to capture a network trace on the device itself. There’s little memory (64 MB) and even less flash (32 MB). If the network is a particularly active one, we could run out of space quickly.</p><p>Instead of doing a local capture, <strong>ssh</strong>, <strong>tcpdump</strong>, and <strong>wireshark</strong> can be combined for a remote capture from your laptop. In the following command [gateway] can be the IP address, “lighting” on Windows or Linux, or “lighting.local” on a Mac.</p><p><strong>ssh root@[gateway] “tcpdump -ni tun0 -s0 -w — “ | wireshark -k -i -</strong></p><p>Provide the root password <em>thinkgreen</em>, and you’re in business! Start sending some commands to the network and watch them appear in Wireshark.</p><p>Here’s the payload of several “turn on” and “turn off” commands. Notice the byte at the end changing. The earlier byte changing is just a packet ID that increments with each command sent.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmtc.cdn.vine.co%2Fr%2Fvideos%2F053D7C32D71132947805674131456_165338a107c.3.4.mp4%3FversionId%3DPZBzWP6u9oo5nrq_I115nu7sc7t.aCgC&amp;src_secure=1&amp;url=https%3A%2F%2Fvine.co%2Fv%2FOAUZgHBEYHh&amp;image=https%3A%2F%2Fv.cdn.vine.co%2Fr%2Fthumbs%2F259568658B1132947807863734272_1.3.4.mp4.jpg%3FversionId%3DiaA9WYqCh9LUiTm1MdDE_Qd644YOkW_n&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=video%2Fmp4&amp;schema=vine" width="600" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ad66c63992de12a0d158c6d15933181/href">https://medium.com/media/9ad66c63992de12a0d158c6d15933181/href</a></iframe><p>So far I have observed that commands that have <strong>0x0F04</strong> in the 8th and 9th bytes are “on” and “off” (the 10th byte being <strong>0x00</strong> or <strong>0x01</strong>), and commands that have <strong>0xBF04</strong> in the 8th and 9th bytes are used to set brightness (the 10th byte, from <strong>0x02</strong> — <strong>0xFF</strong>, incrementing by 3 and 2 alternatively — e.g. <strong>0x2</strong>, <strong>0x05</strong>, <strong>0x07</strong>, <strong>0x0A</strong>, <strong>0x0C</strong>, … <strong>0xFF</strong>). I haven’t done extensive analysis yet, so your mileage may vary. I indend to dig deeper to get a better understanding.</p><h3>What’s Next</h3><p>Analysis! I need to go back and read about packet addressing, observe various commands, and other random traffic as it occurs to better understand what is being said. I might even write my own protocol decoder for wireshark to make analysis a little easier. Eventually, I would also like to install <strong>netcat</strong> and try to spoof some commands directly.</p><p>Hope you found this useful for hacking your own TCP Connected / Greenwave setup. Until next post, happy hacking!</p><h3>TL;DR</h3><p>If you don’t like the jibber jabber and want to get straight to it:</p><ol><li>Install wireshark on your local computer</li><li>SSH into the gateway using username <em>root</em> and password <em>thinkgreen </em>and turn on promiscuous mode on the tun0 interface:<br><strong>ifconfig tun0 promisc</strong></li><li>Pipe tcpdump on the gateway to wireshark on your local machine:<br><strong>ssh root@[gateway] “tcpdump -ni tun0 -s0 -w — “ | wireshark -k -i -</strong></li></ol><p>4. Send commands to the network using the browser, an iPhone, an Android device, or something else you’ve created yourself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58760f3d0505" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding The Greenwave Reality Gateway]]></title>
            <link>https://medium.com/@_i3d/understanding-greenwave-reality-gateway-908504799284?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/908504799284</guid>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Thu, 09 Oct 2014 07:41:53 GMT</pubDate>
            <atom:updated>2014-10-12T05:44:28.291Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*jt0SvioTEN8fJsLM5HIHvA.jpeg" /><figcaption>Holger Danske</figcaption></figure><h2>Understanding the Greenwave Reality Gateway</h2><p>That magical black box.</p><p>I found out quickly that while TCP sells lightbulbs, it looks like they’ve just licensed the connected light bulb tech from Greenwave Reality and slapped their brand on it.</p><p>Now, bulbs don’t just work. They need a gateway to convert normal internet stack traffic to the JenNet-IP stack. They use different protocols and different communication technologies (802.11/ethernet vs 802.15.4).</p><p>The gateway runs a local web server to interpret commands from phones and the browser, which translates those into commands that are sent across the JenNet-IP network (NXP protocol stack for an enhanced 6loWPAN) to the bulbs (or anything else on that network).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*DiXI1cyXPFoBzE9TmBD43w.png" /><figcaption>In this diagram, the green circles represent the Greenwave Reality gateway. Blue and red represent bulbs. Multiple gateways are permitted on a subnet, and bulbs may act as routers.</figcaption></figure><h3>What I know About the Gateway</h3><ul><li>It runs Linux! 400 MHz Power PC 40x Platform, 64 MB Memory and 32 MB Flash</li><li>This has been <a href="http://gtvhacker.com/index.php/Greenwave_Reality_Bulbs">hacked before</a>! sshd is enabled, and the <strong>root</strong> password is <strong>thinkgreen</strong></li><li>Cherokee is the webserver. It rewrites a misleading .php file to a CGI file</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*fK4_7DCRfV6D-15x7E0RjA.png" /></figure><ul><li>This file, <strong>I THINK</strong>, uses NXP APIs to ultimately talk to a daemon, <a href="https://github.com/bdunlay/6LoWPANd">6loWPANd</a>, which kicks off at boot time</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*Hd_G0Fa6Qjb7RGT0PsDZGg.png" /></figure><ul><li>There are web commands via GET and POST to list bulbs on the network, toggle bulbs, and set bulb brightnesss (and presumably more, probably to schedule stuff and configure higher level features like scenes etc, but I haven’t figured them out yet since I don’t have an Android or iPhone)</li><li>This Gateway phones home frequently (to Greenwave reality servers) with a program called holger, who in the <a href="http://www.pantheon.org/articles/h/holger_danske.html">Danish culture</a> is known as a guy who is asleep and ready to wake up and protect the Danish people.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/194/1*6x0ngV2LCWBvXrAmh7YwYw.png" /></figure><ul><li>Holger also knows my GPS coordinates, and can do tons of logging about many things that I will probably find interesting later.</li></ul><p>So, it’s a fully capable computer aware of your physical location and with complete access to your local network. It pings home often and has SSH enabled. In other words, this thing could be considered a bit of a trojan horse for your local network!</p><h4>What I’ve Done</h4><p>Well, I’ve mostly just poked around. The most interesting thing so far I think, from a user’s perspective, is a shell script I wrote that I scheduled with cron to increase the brightness my bulbs from 1–100 over a 10 minute period as a gentle wake up. It simply makes HTTP requests to the Gateway’s web server.</p><p>Since I don’t own an iPhone or Android device, I can’t actually configure the network properly as Greenwave would want me to. When I use their browser interface, it doesn’t let me add bulbs — only manage scenes. So for now, my only way to control these things is via shell scripts. ☺</p><h4>What I’m Doing Next</h4><p>I’m probably going to read NXP’s <a href="http://www.nxp.com/documents/user_manual/JN-UG-3086.pdf">documentation</a> to understand 6loWPANd’s role and what APIs are available. This will help me to write my own application.</p><p>I’m also going to try to sniff the 802.15.4 interface so I can attempt to reverse engineer the application layer protocol that Greenwave is using to communicate with these bulbs. I tried attaching to the TUN interface with tcpdump but so far have not had any luck getting anything. I could also try to <a href="http://wiki.beyondlogic.org/index.php?title=Budget_802.15.4_6LoWPAN_Protocol_Analyser_using_Wireshark">receive network traffic</a> with a spare XBee radio I have laying around.</p><p>Finally, I will probably attempt to analyze what is being sent to / from Greenwave servers. I may want to keep a channel open for potential firmware updates, but maybe not. We’ll see.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=908504799284" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TCP Connected, Out of the Box]]></title>
            <link>https://medium.com/@_i3d/tcp-connected-out-of-the-box-b9d06795783?source=rss-b4b74e67ec30------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9d06795783</guid>
            <dc:creator><![CDATA[Brian]]></dc:creator>
            <pubDate>Thu, 09 Oct 2014 07:35:09 GMT</pubDate>
            <atom:updated>2014-10-12T05:44:47.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*rKEmZcVXnwwE6kopvpp6uA.jpeg" /></figure><p>The Internet of Lightbulbs!</p><p>I’ve been interested in home automation and lighting and such for a long time, but the thought of investing in a particular ecosystem seemed daunting. What if the protocols don’t win (like ZigBee vs Z-Wave?) What if the company goes away and I’m stuck with what their last iteration was? What if I buy other things that don’t integrate?</p><p>Well, I did some research and settled on the <a href="http://go.tcpi.com/GetConnected">TCP Connected</a> bulb. I wanted <a href="http://www2.meethue.com/en-us/">Philips Hue</a> originally, but ultimately decided that for half the price, an apparently hackable gateway, and the ability to what I want (dim), I would give it a go. Admittedly Philip’s marketing is a lot sexier than TCP’s, but the decision to get TCP’s product was more than skin deep!</p><p>Today, 3 bulbs and a gateway arrived. I was so excited that as soon as I opened the package I screwed one of the bulbs in and when to set up the gateway. The light turned on, but I couldn’t figure out how to turn it off.</p><p>I got onto the gateway (<a href="http://lighting/">http://lighting</a>, <a href="http://lighting.local/">http://lighting.local</a> for mac users), but found that there was no ability to manage the bulb. Unfortunately for the purposes of these bulbs, I don’t have an iPhone or an Android device, which means I can’t easily configure them as they were meant to be configured.</p><p>I thought maybe I could pop open an Android emulator, install the app, and try from there… that’s a lot of work. Emulator doesn’t even come with Google Play store. Scratch that.</p><p>Pulled out an old phone, but the thing is so junky that every process running keep crashing without me even touching the device.</p><p>Well, other people have been at this for longer so I went digging around. Turns out the gateway can (at a bare minimum) be managed very easily by some simple commands:</p><p>List all devices on the network. Copy down the Device ID returned of any bulbs on the network</p><ul><li>[GET]</li><li><a href="http://lighting/gwr/gop.php?cmd=GWRBatch&amp;data=%3Cgwrcmds%3E%3Cgwrcmd%3E%3Cgcmd%3ERoomGetCarousel%3C/gcmd%3E%3Cgdata%3E%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cfields%3Ename,image,imageurl,control,power,product,class,realtype,status%3C/fields%3E%3C/gip%3E%3C/gdata%3E%3C/gwrcmd%3E%3C/gwrcmds%3E&amp;fmt=xml">http://lighting/gwr/gop.php?cmd=GWRBatch&amp;data=&lt;gwrcmds&gt;&lt;gwrcmd&gt;&lt;gcmd&gt;RoomGetCarousel&lt;/gcmd&gt;&lt;gdata&gt;&lt;gip&gt;&lt;version&gt;1&lt;/version&gt;&lt;token&gt;1234567890&lt;/token&gt;&lt;fields&gt;name,image,imageurl,control,power,product,class,realtype,status&lt;/fields&gt;&lt;/gip&gt;&lt;/gdata&gt;&lt;/gwrcmd&gt;&lt;/gwrcmds&gt;&amp;fmt=xml</a></li></ul><p>Toggle a device on or off (Change the “value” parameter in the XML to 0 or 1; use Device ID)</p><ul><li>[POST]</li><li><a href="http://lighting/gwr/gop.php?cmd=DeviceSendCommand&amp;data=%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cdid%3EDEVICEID%3C/did%3E%3Cvalue%3E1%3C/value%3E%3C/gip%3E&amp;fmt=xml">http://lighting/gwr/gop.php?cmd=DeviceSendCommand&amp;data=&lt;gip&gt;&lt;version&gt;1&lt;/version&gt;&lt;token&gt;1234567890&lt;/token&gt;&lt;did&gt;DEVICEID&lt;/did&gt;&lt;value&gt;1&lt;/value&gt;&lt;/gip&gt;&amp;fmt=xml</a></li></ul><p>Set the brightness</p><ul><li>[POST] (Change the “value” parameter between 1–100; use Device ID)</li><li><a href="http://lighting/gwr/gop.php?cmd=DeviceSendCommand&amp;data=%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cdid%3EDEVICEID%3C/did%3E%3Cvalue%3E25%3C/value%3E%3Ctype%3Elevel%3C/type%3E%3C/gip%3E&amp;fmt=xml">http://lighting/gwr/gop.php?cmd=DeviceSendCommand&amp;data=&lt;gip&gt;&lt;version&gt;1&lt;/version&gt;&lt;token&gt;1234567890&lt;/token&gt;&lt;did&gt;DEVICEID&lt;/did&gt;&lt;value&gt;25&lt;/value&gt;&lt;type&gt;level&lt;/type&gt;&lt;/gip&gt;&amp;fmt=xml</a></li></ul><p>This was enough to get me rolling. I wrote up a shell script to toggle on the light and then set the brightness from 1–100 incrementing over a period of 10 minutes to simulate a rising sun. I’ll probably make it non-linear in my next iteration, but it seemed like a fun way to enhance the otherwise limited binary functionality of the bulb.</p><p>More fun stuff: root password has been cracked, so it’s easy to SSH into the device and poke around. I will be spending a lot more time in here to figure out what’s what and see what I can do. It’s a full linux box though — there are a lot of possibilities in my head right now.</p><p>I want to get crond running on the gateway, as well as write some of my own applications (or at least APIs) for it. I also want to understand 6loWPANd (the daemon that is running the network) and the JENNET-IP protocol so I can tap into that as well.</p><p>The internet of things is a crazy place… and very exciting. Will keep this blog updated with my progress.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9d06795783" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>