LoginSignup
21
25

More than 3 years have passed since last update.

Raspberry Pi3B+をキオスクモードで使う (2019年11月版)

Posted at

はじめに

ひさしぶりにRaspberryPiを触る時間ができたので、以前の記事「Raspberry Pi3でキオスク端末(自動ログイン+ブラウザ起動)を作る。」を2019年11月時点の内容に書き直ししました。

環境

  • Raspberry Pi3B+
  • Raspbian Buster with desktop (2019-09-26-raspbian-buster.img)

公式サイトからではなくミラーサイト http://ftp.jaist.ac.jp/pub/raspberrypi/ からイメージファイルをダウンロードすると早いです。もし公式サイトで更新された日付より7日以上経過している場合、ミラーサイトから取得することをおすすめします。(7日以内だとミラーサイトに反映されていないことがあるようです)

設定

初期設定

  • OSイメージをダウンロードして、SDカードに展開
  • SDカードをRaspberryPiに刺して電源投入

apt

取得先を変更

取得先を国内のミラーサーバー(RaspbianMirrors)にある日本国内のサーバー(JAIST)に変更します。

sudo vi /etc/apt/sources.list
/etc/apt/sources.list
- deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
+ #deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
+ deb http://ftp.jaist.ac.jp/raspbian buster main contrib non-free rpi

apt IPv6の無効化

もしIPv6環境内ではなくIPv4環境のみ使う場合、下記の設定をします。IPv6がちゃんと設定されていない環境の場合、aptの更新取得が遅くなることがあるようです。

echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4

apt 更新を取得

更新をして再起動します。

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo reboot

一時的にIPv6を無効化する場合は、aptのオプション-o Acquire::ForceIPv4=trueを追加して強制的にIPv4でアクセスするようにします。(例:sudo apt update -o Acquire::ForceIPv4=true)

WiFi用に国コードを設定する

WiFiを使用する場合は設定が必要です。WiFiを使う場合は、/boot/wpa_supplicant.confをつかったほうがいいかもしれません。

sudo raspi-config nonint do_wifi_country JP

GUI関連

解像度

使用しているモニターの出塁などによって解像度などが変わるのですが、若干小さめに描画エリアが設定されるようです。モニターの解像度をすべて使って表示する場合、disable_overscanを設定します。

/boot/config.txt
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
- # disable_overscan=1
+ disable_overscan=1

カーソルを消す

/etc/lightdm/lightdm.conf
- # xserver-config=
+ xserver-config= X -nocursor

上記の方法では全くカーソルが表示されなくなります。動いていない場合にマウスカーソルを消したい場合はunclutterを使ったほうがいいかもしれません。

chronium 自動起動

ブラウザを自動起動するために/etc/systemd/system/chromium-autorun.serviceファイルを新しく作ります。

/etc/systemd/system/chromium-autorun.service
[Unit]
Description=Chromium Autorun

[Service]
Environment=DISPLAY=:0.0
Environment=XAUTHORITY=/home/pi/.Xauthority
#ExecStartPre=/home/pi/kiosk-setting.sh
ExecStart=/usr/bin/chromium-browser --noerrdialogs --disable-infobars --disable-background-mode --kiosk --app=https://youtube.com/
Restart=on-abort
User=pi
Group=pi

[Install]
WantedBy=multi-user.target

ExecStartのオプション指定について (起動オプション - Google Chrome まとめWiki)

  • /usr/bin/chromium-browser chromiumブラウザのパス
  • --noerrdialogs エラーダイアログを表示しない
  • --disable-background-mode バックグラウンドモードを無効
  • --kiosk Kioskモードで起動
  • --app=https://youtube.com/ アプリケーションモードとして指定されたURLを表示する

chromiumの--app=<URL>、全画面モード(F11)のような感じで表示されます。Raspberry Piの電源が強制的に切られてしまった後に再起動すると「『Chromeは正しく終了しませんでした』復元しますか?」とか表示されなくなります。廃止されたオプション--disable-infobarsの代わりに使用。

端末情報の表示

複数台設置したときに、端末情報(IPアドレスなど)が知りたいときがあります。ip addr showでインターフェース情報を取得しテキストファイル出力、leafpadで表示しています。必要がない場合は不要です。

  • 1つ目のsleep 20はleafpadを出力するためのX起動待ち。
  • 2つ目のsleep 10はleafpadを見せる時間(=経過後、chromiumが起動する)
~/kiosk-setting.sh
#!/bin/bash
sleep 20 
ip addr show > ~/ip.txt
DISPLAY=:0.0 leafpad ~/ip.txt &
sleep 10 

念の為に起動時に前回のセッション情報を消しているのですが、chromiumの--app=<URL>オプションを使う場合、必要ないかもしれません。

crontab
@reboot rm -rf ~/.config/chromium/Singleton*

自動起動の設定

sudo systemctl enable chromium-autorun.service
sudo systemctl start chromium-autorun.service

おわりに

前回の記事と大きく異なるとすれば、aptの設定変更、chromeinumのオプション指定内容が変わった感じでした。

21
25
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
21
25