オフィス内の複数の画面に監視機能を備えたダッシュボードを表示する必要がありました。 いくつかの古い Raspberry Pi Model B + と、ほぼ無制限のリソースを備えたハイパーバイザーがあります。
どうやら、Raspberry Pi Model B+ には、ブラウザを常に実行して大量のグラフィックスをレンダリングし続けるのに十分なランダム性がありません。そのため、ページが部分的にバグが発生し、頻繁にクラッシュすることが発生します。
かなりシンプルでエレガントな解決策がありましたので、それを共有したいと思います。
ご存知のとおり、すべての Raspberry にはかなり強力なビデオ プロセッサが搭載されており、ハードウェア ビデオ デコードに最適です。 そこで、別の場所でダッシュボードを備えたブラウザを起動し、レンダリングされた画像を含む既製のストリームをラズベリーに転送するというアイデアが思いつきました。
さらに、この場合、すべての構成が XNUMX 台の仮想マシン上で実行されるため、管理が簡素化され、更新とバックアップが容易になります。
否や言うほどない。
サーバー部
準備完了を使用します
新しい仮想マシンをデプロイし、まずそこにインストールします
apt-get update
apt-get install -y xserver-xorg nodm fluxbox
sed -i 's/^NODM_USER=.*/NODM_USER=ubuntu/' /etc/default/nodm
Xorg の設定も使用しますので、よろしくお願いします。
cat > /etc/X11/xorg.conf <<EOT
Section "Device"
Identifier "device"
Driver "vesa"
EndSection
Section "Screen"
Identifier "screen"
Device "device"
Monitor "monitor"
DefaultDepth 16
SubSection "Display"
Modes "1920x1080" "1280x1024" "1024x768" "800x600"
EndSubSection
EndSection
Section "Monitor"
Identifier "monitor"
HorizSync 20.0 - 50.0
VertRefresh 40.0 - 80.0
Option "DPMS"
EndSection
Section "ServerLayout"
Identifier "layout"
Screen "screen"
EndSection
EOT
systemctl restart nodm
ここで Firefox をインストールし、システム サービスとして実行します。そのため、まずそのためのユニット ファイルを作成します。
apt-get install -y firefox xdotool
cat > /etc/systemd/system/firefox.service <<EOT
[Unit]
Description=Firefox
After=network.target
[Service]
Restart=always
User=ubuntu
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/ubuntu/.Xauthority"
ExecStart=/usr/bin/firefox -url 'http://example.org/mydashboard'
ExecStartPost=/usr/bin/xdotool search --sync --onlyvisible --class "Firefox" windowactivate key F11
[Install]
WantedBy=graphical.target
EOT
systemctl enable firefox
systemctl start firefox
Firefox を全画面モードですぐに実行するには、Xdotool が必要です。
パラメータの使用 -url
ブラウザの起動時に自動的に開くように任意のページを指定できます。
この段階でキオスクの準備は完了しましたが、ここで画像をネットワーク経由で他のモニターやデバイスにエクスポートする必要があります。 これを行うために、私たちは可能性を利用します
そのためには次の XNUMX つのことが必要です。
apt-get install -y make gcc ffmpeg
cd /tmp/
wget https://github.com/ccrisan/streameye/archive/master.tar.gz
tar xvf master.tar.gz
cd streameye-master/
make
make install
cat > /etc/systemd/system/streameye.service <<EOT
[Unit]
Description=streamEye
After=network.target
[Service]
Restart=always
User=ubuntu
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/ubuntu/.Xauthority"
ExecStart=/bin/sh -c 'ffmpeg -f x11grab -s 1920x1080 -i :0 -r 1 -f mjpeg -q:v 5 - 2>/dev/null | streameye'
[Install]
WantedBy=graphical.target
EOT
systemctl enable streameye
systemctl start streameye
私たちの画像は高速更新を必要としないため、リフレッシュ レートを次のように指定しました: 1 フレーム/秒 (パラメーター -r 1
) および圧縮品質: 5 (パラメータ -q:v 5
)
さあ、行ってみよう
クライアント部分
ここでは、先ほども言ったように、Raspberry Pi Model B + を使用する方がまだ簡単です。
まずはインストールしてみましょう
また、ビデオ チップにより多くのメモリを割り当てる必要があります。これについては、 /boot/config.txt
gpu_mem=128
新しいシステムを起動しましょう。pacman キーリングを初期化することを忘れずに、インストールしてください。
pacman -Sy omxplayer
驚くべきことに、OMXPlayer は X がなくても動作するため、ユニット ファイルを作成して実行するだけで済みます。
cat > /etc/systemd/system/omxplayer.service <<EOT
[Unit]
Description=OMXPlayer
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/omxplayer -r --live -b http://your-vm:8080/ --aspect-mode full
[Install]
WantedBy=multi-user.target
EOT
systemctl enable omxplayer
systemctl start omxplayer
パラメータとして -b http://your-vm:8080/
サーバーから URL を渡します。
これだけで、サーバーからの画像が接続された画面にすぐに表示されるはずです。 問題が発生した場合、ストリームは自動的に再起動され、クライアントはストリームに再接続します。
おまけに、得られた画像をスクリーンセーバーとしてオフィス内のすべてのコンピューターにインストールできます。 このために必要となるのは、
mode: one
selected: 0
programs:
"Monitoring Screen" mpv --really-quiet --no-audio --fs
--loop=inf --no-stop-screensaver
--wid=$XSCREENSAVER_WINDOW
http://your-vm:8080/ n
maze -root n
electricsheep --root 1 n
これであなたの同僚はとても幸せになるでしょう 🙂
出所: habr.com