0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ネットワーク送受信とCPU使用率に応じてラズパイ4のLEDを点滅させる

Posted at

www.kernel.org からダウンロードした素のLinuxカーネルの話です(Raspberry Pi OSで使えるか不明)。Linuxでは /sys/class/leds にあるファイルに書き込むとLEDを操作できます。ラズパイ4の場合赤いLEDは /sys/class/leds/PWR, 緑のLEDは /sys/class/leds/ACT に対応します。それらディレクトリの下にある trigger ファイルに何か書くとLEDを点灯する条件を制御できます。条件の一覧は必要なモジュール(ledtrig_netdev.koなどをmodprobeした後に) cat /sys/class/leds/PWR/trigger で出てきますが、それぞれの意味は Kconfig である程度わかります。ここでは

以下のsystemdスクリプトで赤LEDでネットワークip6tnl1の送受信を表示し、緑LEDでCPU使用を表示するようにできます。

/etc/systemd/systemd/leds.service
[Unit]
After=modprobe@ledtrig_activity.service
After=modprobe@ledtrig_netdev.service
After=network-online.target
Wants=modprobe@ledtrig_activity.service
Wants=modprobe@ledtrig_netdev.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo activity > /sys/class/leds/ACT/trigger"
ExecStart=/bin/sh -c "echo netdev > /sys/class/leds/PWR/trigger"
ExecStart=/bin/sh -c "echo ip6tnl1 > /sys/class/leds/PWR/device_name"
ExecStart=/bin/sh -c "echo 1 > /sys/class/leds/PWR/tx"
ExecStart=/bin/sh -c "echo 1 > /sys/class/leds/PWR/rx"

[Install]
WantedBy=multi-user.target
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?