Raspberry Pi - Artnet to DMX node

Part 1: General setup

  • run raspbian-ua-netinst on SD card (default install - server packages of debian wheezy)
  • SSH in as root…
passwd
> /etc/motd
echo artnet-pi > /etc/hostname
sed -i s/pi/artnet-pi/g /etc/hosts
echo "America/Chicago" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
sed -i -e 's/^# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
dpkg-reconfigure -f noninteractive locales
apt-get update
apt-get --no-install-recommends install aptitude
#aptitude install linux-image-rpi-rpfv raspberrypi-bootloader-nokernel
#cp /boot/vmlinuz-* /boot/kernel.img
# the rpi foundation version is less buggy, although distributed in a more annoying way:
aptitude install raspberrypi-bootloader
echo 'blacklist spi-bcm2708' > /etc/modprobe.d/raspi-blacklist.conf
echo 'blacklist i2c-bcm2708' >> /etc/modprobe.d/raspi-blacklist.conf
echo 'blacklist snd-soc-bcm2708-i2s' >> /etc/modprobe.d/raspi-blacklist.conf
sed -i -e 's/^snd-bcm2835/#snd-bcm2835/g' /etc/modules
echo 'vm.min_free_kbytes = 4096' > /etc/sysctl.d/raspi-eth0_fix.conf # see http://wiki.gentoo.org/wiki/Raspberry_Pi#Troubleshooting
aptitude install raspi-copies-and-fills
aptitude install libraspberrypi-bin fbset
# this is a default config.txt file - just comments, no settings:
wget -O /boot/config.txt https://raw.githubusercontent.com/Evilpaul/RPi-config/master/config.txt
sed -i 's/#boot_delay=0/boot_delay=0/g' /boot/config.txt
aptitude install netcat-traditional screen rsync psmisc file patch ethtool strace tcpdump vim
aptitude --without-recommends install dnsutils
aptitude install dosfstools

aptitude install watchdog
sed -i -e 's/^watchdog_module="none"/watchdog_module="bcm2708_wdog"/g' /etc/default/watchdog
sed -i -e 's/^#watchdog-device/watchdog-device/g' /etc/watchdog.conf
sed -i -e 's/^#max-load-1\t/max-load-1\t/g' /etc/watchdog.conf
echo "# Raspberry Pi doesn't work with the default timeout of 60; set it to 10 instead" >> /etc/watchdog.conf
echo $'watchdog-timeout\t= 10' >> /etc/watchdog.conf

aptitude --without-recommends install kbd

adduser tdobes
adduser tdobes adm

Part 2: Wireless

aptitude --without-recommends install ifplugd wpasupplicant
aptitude install ifmetric iw wireless-tools
sed -i -e 's/raspbian wheezy main firmware$/raspbian wheezy main firmware non-free/g' /etc/apt/sources.list
aptitude update
aptitude forget-new
aptitude install firmware-ralink firmware-atheros
sed -i -e 's/^REGDOMAIN=$/REGDOMAIN=US/g' /etc/default/crda
sed -i -e 's/^INTERFACES=""/INTERFACES="eth0"/g' /etc/default/ifplugd
#we don't set HOTPLUG_INTERFACES because wireless interfaces are already handled by udev
#sed -i -e 's/^HOTPLUG_INTERFACES=""/HOTPLUG_INTERFACES="all"/g' /etc/default/ifplugd
sed -i -e 's/^auto eth0/#allow-hotplug eth0/g' /etc/network/interfaces
# this is needed so that we don't run an ifplugd for the lo interface while using HOTPLUG_INTERFACES:
echo 'SUBSYSTEM=="net", KERNEL!="lo", RUN+="ifplugd.agent"' > /etc/udev/rules.d/60-ifplugd.rules
/etc/init.d/ifplugd restart

echo 'allow-hotplug wlan0' >> /etc/network/interfaces
echo 'iface wlan0 inet manual' >> /etc/network/interfaces
echo 'wpa-driver nl80211,wext' >> /etc/network/interfaces
echo 'wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf' >> /etc/network/interfaces
echo 'pre-up iwconfig $IFACE power off' >> /etc/network/interfaces
echo 'iface lighting inet dhcp' >> /etc/network/interfaces
echo 'post-up /root/ola-reload-plugins.sh' >> /etc/network/interfaces
echo 'metric 1' >> /etc/network/interfaces
cat > /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="lighting2"
  #scan_ssid=1
  psk="***PASSWORD***"
  priority=10
  id_str="lighting"
}

network={
  ssid="tom-2.4"
  psk="***PASSWORD***"
  id_str="home"
}
^D

Part 3: OpenLighting and customizations

echo 'deb http://apt.openlighting.org/raspbian wheezy main' > /etc/apt/sources.list.d/openlighting.list
aptitude update
aptitude -o Aptitude::Cmdline::ignore-trust-violations=true install ola
** tell it to start OLA at boot time
cd /var/lib/ola/conf
shopt -s extglob
sed -i 's/enabled = true/enabled = false/g' /var/lib/ola/conf/!(*artnet.conf)
shopt -u extglob
sed -i 's/enabled = false/enabled = true/g' /var/lib/ola/conf/ola-ftdidmx.conf
/etc/init.d/olad restart

