r/HomelabJapan • u/c00750ny3h • 6h ago
OPENVPN connect indicator LED project
Hey all, if it is OK, I would like to share a project I made.
Background
I use a openvpn to access all of my home network stuff, including immich photo server, NAS storage and even my cat cameras. I also grant family members and relatives access to my VPN to access the immich server and some other things.
However though, I still want some kind of a physical indicator when someone connects to VPN server and not just sorting through the logfile everytime to see who was on and when. I decided to set up an RGB LED indicator light whose color would light up according to whichever client was connected and shut off when the client disconnected.
The setup
The openvpn server was installed on the openwrt router itself. Openvpn would run a bash script every time a client connected or disconnected. The bash script would run a Curl command to an arduino which controlled the LED.
The items needed are
-OpenWRT compatible router with openvpn and Curl installed, in my case I used a bananapi bpi r4
-wiznet w5500 ethernet socket to serial pins converter board, can get this for about 600 yen off aliexpress or 3000 yen off Japan amazon
-Arduino UNO, maybe like 3000 yen ish? There are many cheaper imitation boards that function just as well.
The final device is in these pictures.


The ethernet port board is a wiznet w5500 board, and the board on the right with the anime girl is a knockoff arduino UNO.
OPENVPN server config file
user nobody
group nogroup
dev tun
port 2064
proto tcp
server 192.168.9.0 255.255.255.0
topology subnet
client-to-client
keepalive 10 60
persist-tun
persist-key
tun-mtu 1280
mssfix 1240
cipher AES-128-GCM
push "dhcp-option DNS 192.168.9.1"
push "dhcp-option DOMAIN lan"
push "redirect-gateway def1"
push "persist-tun"
push "persist-key"
script-security 2
client-connect /etc/openvpn/Scripts/OVPNConnect2064.sh
client-disconnect /etc/openvpn/Scripts/OVPNDisconnect2064.shThe above is the openvpn server configuration file. For the most part, the options are just the default settings of openvpn but the options I added are script-security 2 client-connect and client-disconnect. This option will cause openvpn to execute the corresponding bash scripts in the corresponding directory.
Openvpn connect and disconnect scripts
Here is /etc/openvpn/Scripts/OVPNConnect2064.sh
#!/bin/sh
curl "http://192.168.1.177/?2" || true
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
echo "IP: ${trusted_ip} TIME: ${timestamp} Port 2064 (RED) CONNECT" >> /mnt/sda1/opnvpnlog
#Dont forget to set chmod 777 on logfilethe bash script that executes whenever a client connects.
and /etc/openvpn/Scripts/OVPNDisconnect2064.sh
#!/bin/sh
curl "http://192.168.1.177/?5" || true
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
echo "IP: ${trusted_ip} TIME: ${timestamp} Port 2064 (RED) DISCONNECT" >> /mnt/sda1/opnvpnlog
#Dont forget to set chmod 777 on logfilethe bash script that executes whenever a client disconnects.
First, curl will send an http query to the local address with ?2 as the tcp data. When disconnecting, the ?5 tcp data is sent (more on this below). The || true is so that in case the destination network address somehow fails, i.e. the LED is malfunctioning, the openvpn will still allow a connection. The lines beginning with timestamp and echo are just logging the IP and time whenever a client makes a vpn connection or disconnection.
The arduino UNO and wiznetw5500 chip
The wiznet w5500 board needs a 5V and a ground connection to be powered on. You can simply connect the 5V and ground pin from the arduino to the wiznet.
The wiznet w5500 pins must be connected to certain pins on the arduino. They are as follows:
| Wiznet W5500 pin | Arduino Pin |
|---|---|
| CS - Chip select | Pin 10 |
| MOSI - Master our slave in | Pin 11 |
| MISO - Master in slave out | Pin 12 |
| SCLK - SPI clock | Pin 13 |
Finally, the code for the arduino to handle the incoming
Since the code for the arduino, I will only codeblock the important parts in the post.
The entire code can be found at my github.
https://github.com/TimOfAllTrades/ArduinoStuff/blob/main/vpnindicatorLight2_FINAL.ino
byte ip[] = { 192, 168, 1, 177 }; //Manual setup only
byte gateway[] = { 192, 168, 1, 1 }; //Manual setup only
byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server = EthernetServer(80); //port 80 Lines 8 to 16: Here you can specify your ip address, gateway and subnet.
if(reading){
Serial.print(c);
SentData +=c;
switch (c) {
case '2':
//add code here to trigger on 2
digitalWrite(5, HIGH);
break;
case '3':
//add code here to trigger on 3
digitalWrite(6, HIGH);
break;
case '4':
//add code here to trigger on 4
digitalWrite(7, HIGH);
break;
case '5':
//add code here to trigger on 5
digitalWrite(5, LOW);
break;
case '6':
//add code here to trigger on 6
digitalWrite(6, LOW);
break;
case '7':
//add code here to trigger on 7
digitalWrite(7, LOW);
break;
}
}The code block for lines 85 to 116: Here the program will decide what to do depending on the tcp data received. If the TCP data received was simply the number 2, like from the curl command in the Connectscript2064.sh, this would cause the 5 pin on the Arduino to set a high voltage state. In the case that the TCP data was the number 5, this would cause that 5 pin to short to ground. The LED lights up when the 5 pin is in the HIGH state and is off when the 5 pin is the LOW state.
While this project isn't that great, what I hope I can do is show a way to interface the open vpn software with a output compatible with breadboard electronics. If you are EE savy enough, you don't have to limit yourself to an LED. With some mosfets, you could probably use that 5V arduino output to toggle larger electronic devices, like speakers or other things.
Any comments, criticisms or improvements is highly welcomed.