WIFI/Network status LED

I’m setting up my first Volumio project based on Raspberry Pi 5 and have a question: my goal is to add a few LEDs to the front panel for signaling purposes. Power is straightforward, and I was also able to map the Raspberry Pi’s Act LED to an external one (using dtparam in userconfig.txt), and it works fine.

However, I also need something to signal whether I have a connection to Wi-Fi or even to the network. Here’s my question: How can I achieve this?

  • I reviewed plugins and found some for controlling GPIO, but they seem to be for switches, not outputs. Is there something ready to work for my needs?
  • I also found similar topics with solutions based on bash scripts. For example, this one: https://forums.raspberrypi.com/viewtopic.php?t=96453
    However, it seems that my Volumio setup is unable to configure GPIO from the script level. When I try:
volumio@volumio:~$ echo "16" > /sys/class/gpio/export  
-bash: echo: write error: Invalid argument

ChatGPT suggested installing WiringPi as a possible solution, but I’m not sure if it will work with Volumio.

Any advice or suggestions would be much appreciated!

with the rPi5 addressing GPIO has completely changed.
There is one plugin to control leds called GPIO Control, however it doesn’t have Network functionality.

I found GPIO Control (only buttons, no outputs) and smaller GPIO Buttons (only few buttons, also no outputs).Script based idea seems to be ok, but how to make gpio working from bash level.
I have tried to install wiringpi, but it also doesn’t work.

Always love a discussion, but read the opening post from GPIO Control:

Ok, my fault, I was too fast with checking. But as you wrote, it doesn’t support such functionality like network availability [quite obvious anyway, should be added]

You can always request it in the correct topic.
But if it is that obvious… I think your the 1st or 2nd person that request this.

Maybe I’ll write it different: it should be obvious. Clear visual indication if there is a network available or not. Should be useful, isn’t it? Ok, I’ll write in that topic.

Uuuupsss… So maybe any “free” output port that can be operated via a script? I’m asking because I’m currently polishing my first Volumio device, and my idea was to add some LED indicators to show simple things like power or RPi activity. These were simple to set up, but then I tried to add a “WiFi on” LED and got stuck here. I have no idea how to control GPIO output via a script in Volumio.

Moved your last posting back to here, to keep pollution out of the GPIO Control plugin.
In bash you could try this:

sudo apt-get update && sudo apt-get install gpiod
cd ~
mkdir scripts && cd scripts
nano network.sh

This example uses gpio9 on a rpi5. Copy and paste content.

#!/bin/bash

GPIO=9
while true;
do
	ping -c 2 www.google.com > /dev/null
	if [ $? != 0 ]
	then
		echo "Your site seems to be down"
		gpioset gpiochip0 ${GPIO}=0
	else 
		echo "Your Site is up"
		gpioset gpiochip0 ${GPIO}=1
	fi
	sleep 5
done

CTRL+0 => Enter => CTRL+x
chmod 777 network.sh

Check it:

volumio@rpi5-ws1280:~/scripts$ gpioget gpiochip0 9
0
volumio@rpi5-ws1280:~/scripts$ bash network.sh
Your Site is up
volumio@rpi5-ws1280:~/scripts$ gpioget gpiochip0 9
1
volumio@rpi5-ws1280:~/scripts$

image

to run it as service.

sudo nano /lib/systemd/system/network_gpio.service

Copy paste:

[Unit]
Description=network_gpio Plugin
Wants=volumio.service
After=volumio.service
[Service]
ExecStart=/bin/bash /home/volumio/scripts/network.sh

[Install]
WantedBy=multi-user.target

sudo chmod 644 /lib/systemd/system/network_gpio.service && sudo systemctl daemon-reload && sudo systemctl enable network_gpio.service && sudo systemctl start network_gpio.service

First of all - thanks, it gives a hope. Nevertheless, it doesn’t work in my case. Script as such is ok, gives answer, but GPIO state is still down:

volumio@volumio:~$ cat network_status.sh 
GPIO=16
while true;
do
        ping -c 2 www.google.com > /dev/null
        if [ $? != 0 ]
        then
                echo "Your site seems to be down"
                gpioset gpiochip0 ${GPIO}=0
        else 
                echo "Your Site is up"
                gpioset gpiochip0 ${GPIO}=1
        fi
        sleep 5
done

volumio@volumio:~$ gpioget gpiochip0 16
0
volumio@volumio:~$ bash network_status.sh 
Your Site is up
Your Site is up
Your Site is up
^C
volumio@volumio:~$ gpioget gpiochip0 16   
0

Try different GPIO, seems this one is being used already. Move to GPIO23 or GPIO24.
This is not a script problem.

Check with commands:

gpioset gpiochip0 23=0
gpioget gpiochip0 23
gpioset gpiochip0 23=1
gpioget gpiochip0 23

gpioinfo gpiochip0

image

I tested 23, your 9 and situation looks the same. Additionally I tried to read status of GPIO26, where I have mapped Act LED, so this GPIO is really busy: in this case I have clear answer:

volumio@volumio:~$ gpioget gpiochip0 26
gpioget: error reading GPIO values: Device or resource busy

I tried also to manually change state of GPIO using command from script and it also doesn’t work:

volumio@volumio:~$ sudo gpioset gpiochip0 23=0
volumio@volumio:~$ gpioget gpiochip0 23       
0
volumio@volumio:~$ sudo gpioset gpiochip0 23=1
volumio@volumio:~$ gpioget gpiochip0 23       
0
volumio@volumio:~$ 

line 23: "GPIO23" unused input active-high

configured as input, how to change?

The set command should already take care of that. Don’t mess with sudo as it’s not needed:
image

gpioset gpiochip0 26=1
image

So in fact type is changing to output:

        line  23:     "GPIO23"       unused   input  active-high 

 volumio@volumio:~$ gpioset gpiochip0 23=1    
 volumio@volumio:~$ 
 volumio@volumio:~$ gpioinfo gpiochip0    
 gpiochip0 - 54 lines:
[...]
        line  23:     "GPIO23"       unused  output  active-high 

But state is still the same:

 volumio@volumio:~$ gpioget gpiochip0 23  
0
 volumio@volumio:~$ gpioset gpiochip0 23=1   
 volumio@volumio:~$ gpioget gpiochip0 23  
0

I’ve connected a LED to GPIO23 and GND.
running below commands turns the LED on/off.
gpioset gpiochip0 23=1
gpioset gpiochip0 23=0

And you have also Rpi 5, right? I found in several places warning that RPi has different chipset for GPIO and it works different than RPi 4, maybe here is a difference? Other hw revision or maybe any software update?

[edit] It seems I reached daily limit of post for new user as me and can’t add next today, so here: problem solved, issue was connected to previous tris with raspi-gpio. After removing both, cleaning atp and installing again gpiod, everything started to work fine.
Thanks for help!

The change for GPIO was between rpi4 and rPi5.
And euh… one moment…
I did start with the rPi5, but then magic happened ending up with a rPi4 :frowning:

Back to the rPi5, test, blinking LED => Works.
while true; do gpioset gpiochip0 24=0; sleep 1; gpioset gpiochip0 24=1; sleep 1;done

Running same script works.
the install lib gpiod is backwards compatible.

cat /proc/device-tree/model
Raspberry Pi 5 Model B Rev 1.0

GPIO Control plugin only does output on the GPIO like LEDs. It does nothing with buttons, these are GPIO input.

It’s possible to add network status, if it’s just a case of running ping -c 2 www.google.com > /dev/null

Not sure what the ask is, but you could run something like this to detect a link beat.
In this case you don’t need to rely on a host. And you can check both wlan as eth.

#!/bin/bash

GPIOA=13
GPIOB=19
GPIOC=26

gpioset gpiochip0 ${GPIOA}=0
gpioset gpiochip0 ${GPIOB}=0
gpioset gpiochip0 ${GPIOC}=0

while true;
do	
eth0=$(/usr/sbin/ifplugstatus | grep "eth0: link beat detected")
wlan0=$(/usr/sbin/ifplugstatus | grep "wlan0: link beat detected")

if   [ "$eth0" ] ; then
	echo "eth0 yes"
	gpioset gpiochip0 ${GPIOA}=1
else
	echo "eth0 no"
	gpioset gpiochip0 ${GPIOA}=0
fi

if [ "$wlan0" ] ; then
	echo "wlan0 yes"
	gpioset gpiochip0 ${GPIOB}=1
else
	echo "wlan0 no"
	gpioset gpiochip0 ${GPIOB}=0
fi
sleep 5
done