** olad has a bug in which it spins the cpu really hard unless it can talk to avahi-daemon... weird!
** even though it's totally superfluous, I guess we'll have to install it:
aptitude --without-recommends install avahi-daemon

** setup files to copy artnet port 10 to ftdi and restore config in case of issues:
mkdir /root/ola-backup
echo '13-A4006DC7-O-0 = 10' > /root/ola-backup/ola-port.conf
echo '2-1-I-0 = 10' >> /root/ola-backup/ola-port.conf
echo 'uni_10_merge = LTP' > /root/ola-backup/ola-universe.conf
echo 'uni_10_name = magicq' >> /root/ola-backup/ola-universe.conf
chown olad:olad /root/ola-backup/ola-port.conf /root/ola-backup/ola-universe.conf
chmod 664 /root/ola-backup/ola-port.conf /root/ola-backup/ola-universe.conf
echo '#!/bin/sh' > /root/ola-backup/restore.sh
echo 'cp -a `dirname $0`/*.conf /var/lib/ola/conf/' >> /root/ola-backup/restore.sh
chmod +x /root/ola-backup/restore.sh
/root/ola-backup/restore.sh
** add /root/ola-backup/restore.sh to /etc/rc.local before "exit 0"

echo '#!/bin/sh' >> /usr/local/bin/dmxmonitor.sh
echo -n "if netstat -lnt | awk '" >> /usr/local/bin/dmxmonitor.sh
echo -n '$4 ~ /:9010$/ {exit 1}' >> /usr/local/bin/dmxmonitor.sh
echo "'; then" >> /usr/local/bin/dmxmonitor.sh
echo '  echo -n Waiting for OLA daemon startup' >> /usr/local/bin/dmxmonitor.sh
echo -n "  while netstat -lnt | awk '" >> /usr/local/bin/dmxmonitor.sh
echo -n '$4 ~ /:9010$/ {exit 1}' >> /usr/local/bin/dmxmonitor.sh
echo "'; do" >> /usr/local/bin/dmxmonitor.sh
echo '    echo -n .' >> /usr/local/bin/dmxmonitor.sh
echo '  done' >> /usr/local/bin/dmxmonitor.sh
echo '  echo Done!' >> /usr/local/bin/dmxmonitor.sh
echo 'fi' >> /usr/local/bin/dmxmonitor.sh
echo 'exec /usr/bin/nice /usr/bin/ola_dmxmonitor -u 10' >> /usr/local/bin/dmxmonitor.sh
chmod +x /usr/local/bin/dmxmonitor.sh
ln -s /usr/local/bin/dmxmonitor.sh /root/dmxmonitor.sh

echo '12:23:respawn:/bin/su -s /bin/sh nobody -c "/usr/local/bin/dmxmonitor.sh" > /dev/tty12' >> /etc/inittab
** add the following lines to /etc/rc.local before "exit 0"
/usr/bin/setterm -powersave off -blank 0
/bin/chvt 12
/bin/fbset -g 930 620 930 620 8

# This doesn't seem to work... at least not under systemd:
#sed -i 's/BLANK_TIME=30/BLANK_TIME=0/g' /etc/kbd/config
#sed -i 's/POWERDOWN_TIME=30/POWERDOWN_TIME=0/g' /etc/kbd/config

echo '#!/bin/sh' > /root/ola-reload-plugins.sh
echo 'if ! pidof /usr/bin/olad > /dev/null; then' >> /root/ola-reload-plugins.sh
echo '  exit 0' >> /root/ola-reload-plugins.sh
echo 'fi' >> /root/ola-reload-plugins.sh
echo 'wget -q -O /dev/null --timeout=0.5 http://localhost:9090/reload &' >> /root/ola-reload-plugins.sh
echo 'if [ -n "$IFACE" ]; then' >> /root/ola-reload-plugins.sh
echo '  if [ -e /sys/fs/cgroup/systemd ]; then' >> /root/ola-reload-plugins.sh
echo '    systemctl --no-block try-restart dmxmonitor@12.service' >> /root/ola-reload-plugins.sh
echo '  else' >> /root/ola-reload-plugins.sh
echo '    killall -u nobody /usr/bin/ola_dmxmonitor' >> /root/ola-reload-plugins.sh
echo '  fi' >> /root/ola-reload-plugins.sh
echo 'fi' >> /root/ola-reload-plugins.sh
echo 'exit 0' >> /root/ola-reload-plugins.sh
chmod +x /root/ola-reload-plugins.sh
** add /root/ola-reload-plugins.sh to post-up for eth0, lighting, home in /etc/network/interfaces
echo 'ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_VENDOR_ID}=="0403", ENV{ID_MODEL_ID}=="6001", RUN+="/root/ola-reload-plugins.sh"' > /etc/udev/rules.d/ola-ftdi-reload.rules
echo 'ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_VENDOR_ID}=="0403", ENV{ID_MODEL_ID}=="6001", RUN+="/root/ola-reload-plugins.sh"' >> /etc/udev/rules.d/ola-ftdi-reload.rules
# note: ola-reload-plugins.sh runs on USB insertion/removal as well as when network interfaces come up.  When network interfaces come up, it also restarts (or kills, to be restarted by init) ola_dmxmonitor, which flashes the diagnostic screen

