Planning for the easily distracted, part 2: Break it down like I’m a 5-year-old

In previous posts I’ve talked about the importance of planning and how to determine which features are essential vs. nice to have. Using my project Hoshi as an example, I’ll now go into how we go from a very high level overview into something we can implement.

Remember that in the previous installment I generated the following MUST and SHOULD list for my sensors:

We MUST have sensors that can detect events in the physical world. The sensors MUST also relay those events to the central system for processing.

The sensors SHOULD be small and inexpensive. The sensors SHOULD be able to be battery powered or use wall power. Users SHOULD be able to have an arbitrarily large number of sensors.

The way the sensors communicate back to the central server SHOULD be robust, easily extensible, and, to be convenient, not require extra hardware to increase range.

Looking at each line, there are some obvious questions that we need to answer. We MUST have sensors that can detect events in the physical world – so what events do we want to detect? In this case, I want to detect motion. I also probably want to detect light levels since I’m building this to control, among other things, lights, and maybe I want to not turn on my lights if it’s broad daylight and I’m getting plenty of sun in a room. So now, my “we MUST have sensors that can detect events in the physical world” becomes:

We MUST have sensors capable of detecting motion and capturing the ambient light level in their environment.”

The next MUST – the sensors MUST also relay those events to the central system for processing – gets me wondering HOW the sensors will relay those events. I could just have the sensors wired directly to the central server, but that seems really limiting – I’d have to run cables all over. So, a wireless connection it is.

This leads us down a further avenue for inquiry – what KIND of wireless connection? And what does having a wireless connection imply for the construction of the sensor – what kind of hardware will I need to support that wireless connection?

For the kind of wireless, I’m going to look at my SHOULDs. I want the sensors to be small and inexpensive, I want them to be able to be battery powered, I want to be able to have an arbitrarily large number of them, and I want my network of sensors to be robust and easy to add nodes to.

So breaking it down into details: I need something that is capable of handling logic for networking as well as reporting back a payload of sensor events over that network – this is clearly a job for a microcontroller such as the Arduino. Looking at my SHOULDs – I need small and cheap, and that means an Arduino Nano, which at ~$3-6 and about 1″x2″ or less, is both small and cheap.  Even better, the Nano is readily available in bulk – if I decide I really want to scale up, I won’t need to source rare or difficult to get hardware. For example, if I wanted to use a Raspberry Pi zero – which is much more capable than a Nano and only $5 – I would have a hard time getting my hands on enough of them.

I will need to connect the motion and light level sensors to the Nano, so I’ll create a module for that which can be added to the Nano. This would require a few inexpensive components – a motion detector (about $1), light sensitive resistors/a light sensor (pennies on up to $1-2 for something fancy), and a small proto board (pennies) to put it all on. That qualifies as cheap!

I will need to add wireless networking to the system. I could do wifi – there are $2 chips for that and they can run pretty well on a battery for a fair amount of time. I could look at Bluetooth low power modules, though those run $5-10, which isn’t very cheap. I could use a RF transceiver, which I can get for under a dollar, but which might also have range issues – in order to get those and also solve the range issue, a little research shows they would cost $5-10 per part. So, I will probably go for the wifi chips.

I will need to make sure that range isn’t a problem and that the network is easy to extend – I want to be able to put my nodes wherever I like and they should be reliably able to communicate back to the central system. To me, this says I need to look at a mesh network, where each node in the network helps extend the network range farther. It also makes me think I might want to consider whether or not making some nodes in the network just function as extensions – I could have two models of nodes, one with sensors and one without…

Breaking THAT down, I realize that the sensor module isn’t very expensive, and maintaining two different types of nodes would be a pain, so I’ll just have one type of node. Ultimately, this gives me:

Sensor nodes will use standard parts that are readily available in bulk, and will all share the same design – all nodes will be functionally identical. The nodes will be based on an Arduino Nano. The sensor module will include motion and light level detection. The node will run on battery and use a wifi chip and will be configured to use the least amount of power possible. The node will be configured to work as part of a mesh network, which will allow the network to be extended as new nodes are added.

