LoginSignup
11
20

More than 5 years have passed since last update.

Raspberry PiをAirPrintサーバ化して、iPadでAirPrint非対応プリンタで印刷するまで

Posted at

iPad用の業務アプリ開発中で、印刷させる必要があるのですが、プリンタがAirPrint非対応なのでラズベリーパイをAirPrintサーバ化しました。
Mac、WindowsPCをサーバ化すればもっと簡単にできそうなのですが、できるだけコンパクトな構成でとのことでしたので・・・
現状は、有線LanでDHCP接続の状態です。

Raspbianインストール

Raspbianダウンロード

公式から最近のRaspbianをダウンロードします。
デスクトップ環境はいらなかったので、LITEの方にしました。
zipだと1時間くらいかかりそうだったので、torrentにしましたが、こっちだと5分くらいで終わりました。

検証

$ shasum 2016-02-26-raspbian-jessie-lite.zip

出力結果とDL元に掲載されている値を比較する。

インストール

名前やサイズから判断して認識されているデバイス確認する。
$ diskutil list
フォーマット
$ diskutil eraseDisk FAT32 RPI /dev/disk2
アンマウント
$ diskutil unmountDisk /dev/disk2
書き込み
$ tar zxvf 2016-02-26-raspbian-jessie-lite.zip
$ sudo dd bs=1024m if=2016-02-26-raspbian-jessie-lite.img  of=/dev/rdisk2

起動

電源刺して起動する。

モニタ、外付けキーボードがない場合

sshで接続するので、モニタはいらないが、IPアドレスがわからないので、MacをDHCPサーバに一時的にする。
LanケーブルをラズベリーパイとMacを接続する。
(Macbook pro 13 late 2013ならこれで繋げられる)
システム環境設定->共有 で設定する。(AX88xはPLANEXのアダプタ。)
スクリーンショット 2016-03-17 13.25.54.jpg

$ arp -a
? (192.168.2.102) at 0:a0:de:31:48:77 on en0 ifscope [ethernet]
? (192.168.2.255) at (incomplete) on en0 ifscope [ethernet]
? (192.168.3.3) at b8:27:eb:2e:67:66 on bridge100 ifscope [bridge]

255は違う。102もたぶん違う。という感じでそれらしいIPアドレスを探す。

sshで接続

$ ssh pi@192.168.3.3

起動後(user:pi pass:raspberry)

$ sudo raspi-config
  • Expand Filesystem
  • Internationalisation Options
    • Change Locale
      • 「en_GB.ISO-8859-15 ISO 8859-15」「ja_JP.EUC-JP EUC-JP」「ja_JP.UTF-8 UTF-8」
      • デフォルト「ja_JP.UTF-8」
    • Change Timezone
      • Asia, Tokyo
$ sudo shutdown -r now

アップデート、アップグレード

sudo apt-get update; sudo apt-get upgrade -y
sudo shutdown -r now

Firewall設定

Port 631はcups用

$ sudo apt-get install -y ufw
$ sudo ufw allow 22
$ sudo ufw allow 80
$ sudo ufw allow 8080
$ sudo ufw allow 631

Apacheインストール

$ sudo apt-get install -y apache2

Webブラウザで、http://(ラズベリーパイのIPアドレス)でApacheの動作確認。

Vimインストール

$ sudo apt-get install -y vim

cups, avahi-discoverのインストール、設定

$ sudo apt-get install -y cups cups-pdf python-cups avahi-discover
$ sudo usermod -aG lpadmin pi
$ sudo /etc/init.d/cups start
$ sudo /etc/init.d/avahi-daemon start
$ sudo vim /etc/cups/cupsd.conf

#Listen localhost:631を下記にする
Port 631

# Allow @Localを入れる
# Restrict access to the server...
<Location />
  Order allow,deny
  Allow @Local
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Order allow,deny
  Allow @Local
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow @Local
</Location>
$ sudo /etc/init.d/cups restart

http://IPアドレス:631 にアクセス。
ラズベリーパイとプリンタを有線で接続しておく。(OS起動前に接続しておいた方がいいかも)
スクリーンショット 2016-03-17 15.04.08.jpg
プリンターとクラスの追加 > プリンターの追加
スクリーンショット 2016-03-17 15.05.32.jpg
プリンタ選択する。
スクリーンショット 2016-03-18 13.14.52.jpg
このプリンターを共有するにチェックを入れる。
スクリーンショット 2016-03-18 13.15.06.jpg
モデルを選択する。
スクリーンショット 2016-03-18 13.21.37.jpg
プリンターを追加して、最後にデフォルトの設定をする。

iPadから印刷。
AirPrint非対応のEPSON PM-G860が選択できています。
スクリーンショット 2016-03-18 13.26.32.jpg

プリンタが選択できても印刷が開始されない場合

これで印刷できる・・・はず

$ sudo /etc/init.d/cups restart
$ sudo /etc/init.d/avahi-daemon restart
11
20
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
11
20