Of nothing in particular

by James Miller

PostedMarch 25th, 2017#Raspberry Pi#MQTT#GPIO#Go

I've wanted to formalize this project for a while and just recently got some free time to do so. gpio-to-mqtt is a Go application that monitors state changes to GPIO pins on a Raspberry Pi and relays those changes as JSON messages to an MQTT broker.

That's a mouthful. Hear me out though.

Say you have an old alarm system in your house that you aren't using. You have the little magnetic reed switches on your windows and maybe some door jamb switches that all run back to a central security system box somewhere in a laundry room, garage, basement, or wherever. With this application, you can repurpose those devices and make them smart. gpio-to-mqtt will notify anyone listening when the those switches are tripped.

All it requires is a Raspberry Pi, a network connection, and Go + gpio-to-mqtt to get running.

Once you have this up and running, you can write any number of utility applications to listen to the broker on your network and perform other actions. Maybe you get a notification every time your front door opens or when someone opens a window unexpectedly. You could even just connect physical buttons to the GPIO pins and use them as network attached buttons.

There is still some development work to be done at this point, a lot of which surrounds additional MQTT options (like the ability to connect using certificates). I'm going to follow this post up with my set up for people to reference if needed. For the time being, here's what my install looks like.

Have fun!

Wired Raspberry Pi


PostedAugust 11th, 2016#Amazon#IoT#AWS

In my last post about hacking Amazon Dash buttons, I mentioned there were some hiccups you would run into when trying to make an ordinary Dash Button work for IoT purposes. Namely, you would get an annoying popup on your phone about how you haven't configured an item to ship when pressed.

Item Not Selected Notification

Annoying...

Sure, there were ways around it, but the tradeoffs weren't things I was willing to deal with.

So it sits on my dryer, awaiting the day I feel like blowing extra cash on detergent...

And then my AWS IoT Button finally shipped. After what, three months? I thought Prime was quicker than that...

AWS IoT Button 1 AWS IoT Button 2 AWS IoT Button 3

Ok, ok, it was a preorder, but still, that was a long wait.

The good news is, it works as you would expect without any annoying popups or other weirdness. At least, none that I ran into.

So how does it work? The process is fairly straight forward.

Overview