** add quiet to the end of /boot/cmdline.txt

Part 4: General systemd + Wheezy hacks

aptitude install systemd dbus
** add init=/bin/systemd to the end of /boot/cmdline.txt
reboot

## NOTE:  Most of these hacks won't be needed in Jessie.

ln -s `which systemd-journalctl` /usr/local/bin/journalctl

echo '[Unit]' > /etc/systemd/system/cron.service
echo 'Description=Regular background program processing daemon' >> /etc/systemd/system/cron.service
echo >> /etc/systemd/system/cron.service
echo '[Service]' >> /etc/systemd/system/cron.service
echo 'ExecStart=/usr/sbin/cron -f' >> /etc/systemd/system/cron.service
echo >> /etc/systemd/system/cron.service
echo '[Install]' >> /etc/systemd/system/cron.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/cron.service
echo '[Unit]' > /etc/systemd/system/ntp.service
echo 'Description=Network Time Protocol daemon' >> /etc/systemd/system/ntp.service
echo 'After=network.target' >> /etc/systemd/system/ntp.service
echo >> /etc/systemd/system/ntp.service
echo '[Service]' >> /etc/systemd/system/ntp.service
echo 'ExecStart=/usr/sbin/ntpd -n -g -u ntp:ntp' >> /etc/systemd/system/ntp.service
echo >> /etc/systemd/system/ntp.service
echo '[Install]' >> /etc/systemd/system/ntp.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ntp.service
echo '[Unit]' > /etc/systemd/system/ssh.service
echo 'Description=OpenBSD Secure Shell server' >> /etc/systemd/system/ssh.service
echo 'After=network.target auditd.service' >> /etc/systemd/system/ssh.service
echo 'ConditionPathExists=!/etc/ssh/sshd_not_to_be_run' >> /etc/systemd/system/ssh.service
echo >> /etc/systemd/system/ssh.service
echo '[Service]' >> /etc/systemd/system/ssh.service
echo 'EnvironmentFile=-/etc/default/ssh' >> /etc/systemd/system/ssh.service
echo 'ExecStart=/usr/sbin/sshd -D $SSHD_OPTS' >> /etc/systemd/system/ssh.service
echo 'ExecReload=/bin/kill -HUP $MAINPID' >> /etc/systemd/system/ssh.service
echo 'KillMode=process' >> /etc/systemd/system/ssh.service
echo 'Restart=on-failure' >> /etc/systemd/system/ssh.service
echo >> /etc/systemd/system/ssh.service
echo '[Install]' >> /etc/systemd/system/ssh.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ssh.service
echo 'Alias=sshd.service' >> /etc/systemd/system/ssh.service
echo '[Unit]' > /etc/systemd/system/ssh\@.service
echo 'Description=OpenBSD Secure Shell server per-connection daemon' >> /etc/systemd/system/ssh\@.service
echo 'After=auditd.service' >> /etc/systemd/system/ssh\@.service
echo >> /etc/systemd/system/ssh\@.service
echo '[Service]' >> /etc/systemd/system/ssh\@.service
echo 'EnvironmentFile=-/etc/default/ssh' >> /etc/systemd/system/ssh\@.service
echo 'ExecStart=-/usr/sbin/sshd -i $SSHD_OPTS' >> /etc/systemd/system/ssh\@.service
echo 'StandardInput=socket' >> /etc/systemd/system/ssh\@.service
echo '[Unit]' > /etc/systemd/system/ssh.socket
echo 'Description=OpenBSD Secure Shell server socket' >> /etc/systemd/system/ssh.socket
echo 'Before=ssh.service' >> /etc/systemd/system/ssh.socket
echo 'Conflicts=ssh.service' >> /etc/systemd/system/ssh.socket
echo 'ConditionPathExists=!/etc/ssh/sshd_not_to_be_run' >> /etc/systemd/system/ssh.socket
echo >> /etc/systemd/system/ssh.socket
echo '[Socket]' >> /etc/systemd/system/ssh.socket
echo 'ListenStream=22' >> /etc/systemd/system/ssh.socket
echo 'Accept=yes' >> /etc/systemd/system/ssh.socket
echo >> /etc/systemd/system/ssh.socket
echo '[Install]' >> /etc/systemd/system/ssh.socket
echo 'WantedBy=sockets.target' >> /etc/systemd/system/ssh.socket
echo 'd /var/run/sshd 0755 root root' > /etc/tmpfiles.d/sshd.conf

systemctl enable cron.service
systemctl enable ntp.service
systemctl disable ssh.service
systemctl enable ssh.socket

