Using Onion to open my apartment gate
I've bought an Onion and a 433MHz transmitter module with the intention of using it to open my apartments electronic gate using the 'Blynk' app on my smartphone.
I took the idea from the guys at Hack.Lenotta who've done the same using a raspberry pi;
I'm stumped at where to start though, my programming knowledge is basic at best.
I know I'll have to set up a web server on the Onion, and put together a batch file for it to activate.
I can get the gate code from my SDR stick, but how will I program it into the onion and activate it?
Anyone had any experience here?!
If you're going to use Blynk you don't really need to setup a server on the Onion, you just need to write a NodeJS script that will run on the Onion (using the Blynk library) and respond to the inputs sent by the Blynk app on your smartphone (eg: button press).
Blynk works through the Blynk Cloud, this is how the Blynk app on your smartphone and the NodeJS script running on your Onion can communicate with each other.
The sad news here is that NodeJS support on the Onion is still very premature right now. I have been trying to run Blynk on my Onion for some time now but it has some issues, for istance it can't keep itself connected to the Blynk Cloud, so it's pretty much unusable now. The folks over at the Blynk forums are also still waiting for Onion to provide a better NodeJS support.
I have created a garage-door opener with the Onion, using the built-in WiFi interface. Basically I have written a simple Python script (garage.py) that toggles a relay connected to a GPIO pin. Another simple program (GARAGE.sh) executes the command "python garage.py" , so I SSH into the Onion and type
This could easily be accomplished with a simple forms-based web page hosted on the Onion, but I haven't delved into that yet. For now, the above solution is pretty handy, and takes only seconds to execute on my iPhone.
It seems the easy part of this is the actual opening of the gate. A simple bash or python script can run the appropriate commands to send a signal to open a relay/GPIO pin.
The hard part seems to be the connection between phone (as you want to be mobile!) and the onion.
A couple of ways I can think of:
- 1: Use Telegram - It is a messaging app but you can use it to send commands to a device. The device polls Telegram through an API and if a specific command is sent then you can tell it to do something. ie, run a script that opens a gate!
- 2: Use IFTTT maker channel - Its a simple cloud based automation tool. So you can either have an IF This Then That, so if your phone gets to this GPS co-ord then open the gate. Or better would be the DO function of IFTTT which you launch the app and it has specific buttons which you can set, ie button to open gate, button to close. In the background, again the device will need a webhook to poll the API of IFTTT looking for the DO button presses.
Each method relies on polling the API of the service, IFTTT DO function would work better as the command structure of Telegram would mean you'd have to a send a command (ie
/opengate) whereas the DO presents a nice button on an app you press.
As each method relies on polling an API and you'd want it to be fast I reckon you'd want something like poll every second. I dont know if this is possible because I've not used it before!
I did make a post on how to use Telegram for notifications, so you can use this to setup your bots which seems a bit odd at first. https://community.onion.io/topic/499/sending-telegram-messages-via-bots/1