By breaking things down into the detail that I did, it prompts me to ask questions I might not have thought about when I was only looking at the high level overview. There are still some questions that were raised that I’ve left unanswered – lots of questions about the mesh networking, specific parts I’d want to use, requirements on range for the sensors (detecting motion within 2 meters vs 10 meters, for example).

My feeling is that, for a personal project, I now have an idea of what parts I want to use and can start doing a bit of research & basic implementation to get them working. For V1 of my project, this level of detail is sufficient – it’s a starting point that can be refined through trial and error into something that works. I’m now ready to get it done!

Planning for the easily distracted, part 1: Must and Should

In business, there’s the idea of a “minimum viable product” or MVP. The MVP is the least expensive (in time, money, and risk) version of a product or feature that you can put in front of potential users to test whether or not there’s a market for whatever it is you want to do. MVPs should be simple, but get the job (gauging interest) done – I know of a startup that literally just went to potential clients with static images and a way to explain their potential product, and it was enough to get early investment so they could actually make the product. MVPs tend to focus on the “golden path” as in, the features and use cases that 90% of the potential market will want to use, rather than niche cases. An MVP should be the bare essentials needed to get started. Extra features – nice to haves – can be put in a backlog of things to get at once you have your first version out the door and it gets traction. Why spend time on things that aren’t essential when you don’t even know if there’s any interest in them?

For personal projects, I’m not very worried about what people will want, as usually I’m just intrigued by an idea or technology and want to play with it. Even so, I want to create something similar to an MVP, getting my project working end-to-end with the bare minimum of extras, and THEN I start adding those nice-to-have features that are such tempting distractions. I do try to get my idea as well specced out as I can so that I don’t suddenly find something that I overlooked that leads to distraction and derails the whole thing.

For an MVP, I think in terms of MUST and SHOULD. MUST items are absolutely essential features, without which nothing works, while SHOULD items are ones that I think can wait until later. While I usually don’t implement SHOULDs right away unless they are absolutely trivial, the important part of thinking about those SHOULDs is that they can influence the way the MUSTs are carried out. I just describe things in terms of what a thing MUST do to be functional, and SHOULD do to be delightful to use or viable as a potential product.

Continuing to use Hoshi, a home automation project that will make my smart home proactive vs. reactive, as our exemplar here, I will provide an example of MUST and SHOULD descriptions.

We MUST have a centralized system that is fluent in multiple external APIs when it receives notifications of events. That system MUST have some kind of rules regarding what to do when a given event happens. To do that, we MUST have sensors that can detect events in the physical world. The sensors MUST also relay those events to the central system for processing.

The centralized system SHOULD be easy to administer. Rules SHOULD be easy for a user to create. It SHOULD be very easy to add both new types of sensors to the system. It SHOULD be very easy to add new APIs to the system.

The sensors SHOULD be small and inexpensive. The sensors SHOULD be able to be battery powered or use wall power. Users SHOULD be able to have an arbitrarily large number of sensors.

The way the sensors communicate back to the central server SHOULD be robust, easily extensible, and, to be convenient, not require extra hardware to increase range.

From all of the above, for this example, I will be digging into the MUSTs and SHOULDs around the sensors rather than everything else. In this case, the SHOULDs about the sensors will strongly influence my initial choices in the MUST section. Because the sensors SHOULD be small and inexpensive, I’m going to look at implementations that don’t rely on stupidly expensive hardware.

If I didn’t pay attention to my SHOULDs, I might say hey, I’ll buy a bunch of pre-made sensors off the shelf which would certainly do for the MUST part. However, they tend to run $30+ which isn’t inexpensive enough for my tastes. The ones that do have a lot of range tend to be more expensive and also don’t last long on battery power. So if I only considered my MUSTs and not my SHOULDs, I’d wind up with a bunch of expensive hardware that doesn’t fit in with my longer-term plans. I’ll need to look at rolling my own sensors, which in addition to being less expensive and more likely to meet my exact needs, will also be a lot of fun.

One thing to note is that I’m not going into the technical details, but in the next step I’ll show how we go from MUST and SHOULD to a functional plan.

Fail to plan? Plan to fail. Planning for the easily distracted, part 0

We’ve all been there – you have an amazing idea for an ambitious personal/hobby project that will leverage a ton of interesting technologies and so something incredible. You start working on one aspect, then realize there’s something else that needs doing first so you switch to that, then another issue comes up and you realize you need to do THAT, and then you just find yourself thrashing and context switching so much you don’t get anything done to the point where you just bail on the whole thing.

At least, I’ve been there. I won’t go so far as to say I have ADD, but I do tend to get easily distracted by flights of fancy and the like when I’m working on stuff that isn’t, you know, work. Like, even as I was typing that sentence, I was thinking about 8 different things, one of them being “should I make the obvious joke where I interrupt myself and say ‘squirrel!'” and you can see, I’m digressing. In any case, for me, having a GOOD plan when I start working on a personal project is absolutely essential to getting things done.

If you haven’t had that problem, then this post is not for you – if you’re one of the rare people who is naturally very disciplined and focused, I’m jealous, but you can skip on past. For everyone else, here’s a technique that has helped me.

Here I’m presenting the methodology I use when working on a personal project that helps keep me from being distracted. I will use Hoshi, the home automation project I wrote about previously, as my example, since I’ll be doing these steps anyway while I work on it.

The steps of my process are pretty straight-forward:

  1. Come up with an idea for a project
  2. Figure out what my product MUST do and what my project SHOULD do
  3. Break a high-level description of the project into very small, detailed, pieces
  4. Turn those details into specifications
  5. Implement the specifications
  6. Put everything together

It’s not rocket science – people will look at the steps I’ve outlined and say “well, DUH” – but the point here is to provide a lightweight conceptual framework that lets you Get Stuff Done, and honestly most of that is just common sense.

Return of the Mac

At work, since I work in .Net-land, I do most if not all of my dev work on a Windows box. Consequently, I would do a lot of my for-fun stuff also on a Windows box. A few years ago I got a MacBook Pro because every Windows laptop I got was built like crap and would get destroyed very quickly when I traveled – I went through like 4 laptops in a 2 year period. The only laptop I’d ever used that was physically durable enough while also not weighing a ton was an aluminum MacBook, so I got one of those.

I never really did much dev work on it, though – it was a solid machine for travel, some games (yay Steam). I maybe noodled around a little doing some front-end experimentation and a little bit of Python, but nothing more than toy projects.

With Hoshi, I’ve decided to start using my Mac for the development, since it’ll all be in Angular and Python + Flask. I’m using VS Code for my editor, since it’s a really nice editor.  Some of the *nix stuff I’ve been learning while setting up my Pis has been helpful, though things like Brew vs. apt-get and some of the other OS X related stuff is a bit annoying.

So far it’s been very nice – even though I’m still figuring out the workflow and fumbling around looking for commands, I’m finding it a pretty decent tool. I have Parallels with a copy of Windows 10 on it, so that’s also been good – I can mix and match bits and pieces in the pipeline.

Getting it done

At my first developer job, we used a tool called Trello to track our sprint work – the stuff we had to get done every two weeks. Our process was that we would create stories and tasks on Trello, and then hand write the tasks onto PostIt notes to put on a physical whiteboard, because there is something deeply satisfying about moving a physical thing when completing a story.

The problem was, this took up time. Having a bunch of developers sitting around hand-writing tasks (with crappy hand-writing, to boot) was obnoxious. Everyone hated it, and everyone would talk about how “easy” and “dead stupid” it would be to just write some kind of app that would leverage the Trello API and generate a printer-friendly display of the tasks so we could just put those on the board. They talked about it, but…

No one did anything. Every sprint planning we’d have 3-5 developers spending an hour or two dutifully scrawling on PostIts while simultaneously bitching about how annoying it was.

Back then, my JavaScript was absolute crap (and to be honest, it still is) so I decided I wanted to get better at it, and was trying to think of a project I could use to do that. After noodling about, I realized that this “obvious” and “easy” project everyone was talking about would be a perfect fit. So I spent some time on a weekend screwing around, and created a very bare bones app that would give a sprint team their tasks, nicely laid out, with all the info that was relevant, ready to be printed out and used on the board.

I spent maybe 10 hours on it, total, and got familiar with some parts of JavaScript I hadn’t used before, so even without any other benefits, it was a win. But at work – it turned something that took up 3-10 total developer hours, per team, per every 2 weeks – into something that took about 10 minutes total. We had 4 sprint teams, and everyone started to use this, which means that my 10 hour weekend project wound up having some pretty disproportionate knock-on effects.

The thing I learned from this is that just having an idea isn’t any big deal. We ALL had the same idea. But acting on an idea – bringing it to fruition – that is special, and all-too-rare.

Yelling at lightbulbs

I’m something of an early-ish adopter when it comes to technology, and wound up getting myself an Echo and Hue lights back when the Echo first launched. I had a dream of a utopian future where I would be able to tell my house to do my bidding, and this was the first step in that plan.

What actually wound up happening that first day was I got increasingly frustrated and spent much of the afternoon yelling at lightbulbs. Echo didn’t do a great job of understanding the difference between “off” and “on” when I spoke unless I over enunciated, and there was some trial and error on picking names I could say quickly and clearly enough that Alexa wouldn’t garble it horribly.

I also found that I really didn’t WANT to talk to my home for trivial shit like turning lights on and off when appropriate. What I actually wanted was my home to figure out – or at least be programmed to follow – my patterns. For example, if I get up between midnight and 6 AM, I wanted my home to know that I was probably going to the bathroom and so to turn on the lights in my bedroom and bathroom to 5% illumination and the color red, so I wouldn’t wake up more than I had to and wouldn’t wreck my night vision/give myself a headache with bright white lights. I wanted my home to know that if I’m moving around in my bedroom between 6 AM and midnight, that probably means I want lights on, normal brightness and soft-white, but only if the room isn’t already pretty well lit. I wanted my house to know that, if I went into the kitchen in the morning, I wanted lights on, I wanted it to tell me the weather, and then ask me if I also wanted to hear the news, without me having to say anything.

In short, it turns out I want a home that anticipates my needs rather than requiring me to micromanage it. At the time, there really wasn’t much on the market that would let me set that up, and what pieces of the puzzle out there that did exist, didn’t talk well to one another.

Doing what any good nerd will do, I started thinking up a system that would let me have everything I wanted and that would let me use any piece of tech that I wanted without having to worry too much about compatibility. My first plan was built around the idea of sensor hardware – motion, light and light level detection – that would send some kind of signal over some protocol or another (Bluetooth, wifi, radio, whatever) to a central device that would then have a set of rules on it for what to do with whatever sensor info came in, and would then translate those rules into API calls to things like my Hue lights or any other system that would take various actions. The idea was to set up sensors around my home that would talk to the central device and have it issue the commands to the actuators, rather than me, verbally, having to do so.

I started to take a few steps toward this – I couldn’t find any good motion sensors out there that weren’t either completely locked down (no way to pick up their signals) or hideously expensive or both – so I started to teach myself some electronics stuff, and settled on adding some motion sensors to an Arduino. Initially I added a wifi adapter to the Arduino, but that was not terribly practical – the adapter cost more than the Arduino, required constant power (so, wall power) rather than a battery to keep alive, and all that jazz. I eventually settled on RF transmitters and started putzing around with building a mesh network of Arduini and them hopefully reporting back to a main hub that would then report the info to something in the middle.

Unfortunately, life got in the way – I sold my place in the city and bought a farm out in the country, and that move ate up all discretionary time that I had. I also changed jobs, which further ate up all of my “learning new stuff” energy as I familiarized myself with the new stack and such. I’m now at a point where I’m feeling a little less slammed, and bonus, it’s winter, so doing a bunch of stuff indoors is quite appealing.

Down side is that I haven’t gotten my electronics workshop set up again, but I can at least start tackling the software side of things. A couple of days ago I got the Raspberry Pis I decided to use as the centerpiece of this project set up, and now my goal is to get the software pipeline set up of taking in a signal and spitting out an API call.

Ultimately, this brain portion is going to be a kind of universal translator, and the first one I’ve built, so I decided to name her Hoshi.