systemctl mask rc.local.service # seems buggy - replace with custom service files
systemctl disable rsyslog.service # disable to reduce writes to sd card
systemctl disable wpa_supplicant.service # unnecessary; started automatically
systemctl mask wd_keepalive.service # apparently conflicts with startup of watchdog because watchdog init script doesn't stop it successfully

systemctl stop rsyslog.service
rm /var/log/auth.log* /var/log/daemon.log* /var/log/debug /var/log/kern.log* /var/log/messages /var/log/user.log*

# Updates to systemd and udev should make these hacks unnecessary under Jessie, but Wheezy needs them
# udev should send "stop" commands to systemd; not just start commands... also ensure that systemctl only gets called for interfaces set as "auto" or "allow-hotplug"
# We also send the stop command to systemd even if ifdown is already running to avoid a race condition with wpa_supplicant
cp -a /lib/udev/net.agent /etc/udev/
echo '--- /etc/udev/net.agent' > /tmp/udev_net_unplug_systemd.patch
echo '+++ /etc/udev/net.agent.new' >> /tmp/udev_net_unplug_systemd.patch
echo '@@ -48,7 +48,11 @@' >> /tmp/udev_net_unplug_systemd.patch
echo ' ' >> /tmp/udev_net_unplug_systemd.patch
echo '     wait_for_interface lo' >> /tmp/udev_net_unplug_systemd.patch
echo '     if [ -e /sys/fs/cgroup/systemd ]; then' >> /tmp/udev_net_unplug_systemd.patch
echo '-      exec systemctl start ifup@${INTERFACE}.service' >> /tmp/udev_net_unplug_systemd.patch
echo "+      if grep -q '"'^\(allow-hotplug\|auto\)[[:space:]].*\<'"'"'"$INTERFACE"'"'"'\>'"'"' \' >> /tmp/udev_net_unplug_systemd.patch
echo '+            /etc/network/interfaces; then' >> /tmp/udev_net_unplug_systemd.patch
echo '+        # this $INTERFACE is marked as "allow-hotplug" or "auto"' >> /tmp/udev_net_unplug_systemd.patch
echo '+        exec systemctl start ifup@${INTERFACE}.service' >> /tmp/udev_net_unplug_systemd.patch
echo '+      fi' >> /tmp/udev_net_unplug_systemd.patch
echo '     else' >> /tmp/udev_net_unplug_systemd.patch
echo '       exec ifup --allow=hotplug $INTERFACE' >> /tmp/udev_net_unplug_systemd.patch
echo '     fi' >> /tmp/udev_net_unplug_systemd.patch
echo '@@ -57,12 +61,16 @@' >> /tmp/udev_net_unplug_systemd.patch
echo ' net_ifdown() {' >> /tmp/udev_net_unplug_systemd.patch
echo '     check_program /sbin/ifdown' >> /tmp/udev_net_unplug_systemd.patch
echo ' ' >> /tmp/udev_net_unplug_systemd.patch
echo '-    if ps -C ifdown ho args | grep -q $INTERFACE; then' >> /tmp/udev_net_unplug_systemd.patch
echo '+    if [ -e /sys/fs/cgroup/systemd ]; then' >> /tmp/udev_net_unplug_systemd.patch
echo '+      exec systemctl stop ifup@${INTERFACE}.service' >> /tmp/udev_net_unplug_systemd.patch
echo '+    else' >> /tmp/udev_net_unplug_systemd.patch
echo '+      if ps -C ifdown ho args | grep -q $INTERFACE; then' >> /tmp/udev_net_unplug_systemd.patch
echo $' \t''debug_mesg "Already ifdown-ing interface $INTERFACE"' >> /tmp/udev_net_unplug_systemd.patch
echo $' \texit 0' >> /tmp/udev_net_unplug_systemd.patch
echo '-    fi' >> /tmp/udev_net_unplug_systemd.patch
echo '+      fi' >> /tmp/udev_net_unplug_systemd.patch
echo ' ' >> /tmp/udev_net_unplug_systemd.patch
echo '-    exec ifdown --allow=hotplug $INTERFACE' >> /tmp/udev_net_unplug_systemd.patch
echo '+      exec ifdown --allow=hotplug $INTERFACE' >> /tmp/udev_net_unplug_systemd.patch
echo '+    fi' >> /tmp/udev_net_unplug_systemd.patch
echo ' }' >> /tmp/udev_net_unplug_systemd.patch
echo ' ' >> /tmp/udev_net_unplug_systemd.patch
echo ' do_everything() {' >> /tmp/udev_net_unplug_systemd.patch
patch -p0 < /tmp/udev_net_unplug_systemd.patch && rm /tmp/udev_net_unplug_systemd.patch
cp -a /lib/udev/rules.d/80-networking.rules /etc/udev/rules.d/
sed -i 's/RUN+="net.agent"/RUN+="\/etc\/udev\/net.agent"/g' /etc/udev/rules.d/80-networking.rules

