I forget when I'm on the VPN
The COVID-19 breakout has resulted in me working from home for the foreseeable, which means I’m using the work VPN more than I’m used to. Typically I don’t have to use the work VPN as I tend to work in the office most of the time but being at home has me flipping in and out of the VPN a couple of times a day. One thing I keep forgetting about the VPN is whether I’m on it or not. This can cause a minute or two of confusion when I’m trying to access certain things on the Co-op network. There’s a tiny icon on the top left of my screen which indicates if the VPN connection is active or not, but ideally, I would like something a bit more visible. Something that will constantly be in the periphery of my vision at all times. That’s why I spent an evening and a morning putting together a little lightbox which lights up when I’m connected to the VPN and turns off when I’m disconnected from it.
The first task was to come up with a circuit. I decided that I would build a smaller version of my text-clock, just with the text “ON VPN” that would light up like the “ON AIR” signs you see above studio doors.
I threw together a small circuit of six red LEDs with six 220 ohm resistors in parallel, which you can see above. The idea was to have a script that ran on my machine every few seconds and sent either a “1” or a “0” to the Arduino via the Arduino’s serial port, depending on whether the VPN connection was active or not. The Arduino would then turn on the LEDs if the connection to the VPN was active, and turn them off if not.
The above code is what is loaded onto the Arduino. The python script that will run on my machine is below:
Initially, I wanted to run this script every few seconds via a cronjob or something, however, it turns out every time you initiate a connection to the Arduino via the serial port, the Arduino restarts losing all previous state. This wasn’t going to work for this scenario so I decided to instead write a script that would connect to the Arduino at the beginning and then loop “forever”.
The code which determines whether or not the machine is on the VPN isn’t particularly sophisticated. It runs
ifconfig and greps the result for
utun2 which is present in the
ifconfig output when connected to the VPN. If
utun2 is in the output
ifconfig then it writes “1” to the Arduino, which turns the lights on, otherwise, it writes a “0” to the Arduino, which turns the lights off.
Once that was all working I got started on making this solution (if you can call a terrible hack a solution) a bit more permanent.
I didn’t want the lightbox to be much bigger than the Arduino Nano so I used my smallest stencil and stencilled out the letters “ON VPN”. These letters were cut out from the paper, creating some negative space for the light to come through.
Next, I got started on the frame to hold everything together. One of the things I learnt when making the text-clock was that when the LEDs are pointing out the light doesn’t disperse very well. The plan was to have the LEDs point inwards so that the light wouldn’t come through the letters as harshly as they do currently on my text-clock.
I cut some scraps of paper and got to work soldering (which I’m still terrible at btw) and hot glueing.
Once I had a basic frame in place I hooked up the resistors to the positive leads and hooked this circuit up to the Arduino to check everything was working as expected.
Once I was happy with how it looked I covered all the exposed wires with a bit of insulation tape and soldered the circuit onto the Arduino Nano. I also mounted the Arduino onto the back of the frame using hot glue.
The last thing to do was to apply the face to the frame. I glued a piece of transparent paper to the back of the wording and wrapped the entire cardboard frame.
This was a nice little project to get myself back into electronics as I hadn’t done any in a while. I’m hoping I can get back into this hobby over the next few months… it’s not like I won’t have the time!