Skip to content

Commit 6004263

Browse files
luci-app-ledtrig-ping: add ping-based LED trigger
Add LED trigger driven by ping (on = reachable, off = unreachable). - LED trigger plugin (ping target + check interval) on System -> LEDs - Procd service and script; ucitrack reload on system config change - PKG_VERSION 1.0.0, PKG_RELEASE 1 Closes: #8309 Signed-off-by: smartcoder0777 <smartcoder0215@gmail.com>
1 parent a4117e8 commit 6004263

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (C) 2025 OpenWrt LuCI community
3+
#
4+
# This is free software, licensed under the Apache License Version 2.0.
5+
#
6+
7+
include $(TOPDIR)/rules.mk
8+
9+
LUCI_TITLE:=LuCI LED trigger: ping target
10+
LUCI_DESCRIPTION:=LED trigger that indicates reachability of a host (on = reachable, off = unreachable).
11+
LUCI_DEPENDS:=+luci-base
12+
13+
PKG_VERSION:=1.0.0
14+
PKG_RELEASE:=1
15+
PKG_LICENSE:=Apache-2.0
16+
PKG_MAINTAINER:=LuCI community <luci@lists.openwrt.org>
17+
18+
include ../../luci.mk
19+
20+
# call BuildPackage - OpenWrt buildroot signature
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
'require baseclass';
3+
'require form';
4+
5+
return baseclass.extend({
6+
trigger: _('Ping target (userspace)'),
7+
description: _('The LED indicates reachability of a host by blinking on success and off on failure.'),
8+
kernel: false,
9+
addFormOptions: function(s) {
10+
var o;
11+
12+
o = s.option(form.Value, 'target', _('Ping target'),
13+
_('Host or IP address to ping for LED state.')
14+
);
15+
o.placeholder = '8.8.8.8';
16+
o.rmempty = false;
17+
o.modalonly = true;
18+
o.depends('trigger', 'ping');
19+
20+
o = s.option(form.Value, 'interval', _('Check interval (seconds)'),
21+
_('How often (in seconds) to check reachability.')
22+
);
23+
o.placeholder = '5';
24+
o.datatype = 'uinteger';
25+
o.rmempty = true;
26+
o.modalonly = true;
27+
o.depends('trigger', 'ping');
28+
}
29+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
START=21
4+
STOP=10
5+
USE_PROCD=1
6+
7+
start_service() {
8+
procd_open_instance
9+
procd_set_param command /usr/libexec/ledtrig-ping
10+
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
11+
procd_close_instance
12+
}
13+
14+
service_triggers() {
15+
procd_add_reload_trigger "system"
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
# LED trigger: ping target. Reads UCI system.@led[], for each with trigger=ping
3+
# sets LED to "none" and drives brightness by pinging the configured target.
4+
5+
LEDS_PATH="/sys/class/leds"
6+
CHECK_INTERVAL=5
7+
8+
while true; do
9+
for sec in $(uci show system 2>/dev/null | sed -n 's/^system\.\([^.=]*\)\.trigger=.*/\1/p'); do
10+
[ "$(uci -q get system.$sec.trigger 2>/dev/null)" != "ping" ] && continue
11+
sysfs=$(uci -q get system.$sec.sysfs 2>/dev/null)
12+
target=$(uci -q get system.$sec.target 2>/dev/null)
13+
[ -z "$sysfs" ] || [ -z "$target" ] && continue
14+
[ -d "$LEDS_PATH/$sysfs" ] || continue
15+
16+
echo none > "$LEDS_PATH/$sysfs/trigger" 2>/dev/null
17+
18+
interval=$(uci -q get system.$sec.interval 2>/dev/null)
19+
interval=${interval:-$CHECK_INTERVAL}
20+
[ "$interval" -ge 1 ] 2>/dev/null || interval=$CHECK_INTERVAL
21+
22+
if ping -c 1 -W 3 -q "$target" >/dev/null 2>&1; then
23+
echo 255 > "$LEDS_PATH/$sysfs/brightness" 2>/dev/null
24+
else
25+
echo 0 > "$LEDS_PATH/$sysfs/brightness" 2>/dev/null
26+
fi
27+
done
28+
sleep $CHECK_INTERVAL
29+
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"config":"system","init":"ledtrig-ping"}

0 commit comments

Comments
 (0)