# ifplugd should start up / shut down interfaces using systemd, not calling ifupdown directly
# ideally, this would work... but we have to comment out allow-hotplug in /etc/network/interfaces to prevent udev from ifup'ing eth0... and ifup@.service passes --allow=hotplug to ifup, which prevents this from working
# ...so I gave up and just let ifup run in the ifplugd service instead
#echo '--- /etc/ifplugd/action.d/ifupdown' > /tmp/ifplugd_systemd.patch
#echo '+++ /etc/ifplugd/action.d/ifupdown.new' >> /tmp/ifplugd_systemd.patch
#echo '@@ -3,9 +3,17 @@' >> /tmp/ifplugd_systemd.patch
#echo ' ' >> /tmp/ifplugd_systemd.patch
#echo ' case "$2" in' >> /tmp/ifplugd_systemd.patch
#echo ' up)' >> /tmp/ifplugd_systemd.patch
#echo $'-\t/sbin/ifup $1' >> /tmp/ifplugd_systemd.patch
#echo $'+\tif [ -e /sys/fs/cgroup/systemd ]; then' >> /tmp/ifplugd_systemd.patch
#echo $'+\t\t/bin/systemctl start ifup@$1.service' >> /tmp/ifplugd_systemd.patch
#echo $'+\telse' >> /tmp/ifplugd_systemd.patch
#echo $'+\t\t/sbin/ifup $1' >> /tmp/ifplugd_systemd.patch
#echo $'+\tfi' >> /tmp/ifplugd_systemd.patch
#echo $' \t;;' >> /tmp/ifplugd_systemd.patch
#echo ' down)' >> /tmp/ifplugd_systemd.patch
#echo $'-\t/sbin/ifdown $1' >> /tmp/ifplugd_systemd.patch
#echo $'+\tif [ -e /sys/fs/cgroup/systemd ]; then' >> /tmp/ifplugd_systemd.patch
#echo $'+\t\t/bin/systemctl stop ifup@$1.service' >> /tmp/ifplugd_systemd.patch
#echo $'+\telse' >> /tmp/ifplugd_systemd.patch
#echo $'+\t\t/sbin/ifdown $1' >> /tmp/ifplugd_systemd.patch
#echo $'+\tfi' >> /tmp/ifplugd_systemd.patch
#echo $' \t;;' >> /tmp/ifplugd_systemd.patch
#echo ' esac' >> /tmp/ifplugd_systemd.patch
#patch -p0 < /tmp/ifplugd_systemd.patch && rm /tmp/ifplugd_systemd.patch

cp -a /lib/systemd/system/getty\@.service /etc/systemd/system/
sed -i 's/ExecStart=-\/sbin\/agetty %I 38400/ExecStart=-\/sbin\/agetty --noclear %I 38400/g' /etc/systemd/system/getty\@.service
sed -i 's/TTYVTDisallocate=yes/#TTYVTDisallocate=yes/g' /etc/systemd/system/getty\@.service
mkdir /etc/systemd/system/getty.target.wants
ln -sf /etc/systemd/system/getty\@.service /etc/systemd/system/getty.target.wants/getty\@tty1.service

systemctl mask networking.service # we use ifplugd instead
systemctl mask kbd.service # this doesn't seem to work anyway
echo 'D /run/network 0755 root root' > /etc/tmpfiles.d/debian-networking.conf
echo 'F /run/network/ifstate 0644 root root - lo=lo' >> /etc/tmpfiles.d/debian-networking.conf

See also: http://blog.higgsboson.tk/2012/09/19/systemd-on-raspbian/

Part 5: systemd / OpenLighting and customization

echo '[Unit]' > /etc/systemd/system/olad.service
echo 'Description=OLA daemon' >> /etc/systemd/system/olad.service
echo 'After=network.target' >> /etc/systemd/system/olad.service
echo >> /etc/systemd/system/olad.service
echo '[Service]' >> /etc/systemd/system/olad.service
echo 'ExecStart=/usr/bin/olad --syslog --log-level 3 --config-dir /var/lib/ola/conf' >> /etc/systemd/system/olad.service
echo 'User=olad' >> /etc/systemd/system/olad.service
echo 'Restart=always' >> /etc/systemd/system/olad.service
echo 'RestartSec=2' >> /etc/systemd/system/olad.service
echo >> /etc/systemd/system/olad.service
echo '[Install]' >> /etc/systemd/system/olad.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/olad.service
systemctl enable olad.service

