Recently I had an idea that I wanted to explore: what if I could build a real button and make it trigger ANYTHING using simply an URL (webhook)? In this very quick post, I will walk you through how I managed to build this project in one evening:
See it in action:
Let's start...
The hardware
A physical button
To begin with, I needed an actual physical button (this seems obvious right?). Luckily, I had already ordered on Amazon an "emergency button" a couple of weeks ago. I stumbled upon this cool button and decided to buy in case someday I needed to build something with it. It seems I was right!
Of course, you can have any other button, just make sure it has a latching switch (it's more realistic this way!) but feel free to take any other kind of switches.
The chipboard (the brain)
I am a big fan of the Onion Omega boards. I actually do have a lot of them (you know, just in case). And I use them in each one of my IoT projects, such as my "voice-controlled standing desk" hack.
Hey Google, set my desk to standing mode!
Wassim Chegham ・ Jan 30 '19
For this setup, things are going to be way easier, since we only have 2 wires to connect (solder, coming from the button's switch and going into the Omega2+ pins.
Here is the Fritzing diagram:
If you want to know more about the Onion Omega2+ board, here is a great getting started tutorial.
The Wifi antenna
One thing (which is not mandatory) is to use an external Wifi antenna for the Onion Omega2+ board. This is just in case we encounter any signal loss due to the surface-mounted (SMT) antenna.
For my setup, I used a 6dBi antenna that was lying around inside my toolbox. Just make sure your antenna is compatible with the u.FL connector. If you need more information about how to connect this kind of antennas, I highly recommend reading the Onion guide.
Puting everything together
Finally, we need to connect the micro USB cable to the Omega2+ (to power the board) and get everything tightly positioned inside the button's box:
The software
When it comes to the software part, and as I mentioned this is an easy setup, we can really choose any technology (python, node...) that can communicate with an HTTP endpoint. S for this quick DIY project, I just wrote a quick Shell script to take care of the button behavior. I've added the comments inside the code:
What this code does is basically start a loop and listen continuously for the $PIN
state change. When we press the button, we activate the switch which connects the 2 wires altogether and closes the circuit. When this happens, the Omega 2+ board receives a high voltage (3.3v) in $PIN
. Using the fast-gpio
included package, we can read the state.
- A value of
0
means the button is pressed. - A value of
1
means the button is released.
The rest of the logic is only there to deal with press and lock mode of this particular button, and this is because this button is using a latching switch.
Your turn...
Now, you may be wondering what can you do with this button? Well, to be honest, there are endless use case scenarios to use this button for but basically, any service that exposes an HTTP endpoint (deploy URLs, a serverless API...etc) would be a great candidate!
In case you want to start playing around and hook this button to an API, you can try out the Azure Functions which let you quickly create and deploy your application logic to a serverless environment, see how you can do it.
Let me know in the comments below what would be your use (be creative)?
Enjoy.
Top comments (13)
I've always wanted to build a big red lever that would run "git push".
I mean big. Like, I'd have to mount it on the wall and the hinge would squeal and hiss when you pull it. That would make my job so epic.
This post looks like a great place to get started.
While I worked at a certain consulting agency, every time we did a production deployment we played The Imperial March from Star Wars. Epic stress is better than mundane stress haha.
First shell script line supposed to be
#!/bin/bash
or#!/bin/sh
?Anyway, this looks like a really fun gadget. Wish I could make one myself (don't have the parts and, quite frankly, afraid I'll break them during assembly).
Thanks for sharing!
I'm inclined to believe that
#!/bin/ash
is correct.ash
is the Almquist shell, which is often used in embedded systems because it's small and fast.Ah didn't know that! Thanks! And that does make sense for this application.
This is such a great post and I promise to give it a try! My whole life in tech is finding stuff like this super cool and never following through. But this time will be different, I swear!
Oh wow! I'm so excited to hear that! Please let me know if you need any more details about the setup. I did skip some parts on purpose to keep this post as short as possible. But I am happy to provide even more details if needed.
Looking forward to seeing what you are gonna build 😍
Great little project, thanks for sharing !
Is there a way to connect it using ethernet instead of wifi ? Other than the ethernet board which isn't available right now in my country.
Or maybe another solution is more appropriate ? Not the onion ?
Basically I want a button just like that but connected over ethernet instead of wifi. I saw the module WT32-ETH01 might do the trick ?
Thanks for reading me !
I need those. Lots and lots of those. It's fucking awesome.
Wow! I really need to know more from this Omega2 things... where to buy how to get started? what is the basic setup needed to get this running?
Nicely done! 👏
Thats a great Idea! I'm gonna make one for each app I have, and hook it up with a script to put it into maintenance mode in a hurry.
Oh! Nice idea. I haven't thought about the maintaince mode.