How to bake a Raspberry Pi

When they first came out, I picked up a couple of Raspberry Pi 3 model B kits out of curiosity. I set up one of them and tooled around for a few minutes. It was pretty decent – I was able to play videos and stuff on it, and do a little surfing, but I didn’t really have a project in mind, or more than the most basic *nix knowledge to do anything useful with it, so I stopped tinkering with it and haven’t used it since.

Recently, however, I had the inkling of an idea for a project that would require a reasonably capable computer at the heart of it, and the Pi seemed like a perfect fit. This morning I dusted off my Pis and got them up and running again, using the following steps:

0. Smoke tests: I used a micro USB cable connected to a charger I have laying around, and that worked fine for powering the Pis. After plugging in a mouse and keyboard, I hooked the Pi to my tv and voila, it was up and at the desktop pretty quickly. I connected to my wifi and made sure I could hit the web and stuff like that. Everything was working as expected.

1. Host Name and Password: Since IP addresses can change, I want to be able to remote into my Pis by name, which won’t change. I also wanted to change the Pi user password from the default to something more secure.

First, I changed the name of my Pis by following howtogeek’s guide, and picked something memorable.  After rebooting, I went to a terminal and changed my password using the passwd command, followed by a reboot.

2. Wifi: Once I rebooted, my Pi didn’t automatically reconnect to my wifi. I want my Pis to always connect to wifi so that I’m able to remote into them without having to manually reconnect to wifi – who wants to break out the keyboard and mouse and all that noise?

Using the fine tutorial by adafruit, I set my Pis to automatically connect to my wifi. Now when my power goes out or I reboot or whatever, they will automatically reconnect. Partial yay!

Partial because automatically connecting is just part of the problem – some versions of the Pi are known to go into a sleep mode/power save mode wherein they will shut down their wifi if the network has been inactive for too long, so I needed to fix this as well. For that, I decided to make a cron job to have it ping something every minute or so, which should keep it alive. A bit of googling and some judicious use of man pages lead to the following solution. In a terminal window, I typed:

sudo crontab -e

which opened an editor that allowed me to create a cron job. In the editor, I added in the following line at the bottom:

* * * * * ping -c1 8.8.8.8 > /dev/null 2>&1 &

This says, basically  “every minute send one ping and one ping only to 8.8.8.8 and don’t bother worry about the response, and do all this in the background.” 8.8.8.8 is, I believe, one of Google’s name servers, just FYI. I saved and exited the editor, and then entered:

sudo crontab -l

This gave me a list of the cron jobs on my Pi, and I was able to confirm that the one I had added was indeed there. Then I rebooted, not because I needed to for the cron job to run, but because I wanted to make sure that my wifi would auto connect and that my ping would run even after a reboot:

reboot

When the system came back online, I went into a terminal and typed:

grep "ping" /var/log/*

which yielded a list of all the times “ping” showed up in any log file – I was looking for the ping I’d entered as a cron job and it did in fact show up. Success! Now I should be able to always remote into my Pis.

Because my Pis are now accessible through wifi, I was able to do the remaining steps by remoting in to the Pi from my laptop, which was much more convenient.

3. Updates: There were probably some updates in the 2ish years since these Pis were bought, and I figured I should update my OS to be as current as possible. At a terminal I entered the following:

sudo apt-get update
sudo apt-get dist-upgrade

Running the first command took about a minute, and the second took a longish time (30 minutes or so?) because I have crappy internet (I’m out in the boonies) and it needed to pull down a number of files. Once this finished and I rebooted, my Pis were now up to date.

4. Boot to Command Line: Since I will be remoting in all the time, I don’t need a graphical desktop on my Pis, and I definitely don’t need the overhead of having the desktop. Finally, I wanted to make sure that nobody who happened to take my Pi would be able to use it without knowing the password – by default the Pi boots to the desktop already logged in. That’s bad.

At a terminal window I entered:

sudo raspi-config

and followed the handy menu that came up to set it so that my pi will boot to the command line only and not log me in automatically, and I can still remote in as per usual.

NOW I’m finally ready to get to work on my project!