echo '[Unit]' > /etc/systemd/system/dmxmonitor\@.service
echo 'Description=DMX Monitor on TTY%I' >> /etc/systemd/system/dmxmonitor\@.service
echo 'Requires=olad.service' >> /etc/systemd/system/dmxmonitor\@.service
echo 'After=olad.service' >> /etc/systemd/system/dmxmonitor\@.service
echo 'After=switch_vt@%I.service' >> /etc/systemd/system/dmxmonitor\@.service
echo >> /etc/systemd/system/dmxmonitor\@.service
echo '[Service]' >> /etc/systemd/system/dmxmonitor\@.service
echo 'ExecStart=/usr/local/bin/dmxmonitor.sh' >> /etc/systemd/system/dmxmonitor\@.service
echo 'User=nobody' >> /etc/systemd/system/dmxmonitor\@.service
echo 'StandardInput=tty' >> /etc/systemd/system/dmxmonitor\@.service
echo 'StandardOutput=tty' >> /etc/systemd/system/dmxmonitor\@.service
echo 'TTYPath=/dev/tty%I' >> /etc/systemd/system/dmxmonitor\@.service
echo 'TTYReset=yes' >> /etc/systemd/system/dmxmonitor\@.service
echo 'TTYVTDisallocate=yes' >> /etc/systemd/system/dmxmonitor\@.service
echo 'Restart=always' >> /etc/systemd/system/dmxmonitor\@.service
echo 'RestartSec=2' >> /etc/systemd/system/dmxmonitor\@.service
echo >> /etc/systemd/system/dmxmonitor\@.service
echo '[Install]' >> /etc/systemd/system/dmxmonitor\@.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/dmxmonitor\@.service
# systemctl enable dmxmonitor\@12.service # doesn't work due to some sort of bug... WTF?
ln -s /etc/systemd/system/dmxmonitor\@.service /etc/systemd/system/multi-user.target.wants/dmxmonitor\@12.service

echo '[Unit]' > /etc/systemd/system/switch_vt\@.service
echo 'Description=Switch to VT%I' >> /etc/systemd/system/switch_vt\@.service
echo 'After=no_console_blank.service' >> /etc/systemd/system/switch_vt\@.service
echo >> /etc/systemd/system/switch_vt\@.service
echo '[Service]' >> /etc/systemd/system/switch_vt\@.service
echo 'Type=oneshot' >> /etc/systemd/system/switch_vt\@.service
echo 'RemainAfterExit=yes' >> /etc/systemd/system/switch_vt\@.service
echo 'ExecStart=/bin/chvt %I' >> /etc/systemd/system/switch_vt\@.service
echo 'ExecStop=/bin/chvt 1' >> /etc/systemd/system/switch_vt\@.service
echo >> /etc/systemd/system/switch_vt\@.service
echo '[Install]' >> /etc/systemd/system/switch_vt\@.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/switch_vt\@.service
# systemctl enable switch_vt\@12.service # doesn't work due to some sort of bug... WTF?
ln -s /etc/systemd/system/switch_vt\@.service /etc/systemd/system/multi-user.target.wants/switch_vt\@12.service

echo '[Unit]' > /etc/systemd/system/no_console_blank.service
echo 'Description=Disable Console Blanking' >> /etc/systemd/system/no_console_blank.service
echo >> /etc/systemd/system/no_console_blank.service
echo '[Service]' >> /etc/systemd/system/no_console_blank.service
echo 'Type=oneshot' >> /etc/systemd/system/no_console_blank.service
echo 'ExecStart=/usr/bin/setterm -powersave off -blank 0' >> /etc/systemd/system/no_console_blank.service
echo 'Restart=on-failure' >> /etc/systemd/system/no_console_blank.service
echo 'StandardInput=tty' >> /etc/systemd/system/no_console_blank.service
echo 'StandardOutput=tty' >> /etc/systemd/system/no_console_blank.service
echo 'StandardError=journal' >> /etc/systemd/system/no_console_blank.service
echo 'TTYPath=/dev/tty1' >> /etc/systemd/system/no_console_blank.service
echo >> /etc/systemd/system/no_console_blank.service
echo '[Install]' >> /etc/systemd/system/no_console_blank.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/no_console_blank.service
systemctl enable no_console_blank.service

echo '[Unit]' > /etc/systemd/system/fb_geometry.service
echo 'Description=Adjust Framebuffer Geometry for DMX Monitor' >> /etc/systemd/system/fb_geometry.service
echo 'After=switch_vt@12.service' >> /etc/systemd/system/fb_geometry.service
echo >> /etc/systemd/system/fb_geometry.service
echo '[Service]' >> /etc/systemd/system/fb_geometry.service
echo 'Type=oneshot' >> /etc/systemd/system/fb_geometry.service
echo 'ExecStart=/bin/fbset -g 930 620 930 620 8' >> /etc/systemd/system/fb_geometry.service
echo >> /etc/systemd/system/fb_geometry.service
echo '[Install]' >> /etc/systemd/system/fb_geometry.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/fb_geometry.service
systemctl enable fb_geometry.service

echo '[Unit]' > /etc/systemd/system/restore_ola_backup.service
echo 'Description=Restore OLA backup' >> /etc/systemd/system/restore_ola_backup.service
echo 'Before=olad.service' >> /etc/systemd/system/restore_ola_backup.service
echo >> /etc/systemd/system/restore_ola_backup.service
echo '[Service]' >> /etc/systemd/system/restore_ola_backup.service
echo 'Type=oneshot' >> /etc/systemd/system/restore_ola_backup.service
echo 'ExecStart=/root/ola-backup/restore.sh' >> /etc/systemd/system/restore_ola_backup.service
echo >> /etc/systemd/system/restore_ola_backup.service
echo '[Install]' >> /etc/systemd/system/restore_ola_backup.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/restore_ola_backup.service
systemctl enable restore_ola_backup.service