After you have the button set up (which I'll go into later), pressing it allows the button to turn on, connect to AWS, and fire off a Lambda function that you configure during set up. For those that don't know, Amazon Lambda allows you specify a block of either Java, Javascript, or Python code that is run in the cloud every time the button is pressed.

This raised at least one obvious question for me. What if the device I want this button to interact with exists on my local network and is not accessible from the greater internet? Unless that device itself has some cloud connectivity, you're going to wind up crafting something custom.

Luckily, the AWS IoT button works the same way the original Dash button works in that when it's pressed, it sends out an ARP request on the local network which can be captured fairly easily. I used the go-dash-button library written by Mike Flynn to do my initial tinkering with the button and it worked just fine.

That being said, there are tons of ways to get this to interact with your local network besides using the ARP request method.

I wanted to integrate the button with my Home Assistant install and as such, I typically use MQTT for sharing messages on my local network. After exposing my MQTT server to the greater web and locking it down, I was able to configure the AWS Lambda function to connect to my home MQTT broker and send a message that Home Assistant could then use for automation.

Setup

This was the part that seemed a little unpolished for me. With the Dash button, the wifi is configured through the Amazon app and is a pretty seemless process if I remember correctly. With the AWS IoT button though, it's a bit different. Not unlike many other IoT devices that require internet connectivity, the button creates its own wifi network that you have to connect to with another device.

Before you even get to that point though, you have to set up your Lambda function within the AWS management console and grab some assorted information (including a certificate and private key) to plug into the button's set up page. This part was a little cumbersome, but not too terrible.

Once you've done that, you are instructed to connect to the device's wifi network and pull up a webpage using the IP of the device to configure it. It looks like this:

AWS IoT Button Set Up

Once that's done though, it's easy to use and modify to your liking. You can simply edit your Lambda code and it'll fire at will when pushed.

A Caveat

I mentioned earlier that the way I got the button to work with my home network was to have my Lambda function connect to a publicly accessible MQTT broker. I wanted to clarify one caveat for why I did that instead of just using the go-dash-button library to send MQTT messages so that I don't have to rely on internet connectivity. The reason I did this is that the AWS IoT button supports three different button pushes: single, double, and long press. If you use the ARP library approach, you just get a notification that it's been pressed (or rather, you get a notification that the button is sending an ARP request as it connects to your local network). That's it. If you want to take advantage of those three different modes, I believe the only way is to use the Lambda approach.

I essentially had the Lambda function send an MQTT message with a payload that specifies how the button was pressed so that my Home Assistant install can make use of all three modes.

A Tip

One tip that I came across for making the button a little bit snappier is to get the button's MAC address and set up an IP reservation with your local DHCP provider. The button would often take between 10 and 20 seconds to connect and execute the Lambda function and after giving it a DHCP reservation, it cut this time down some. It seems that some significant portion of that time was spent negotiating an IP.


PostedJuly 12th, 2016#Amazon#IoT

A lot has been written about how to hack Amazon Dash buttons to do your bidding. When Amazon announced their AWS IoT buttons, I immediately preordered one but I also purchased a regular Dash button to play with in the interim. My first thought about the whole ordeal was "Why buy the $20 IoT button when you can just get a regular dash button for much cheaper and hack it?" Turns out, there is at least one reason...

Reading a lot of blogs about how this is accomplished ahead of time, I got an idea for how it worked. Most made it seem like it was a fairly simple ordeal: Set up the button in the Amazon app but stop short of selecting an item for it to ship and voilà, you can then write a bit of code to monitor your network for button presses.

At the time I did this, none of the articles I read mentioned one particular annoyance with using the button this way. When you set up the button this effectively associates the button with your account. Now that it's associated with your account and because you haven't selected an item yet, the Amazon app will send a push notification to your device every time the button is pressed letting you know you haven't selected an item...

If you're anything like me, that would be incredibly annoying.

Item Not Selected Notification

Sure, you could turn off notifications for the Amazon app but I actually find the notifications it offers kind of useful. So that was a no-go for me. Another suggestion I've seen thrown around recently is to create a separate Amazon account and set it up using that account. That would work fine, but felt kind of overkill for the purpose it was serving for me.

I did take it as far as writing a Go app for toggling our Vera between home and away modes, but the notifications made it less appealing.

At this point I'm just waiting on my IoT button to ship in August and meanwhile using the button to (not) order over priced laundry detergent...


PostedJanuary 28th, 2016#D&D

A few friends of my wife and I have started a D&D campaign recently. I've played once before with some friends but I honestly had no idea what I was doing at the time which means I missed a lot of what makes D&D fun. With podcasts like The Adventure Zone and web series like Titansgrave, it ignited an interest in playing amongst a few of our friends. Now with a better understanding of the game, I was excited to tackle creating a proper character. Mostly though, I was looking forward to writing my character's backstory.

I created Kyrell Amari, an Paladin outlander that was part of a nomadic tribe before their disappearance.

I should point out that I rushed this backstory out over a night with only a few collaborations with my wife about how our character's met (my wife's character is the halfling Jack). That being said, the story is a little rushed towards the end and I'm sure there are plot holes the size of 747's in there.

Whatever though, I'm really happy with how it turned out and I'm actually considering doing some more, unrelated writing since I enjoyed doing it so much.

Kyrell Amari

The first thing you would notice about an Amari would be their stature. A strong tribe, the men and women stood tall and proud alongside each other. As a nomadic people, their stature was not without purpose. It gave them the strength to endure and thrive in the harsh winters and blistering summers they would encounter as they moved about The Realm. One would be wrong to assume their strength is the only attribute which sustains them though. With the ability to quickly adapt to situations, the Amari could use their strength and agility to get out of physical altercations and persuasion and intimidation to navigate complex social situations. It's no wonder the Amari thrived. However, with every sun rise there must also be a sunset and Kyrell walks in the darkness.

Kyrell was your typical Amari. Large in stature with long, braided blonde hair and blue eyes. He enjoyed traveling The Realm and being a part of the Amari tribe let him see it all. There are many Amari rituals that celebrate the transition of a child through different stages of maturity. By far, the most important of those rituals is known simply as The Undertaking. Amari are groomed to be self-sustaining from the day they can walk and The Undertaking is the ultimate test of all of the attributes that make an Amari tribes-person who they are.

At the age of seventeen, all Amari children leave the tribe to live alone in the wilderness. They must sustain themselves and return only after enduring each season in The Realm. During this time, the Amari wanderer is referred to simply as The Lost One. Only after navigating back to the tribe does the wanderer gain the title The Found. Unfortunately, Kyrell may never be Kyrell The Found.

Kyrell becomes The Lost One amongst much fanfare and well-wishes from his family and fellow tribesmen. With only the bare necessities to sustain him, he sets out on his own. The ensuing seasons are harsh. The Deepwinter nights nearly cost him several digits on his hands and feet. The Highsun threatened to dry him to the bone. Still, Kyrell endured. He became The Lost One during Summertide and by Summertide's return he would start his journey back.

The Amari's path through The Realm is predictable, but not entirely. Guided mostly by the stars, they use other means known only to the tribe to deviate slightly from their path to keep marauders from pinpointing their location while still allowing Lost One's to be Found. Kyrell begins his journey by simply gazing into the heavens and reading them like pages in a book. The story of his tribe’s travels is laid out before him and after reflecting on his journey, he takes his first step. A step not only towards finding his tribe, but his first step to becoming Found.

Weeks later, Kyrell nears the location of his tribe and quickly finds the markers they have left behind for him. Approaching their location, Kyrell knows something isn't right. The air has an evil stench about it and is silent. Dead silent. From a distance Kyrell can see that his tribe's campsite is devoid of all life. Everyone is gone.

It is not like the Amari to abandon their campsite. A people of enormous respect for the wilds, they only ever leave footsteps when migrating. Leaving an entire campsite would never happen under normal circumstances. Kyrell knows this and approaches with caution and surveys his people's campsite. The first thing he notices is that it doesn't look like there were signs of a struggle. Indeed, it looks like his tribesmen had no time to react to whatever overtook them. It appears as if they vanished into thin air.

Food and steins of ale for supper are waiting to be consumed. They are still hot. Armor and weapons are in chairs and on the ground where people would have been sitting. Cots are still ever so slightly warm against the cool night air from their now gone occupants.

The air is still.

Kyrell knows danger could still be near and takes refuge in a nearby tree to await whatever befell his tribe's return with no small part of him hoping this is a dream or a misunderstanding. He waits for days and knows the answer.

He will forever be Kyrell the Lost One.

Kyrell wanders The Realm for several years looking for answers anywhere he might find them. He finds only frustration and more questions. How could his tribe disappear into thin air? Was an outsider able to read the stars and their hidden markers to predict their location? Is there a chance they're still alive?

Kyrell's journey is forever changed after discovering a hidden temple deep within the High Forest. An explorer by nature, he easily penetrates deep into the temples inner sanctum. In an attempt to reclaim the temple, trees and plants have begun to take over the walls, floors, and ceilings of every chamber he passes though. The sanctuary, however, is the one exception. The entrance to the sanctuary seems to repel those who are not pure of heart and purpose and though the High Forest is seen as a noble entity to most in The Realm, it is not without flaws. Kyrell passes with ease.

As he approaches what looks like the temple's alter, flecks of light begin radiating from the many runes that adorn the temple. What at first felt like no more than moonlight soon begins to flood into the room in a torrent as he approaches the alter. It's brilliance is blinding. Kyrell begins to make out faint shapes moving in the light that begin to merge into, at first, several figures. Those figures soon coalesce into a solitary figure that dominates his vision, light pouring in from behind it hiding its features, until all at once the light crashes around him to reveal an Archon of Justice.

The Archon speaks to Kyrell in a language he doesn't understand at first. In a flash, he finds himself gasping for air as he feels his mind seemingly explode with activity. As he regains his breath he realizes he's no longer hearing just a forgotten language, he's understanding it.

The Archon tells Kyrell that what has befallen his family is of a truly evil nature and one that threatens many in The Realm. Archon's rarely intervene in affairs in The Realm unless they believe they can influence positive change in an indirect manner. The Archon explains to Kyrell that he will be a vessel for Justice within The Realm and that only through that pursuit will he discover the truth. Kyrell pledges himself to the Archon's cause. As the Archon begins to fade from view, it offers words that cause Kyrell to weep both tears of happiness and fear...

"Know that your tribe is alive but in danger. Neverwinter may hold the key you are looking for..."

The Archon disappears but Kyrell feels its presence with him. He is newly invigorated by his cause but fears what he may find. Bounding out of the temple, he aligns himself with the stars and heads towards Neverwinter.

Kyrell reaches Neverwinter in the late morning on a typical balmy day. His years as a wanderer have taught him to always be on alert for suspicious activity. Being on guard has kept him alive on more than one occasion. On this day, that suspicious activity came in the form of little girl walking alone down a Neverwinter street. A picture of beauty, her blonde flowing hair and dress made her easy to pick out amongst the merchants and street urchins that populated Neverwinter. Kyrell knew that a girl that young alone was asking for trouble and kept an eye on her as she passed and smiled at him.

Almost immediately Kyrell knows she's in danger as three men pass and tail her into an alley. Quickly finding an intersecting alley, Kyrell hides against the wall waiting for the girl and men to pass. They pass without notice. He stays in the shadows and witnesses the little girl hurriedly cast a sleep spell on the men in defense. Only one falls asleep while the others are caught off guard after being attacked by whom they thought was a helpless child. In a panic, the men begin to rush the little girl but not before Kyrell brings swift and absolute justice to the men, seemingly out of nowhere. Even the little girl is surprised and panicked.

"Oooookayyyyyy..." says the little girl, unsure how to process what just happened.

"What are you doing walking alone down an alley like this? Where are your parents?" Kyrell sternly demands.

"This is where I live. I don't have the luxury of parents." she says hurriedly, somewhat fearful of Kyrell.

"Then why aren't you in an orphanage? The street is no place for a girl as young as yourself."

"Mister, I appreciate what you did but an orphanage isn't the place for me. I'll be f..." Kyrell interrupts the girl and throws her onto his shoulder, his pauldrons easily supporting the weight of the tiny girl.

"I don't want to hear it. You're coming with me and we're getting you somewhere safe. There is an orphanage in Neverwinter, right? There's got to be an orphanage around here somewhere..." Kyrell says, unsure of both the task he's just undertaken and whether there's an orphanage anywhere in the vicinity. Kyrell has never been to Neverwinter.

He heads towards the direction he thinks the orphanage is only to feel the little girl leap from his shoulder. Kyrell attempts to grab her wrist and walk with her but the little girl resists with such strength that Kyrell is caught off guard.

"Look, you've got this whole situation wrong. I'm not a little girl." The little girl tugs at her hair and pulls at her dress. In the blink of an eye the little girl has transformed into a halfling man with platinum white hair. Kyrell is stupefied.

"You looked better as a little girl" Kyrell says snidely.

"Funny..." he says sarcastically, "the name is Jack."

"Kyrell Amari, The Lost Child of Archon" he says with pride.

"That's a hell of a name you got there."

"It suits me just fine. Why were you dressed up like a little girl?"

Jack brushed the question off "I'd rather not talk about it."

"In that outfit, I have a hard time believing you were completely unaware of what you were doing when they followed you down that alley. What were you trying to accomplish?"

"Listen, I don't got a lot going for me. I don't have a home, I have no money, I've lost my family... It's just me and this lyre and when music doesn't put food on the table, I have to resort to other means."

"Our pasts are not so different, Jack The Lost One..." Kyrell says in an understanding tone.

"Lost? Yeah, I guess you could say that..."

They sit for a few moments, contemplating the events that have lead them to this point in their lives. Kyrell understands Jack's loss and sympathizes, though he disapproves of these "other means" that Jack employs. Kyrell misses his tribe but sees something buried deep in Jack that he's been longing for. Something he lost when he lost his tribe. Kyrell misses camaraderie and sees potential in Jack's disheveled face.

"Well, I guess the orphanage is out of the question." Kyrell says jokingly.

"That would be awkward, so yes, out of the question"

"I don't have much to offer except my sword and a place by my side. I too am trying to find a place for myself in this world and I could always use some help. Maybe that'll get you off the streets for a while. Besides, being alone in the wilds for months at a time can make you a little... wild? Something like that. It would be nice to have some company."

Jack thinks for a bit but is not quite convinced. "Why would I run off with some random guy I just met?" Jack says.

"Because I lost my family also and if I never see them again, I'd like to know I have someone in this world I can call a friend."

Jack was silent, but he knew in his heart that he felt the same way.

"Alright, but on one condition..." Jack hesitated.

"What's that?"

"I get to hang out on that massive shoulder of yours. Deal?"

"Deal."


PostedAugust 29th, 2015#Alfred#Workflows

One of my favorite apps on OS X has always been Alfred. The number of things you can do with it is crazy and for someone who likes to fiddle with things and streamline cumbersome processes, it really is a godsend.

Over time, I've found some workflows that have been pretty useful and also created some of my own. A lot of them are pretty pointless to share (who wants a workflow to download their kid's daycare pictures? I didn't think so...) but a couple of them are helpful.

I put together a Github repository to store and share them. Right now I only have two in there but I'll add more as I clean some of them up and as others come to me. I've added one that allows you to generate GUIDs on the fly and another that toggles your bluetooth radio.

Generate Guid

It does just what it says on the tin. You can either use a keyword of "guid" which will simply copy a new guid to your clipboard or you can hit the hotkey Cmd+Shift+G and it will copy it to your clipboard and insert it wherever your cursor currently is. I find myself needing unique guids fairly often so this is pretty helpful.

Note: This workflow requires the uuidgen application. I think it was on my machine by default, but let me know if that's not always the case on OS X.

Bluetooth Toggle

This one is also fairly obvious. You can essentially use a keyword of "bt" or Cmd+Shift+B and it will toggle your bluetooth radio. I do this often so using the keyboard is preferable.

Note: This workflow requires the use of the blueutil applicaiton, which can be found here.

James Miller