I am using a bridged modem and my Pi 4 as a router. Pi's led is always red. After I set modem in bridge mode, only DSL, (I am using VDSL), Power and LAN leds are on. But "internet" led which indicates there is internet connection is off. So, I want to set Pi4's led as green when internet connection is active, and red when internet is off. Can i do this? Or will it require me to write code? There is a Led Configuration option under System in Openwrt. There are Options like "default-on", "led0", "led1", "mmc0". I don't know how to use them.
No, you won't brick the router through the LED configuration page on LuCI. And even if you could, Raspberry Pis are quite possibly the easiest routers to flash. Just re-image or exchange the SD card.
Do you want the LED to indicate if the Ethernet link between the router and the modem is up, or do you want it to indicate if there's Internet connectivity?
If it's the former, you can do this from the web interface:
Go to LuCI → System → LED Configuration and click Add LED action.
Set Name to anything you want.
Set LED Name to either led0 or led1. I think led0 is the green one, but I could be misremembering.
You can only set a led if it is connected on a available GPIO pin.
I don’t think Pi4 have any GPIO connected led. As far as I know they are all directly hardware controlled and the power LED is definitely hardwired to the 5V power line.
There are two software controllable leds on the pi 4. Led0 and led1. Those should show up in the system by default. I use the netdev trigger on them - in my case, it indicates my vpn traffic.
Other option would be to use hotplug scripts or polling on schedule to change sysfs LED values directly. The notation of "I have internet" is technically composite of having DNS and being able to connect like across the closest sea.
They both use the exact same SoC and run the same set of operating systems (OpenWrt, Raspberry Pi OS, etc). The biggest difference, besides the form factor, is the VL805 xHCI controller hanging off the SoC's 1x PCIe lane in the Pi 4B. But that isn't relevant to the OP's question. The "activity" LED is definitely controllable by writing to files in the /sys/class/leds/led0 directory on both CM4 and Pi 4B.