Quick Performance Measurement

  • sysvinit startup = 32 seconds
  • systemd startup = 14 seconds

X10 Control

(CM11A computer interface attached to PL2303 USB→RS232 adapter)

wget http://wiki.mcpstars.org/_media/computer/heyu-rpi.tar.gz
su
cd /
tar -xzf ~tdobes/heyu-rpi.tar.gz && rm ~tdobes/heyu-rpi.tar.gz

# only works with newer versions of systemd than the one shipped with wheezy:
#mkdir /etc/systemd/system/heyu.service.d
#echo '[Service]' > /etc/systemd/system/heyu.service.d/nice.conf
#echo 'Nice=1' >> /etc/systemd/system/heyu.service.d/nice.conf
echo '--- /etc/systemd/system/heyu.service' > /tmp/heyu-systemd.patch
echo '+++ /etc/systemd/system/heyu.service.new' >> /tmp/heyu-systemd.patch
echo '@@ -6,6 +6,7 @@' >> /tmp/heyu-systemd.patch
echo ' Type=forking' >> /tmp/heyu-systemd.patch
echo ' User=nobody' >> /tmp/heyu-systemd.patch
echo ' Group=dialout' >> /tmp/heyu-systemd.patch
echo '+Nice=1' >> /tmp/heyu-systemd.patch
echo ' Restart=always' >> /tmp/heyu-systemd.patch
echo ' RestartSec=2' >> /tmp/heyu-systemd.patch
echo >> /tmp/heyu-systemd.patch
patch -p0 < /tmp/heyu-systemd.patch && rm /tmp/heyu-systemd.patch

systemd-tmpfiles --create /etc/tmpfiles.d/heyu.conf
systemctl enable heyu.service

echo >> /etc/heyu/x10.conf
echo 'HOUSECODE\tM' >> /etc/heyu/x10.conf
echo 'ALIAS\thouse1\tM1\tLM465-1' >> /etc/heyu/x10.conf
echo 'ALIAS\thouse2\tM2\tLM' >> /etc/heyu/x10.conf
echo 'ALIAS\twork\tM3\tLM' >> /etc/heyu/x10.conf

systemctl start heyu.service

# dialout group can control x10 stuff via. heyu
adduser tdobes dialout

See also: http://wiki.mcpstars.org/computer/raspberry_pi_x10_notes#precompiled_binary

Web Interface for X10

aptitude --without-recommends install mini-httpd
sed -i -e 's/^START=0$/START=1/g' /etc/default/mini-httpd
mkdir /var/www
sed -i -e 's/^host=localhost$/#host=localhost/g; s/^user=nobody$/user=www-data/g; s|^data_dir=/usr/share/mini-httpd/html$|data_dir=/var/www|g' /etc/mini-httpd.conf
adduser www-data dialout
systemctl restart mini-httpd.service

cat > /var/www/index.html
<html>
<head>
<title>Studio Lighting Control</title>
</head>
<body>
<iframe src="cgi-bin/levels.sh" style="float: right;" width="165" height="90"></iframe>
<h1>House Lights Control</h1>
<table>
<tr><td>Chandeliers:</td><td>
<a href="cgi-bin/house1.sh?0" target="action">OFF</a> &middot;
<a href="cgi-bin/house1.sh?15" target="action">25%</a> &middot;
<a href="cgi-bin/house1.sh?31" target="action">50%</a> &middot;
<a href="cgi-bin/house1.sh?46" target="action">75%</a> &middot;
<a href="cgi-bin/house1.sh?62" target="action">FULL</a></td></tr>
<tr><td>Concessions:</td><td>
<a href="cgi-bin/house2.sh?0" target="action">OFF</a> &middot;
<a href="cgi-bin/house2.sh?5" target="action">25%</a> &middot;
<a href="cgi-bin/house2.sh?10" target="action">50%</a> &middot;
<a href="cgi-bin/house2.sh?15" target="action">75%</a> &middot;
<a href="cgi-bin/house2.sh?20" target="action">FULL</a></td></tr>
<tr><td>Worklights:</td><td>
<a href="cgi-bin/work.sh?0" target="action">OFF</a> &middot;
<a href="cgi-bin/work.sh?5" target="action">25%</a> &middot;
<a href="cgi-bin/work.sh?10" target="action">50%</a> &middot;
<a href="cgi-bin/work.sh?15" target="action">75%</a> &middot;
<a href="cgi-bin/work.sh?20" target="action">FULL</a></td></tr>
<tr><td><strong>ALL:</strong></td><td>
<a href="cgi-bin/all.sh?0" target="action">OFF</a> &middot;
<a href="cgi-bin/all.sh?5" target="action">25%</a> &middot;
<a href="cgi-bin/all.sh?10" target="action">50%</a> &middot;
<a href="cgi-bin/all.sh?15" target="action">75%</a> &middot;
<a href="cgi-bin/all.sh?20" target="action">FULL</a></td></tr>
<tr><td colspan="2" style="border: 1px solid black; font-size: small;"><a href="cgi-bin/all.sh?off" target="action">Total OFF</a> <span style="color: #900;">WARNING: Cheap modules cannot fade up from this state. Do this only when leaving!</span></td></tr>
</table>
<hr />
<p style="text-align: right; font-size: xx-small;"><a href="/" onclick="javascript:event.target.port=9090">OLA Web Interface</a><br />(use with caution!)</p>
<iframe src="about:blank" name="action" width="0" height="0" style="display: none;"></iframe>
</body>
</html>
^D

