Errata‎ > ‎RaspberryPi‎ > ‎

HomePi V3: Apple AirPrint/Play/Homekit on Raspberry Pi

Last Update:  02 Dec 2018

This is a work-in-process rebuild of our HomePi server - originally shared here.  Decided to use my new fav - DietPi as a foundation for this version of HomePi as opposed to stock raspbian.  Totally a work in process, simply recording my steps incase I have to go back and do this again!  NOT DONE!  Some of this is still flakey!

See original DIY Apple AirPlay/Print HowTo for Backgrounder 

Hardware

not much change here - 'upgraded' the sound board
Software

Dietpi is biggest change here - Raspbian but comes with many preinstalled/optimized Pi packages - including shairport-sync and cups. Much better environmentals too - e.g. backup, admin,  utilities, admin

DietPi Install Notes

OS Prep (Rasbian) and some optimized packages
  • Automatically resizes partitions, forces password changes and updates itself - ~5min
  • Config via SSH & DietPi-Software (try to avoid massive mods - DietPi does a quite a bit of tuning for you)
    • DietPi-Config/Audio Options->Soundcard=usb-dac
    • DietPi-Config/Advanced Options->Update Firmware
    • DietPi-Config/Language&Regional->Local=en.US.UTF-8 + Timezone + Keyboard[us]
    • DietPi-Config/Security->Change Hostname
      <reboot>
    • DietPi-Config/AutoStart->Automatic Login
  • Software via SSH and DietPi-Software
    • Software Optimized - Check the following
      • Media Systems->Shairport Sync (for AirPlay)
      • System Stats->RPi-Monitor (nice web-based monitor)
      • Printing->CloudPrint (aka cups for AirPrint)
  • My Stuff
    • Can't live without joe (editor):  apt-get install joe
    • Disabled WiFi Power Management to be safe
      iwconfig wlan0 power off
    • <more here?  Trying to live without net-tools>

AirPrint (CUPS)

  • Basically fully installed via DietPi-Software ... but, includes google cloudprint - no want that!  Just Cups!
    Have not figured out how to permanently disable (not run) cloudprintd - Mannually disabe after a boot for now
    systemctl disable cloudprintd.service
  • Simply configure printer(s) via https://<your PI IP address>:631
    • Log in to CUPS administration using system user & password 
    • Administration page: check "Share Printers" and "Allow Remote Admin"
    • Administration/Add Printer - "Discovered Network Printers" found our Dell M5200 w/ a couple of tweaks:

AirPlay (Shairport-sync)

  • Shairport-sync installed via DietPi-Software
  • Config file @ /usr/local/etc/shairport-sync.conf
    • Simply changed name in general section to identify location (e.g. "Family Room Bose")
    • left everything else  
  • install using https://githuamixerb.com/mikebrady/shairport-sync/blob/master/README.md  - Install/testing takes 45min - 1hr
  • Install steps below were distilled from README - Should work on Jessie or Stretch!  Read through the README to season to taste and understand the process. 

HomeKit (HomeBridge)

  • HomeBridge homepage @ https://github.com/nfarina/homebridge.
    Install can take some time, count on an hour with minimal plugin playtime!
  • One preliminary - check for plugins for your smart devices before you go through install  - just to make sure you'll be able to control your device.  Go to https://www.npmjs.com and search for  "homebridge-<your dev>".  For example https://www.npmjs.com/package/homebridge-wemo or https://www.npmjs.com/package/homebridge-philipshue
  • RPI Homebridge Install from https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi
    (Note no sudo's - running all this as root on dietpi)
    • Via DietPi-Software utility install Build-Essentials (c++ compiler and friends), node.js, Avahi and Git Client 
      Check Versions:

      $ g++ -v
      ..version at bottom..
      gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)

      $ node -v
      v11.2.0
    • Install Avahi and other Dependencies (not sure if this went in via DietPi Avahi)

      $ sudo apt-get install libavahi-compat-libdnssd-dev

    • HomeBridge Install:  README https://github.com/nfarina/homebridge/blob/master/README.md
      ?? Quite a few warnings 'deprecated' but nothing to worry about(?) ???

      $ npm install -g --unsafe-perm homebridge

    • Fire it up, it will complain about no plugins, but should see it run & offer a pairing code,  <Ctl>C to kill

      $ homebridge 

    • Create config.json file in /home/pi/.homebridge directory see README if you have probs, it could be your editor
  • Plugins installation.  Steps are dependent on the smart device.   Plugins are also installed using npm, will have their own readme/instructions including a snippet to add to your config.json file.  Get plugins by searching for "homebridge-" on https://www.npmjs.com.  Expect some trial/error and fiddling to get plugins working
  • Testing:  Once Plugins are installed,  Fire up Homebridge and test.  I test in a terminal window for a day or two to keep an eye on message chatter
  • To start Homebridge when RPI boots, create a systemd service from https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi#running-homebridge-on-bootup-systemd
    • Create /etc/default/homebridge file using example from https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/#file-homebridge

      $ cat /etc/default/homebridge

      # Defaults / Configuration options for homebridge
      # The following settings tells homebridge where to find the config.json file
      # and where to persist the data (i.e. pairing and others)
      HOMEBRIDGE_OPTS=-U /var/lib/homebridge

      # If you uncomment the following line, homebridge will log more
      # You can display this via systemd's journalctl: journalctl -f -u homebridge
      # DEBUG=*

    • Create /etc/systemd/system/homebridge.service file using example from https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/#file-homebridge-service
    • Check homebridge location - response should be usr/bin or usr/local/bin

      $ which homebridge
      /usr/local/bin/homebridge

    • Edit /etc/systemd/system/homebridge.service - set ExecStart to homebridge location (e.g. usr/bin/) 
      $ cat /etc/systemd/system/homebridge.service

      [Unit]
      Description=Node.js HomeKit Server 
      After=syslog.target network-online.target

      [Service]
      Type=simple
      User=homebridge
      EnvironmentFile=/etc/default/homebridge
      # Adapt this to your specific setup (could be /usr/bin/homebridge)
      # See comments below for more information
      ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
      Restart=on-failure
      RestartSec=10
      KillMode=process

      [Install]
      WantedBy=multi-user.target

    • Set execute permissions for service

      $ chmod +x /etc/systemd/system/homebridge.service

    • Add Homebridge system account, user and group created, no home directory (-M)

      $ useradd -M --system homebridge

    • Create system dir and copy config.json file for new homebridge service - set ownership and write

      $ mkdir /var/lib/homebridge

      $ chmod +w /var/lib/homebridge 
      $ chown -R homebridge:homebridge /var/lib/homebridge 
      $ cp /root/.homebridge/config.json /var/lib/homebridge/.

    • Enable/Run/Check the service

      $ systemctl daemon-reload
      $ systemctl enable homebridge
      $ systemctl start homebridge
      $ systemctl status homebridge

    • Check /var/log/daemon.log if anything goes bump.

      tac /var/log/daemon.log | less

    • Reboot to get the witches out and test service startup

      sudo shutdown now -r

  • Set up phone via https://support.apple.com/en-us/HT204893
    • if you forgot your pin/scan code dig it out of systemd journal

      sudo journalctl -u homebridge

  • Debugging:  Troubleshooting Guide @ https://github.com/nfarina/homebridge/wiki/Basic-Trouble-Shooting
    • Running in terminal window is very helpful 
    • See Also:  Common Issues section in the README

  • Apple Home info @ https://www.apple.com/ios/home/