0

BananaPi Zero M2 can be connected on the Lan/Wan with ethernet.

See topic How to enable eth0 on Banana PI ZERO M2

How can we set LEDs embedded into the RJ45 connector ?

1 Answers1

0

Assume:

  • gpio0 is ethernet link status (green)
  • gpio1 is the traffic led (yellow)

Create a simple script like: (if someone want to improve ;-). )

#!/bin/sh
#
#
# This script check the eth0 status (connected or not)
# and set RJ45 LEDs

# TODO: add headers for update-rc.d

LINK=/sys/class/gpio/gpio1/value
TRAFFIC=/sys/class/gpio/gpio0/value
RX=/sys/class/net/eth0/statistics/rx_packets

PRXP=0
LED=0

while [ 1 ];do
    cat /sys/class/net/eth0/carrier > $LINK
    RXP=`cat $RX`
    if [ $RXP -ne $PRXP ];then
        if [ $LED -eq 0 ];then
            LED=1
        else
            LED=0
        fi
        echo $LED > $TRAFFIC
        PRXP=$RXP
    fi
    sleep 0.1
done