mkdir /var/www/cgi-bin
cat > /var/www/cgi-bin/house1.sh
#!/bin/sh
echo 'Content-type: text/plain'
echo

if [ "$#" -ne 1 ]; then
  echo "USAGE: $0 ACTION" >&2
  echo "where ACTION is:" >&2
  echo "  on" >&2
  echo "  off" >&2
  echo "  0 to 63" >&2
  exit 1
fi

addr=M1

case "$1" in
  "on"|"ON"|"On")
    heyu on $addr
    ;;
  "off"|"OFF"|"Off")
    heyu off $addr
    ;;
  *)
    heyu xpreset $addr $1
    ;;
esac

cat > /var/www/cgi-bin/house2.sh
#!/bin/sh
echo 'Content-type: text/plain'
echo

if [ "$#" -ne 1 ]; then
  echo "USAGE: $0 ACTION" >&2
  echo "where ACTION is:" >&2
  echo "  on" >&2
  echo "  off" >&2
  echo "  0 to 20" >&2
  exit 1
fi

addr=M2

case "$1" in
  "on"|"ON"|"On")
    heyu on $addr
    ;;
  "off"|"OFF"|"Off")
    heyu off $addr
    ;;
  *)
    level=`heyu dimlevel $addr`

    if [ "$level" -eq 0 ]; then
      if [ "$1" -gt 4 ]; then
        heyu on $addr
        heyu dim $addr $((20-$1))
      fi
    elif [ "$1" -lt 1 ]; then
      heyu dim $addr 22
    elif [ "$1" -gt 19 ]; then
      heyu bright $addr 22
    else
      # this is pretty crude, but we'll do our best
      offset=$(($1-$level/5))
      if [ $offset -gt 0 ]; then
        heyu bright $addr $offset
      elif [ $offset -lt 0 ]; then
        heyu dim $addr $((-$offset))
      fi
    fi
    ;;
esac
^D

cp -a /var/www/cgi-bin/house2.sh /var/www/cgi-bin/work.sh
sed -i -e 's/^addr=M2$/addr=M3/g' /var/www/cgi-bin/work.sh

cat > /var/www/cgi-bin/all.sh
#!/bin/sh
echo 'Content-type: text/plain'
echo

if [ "$#" -ne 1 ]; then
  echo "USAGE: $0 ACTION" >&2
  echo "where ACTION is:" >&2
  echo "  on" >&2
  echo "  off" >&2
  echo "  0 to 20" >&2
  exit 1
fi

case "$1" in
  "on"|"ON"|"On")
    ./house1.sh on
    ./house2.sh on
    ./work.sh on
    ;;
  "off"|"OFF"|"Off")
    ./house1.sh off
    ./house2.sh off
    ./work.sh off
    ;;
  *)
    ./house1.sh $(($1*62/20))
    ./house2.sh $1
    ./work.sh $1
    ;;
esac
^D

cat > /var/www/cgi-bin/levels.sh
#!/bin/sh

echo 'Content-type: text/html'
echo
echo '<html>'
echo '<head>'
echo '<title>X10 Levels</title>'
echo '<meta http-equiv="refresh" content="3">'
echo '</head>'
echo '<body>'
echo '<table>'
level=`heyu dimlevel M1`
echo '<tr><td>Chandeliers:</td><td>'
echo "$level%"
echo '</td></tr>'
level=`heyu dimlevel M2`
echo '<tr><td>Concessions:</td><td>'
if [ $level -lt 2 ]; then
  echo '<span style="color: #900;">-OFF-</span>'
elif [ $level -lt 6 ]; then
  echo '0%'
else
  echo "$level%"
fi
echo '</td></tr>'
level=`heyu dimlevel M3`
echo '<tr><td>Worklights:</td><td>'
if [ $level -lt 2 ]; then
  echo '<span style="color: #900;">-OFF-</span>'
elif [ $level -lt 6 ]; then
  echo '0%'
else
  echo "$level%"
fi
echo '</td></tr>'
echo '</table>'
echo '</body>'
echo '</html>'
^D

chmod +x /var/www/cgi-bin/house1.sh /var/www/cgi-bin/house2.sh /var/www/cgi-bin/work.sh /var/www/cgi-bin/all.sh /var/www/cgi-bin/levels.sh
computer/raspberry_pi_artnet.txt · Last modified: 2016/01/05 00:04 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS