This is an old revision of the document!

Raspberry Pi - MCP Weather Station

Part 1: General setup

  • run raspbian-ua-netinst on SD card (default install - server packages of debian wheezy)
  • SSH in as root…
> /etc/motd
echo rpi-weather > /etc/hostname
sed -i s/pi/rpi-weather/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
echo LANG=en_US.UTF-8 > /etc/locale.conf # needed to pass LANG parameter to services started by systemd
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
# however, the installer pins the non-foundation version, so we have to get rid of that
# commenting out lines in apt preferences files seems to be problematic, so we just delete it
rm /etc/apt/preferences.d/01vcgencmd.pref
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
aptitude install raspi-copies-and-fills
aptitude install libraspberrypi-bin fbset
# this is a default config.txt file - just comments, no settings:
mv /boot/config.txt /boot/config.txt.orig ; wget -O /boot/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 '# not supported on realtek dongle:' >> /etc/network/interfaces
echo '#pre-up iwconfig $IFACE power off' >> /etc/network/interfaces
echo 'iface mcp inet dhcp' >> /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



Part 3: WeeWx

aptitude install python-serial python-usb
aptitude install picocom usbutils

dpkg -i weewx_3.1.0-1_all.deb
*** Location: Merrillville, IN
*** Latitude, Longitude: 41.4894, -87.3331
*** Altitude: 680, foot
*** Display units: US
*** Weather Station type: Ultimeter
*** Weather Station model: Ultimeter 2100
*** serial port: /dev/ttyUSB0

*** you'll get dependency errors... fix them with:
aptitude install
*** (pick 2nd solution which involves it installing the extensions, not removing them stupidly)
*** unfortunately, this pulls in python2.6 for some dumb reason

# needed to provide unicode characters for graph rendering:
aptitude install fonts-freefont-ttf

adduser weewx
** press ctrl+d for password (don't set a password)
** Full name: WeeWx daemon
** (all other values empty)
chsh -s /bin/false weewx

adduser weewx dialout
adduser tdobes dialout # for troubleshooting

/etc/init.d/weewx stop
mkdir -p /var/lib/weewx
chown -R weewx:weewx /var/lib/weewx /var/weewx
echo 'WEEWX_USER=weewx:weewx' > /etc/default/weewx
echo 'touch $PIDFILE' >> /etc/default/weewx
echo 'chown $WEEWX_USER $PIDFILE' >> /etc/default/weewx
mkdir -p /var/www/weewx
chown weewx:weewx /var/www/weewx
/etc/init.d/weewx start

# Javascript Weather Console via. realtime.txt file
wee_setup install --extension weewx-crt-0.12.tgz
sed -i 's/    filename = \/var\/tmp\/realtime.txt/    filename = \/tmp\/weewx-realtime.txt/g' /etc/weewx/weewx.conf
/etc/init.d/weewx stop ; /etc/init.d/weewx start
mkdir /var/www/console
ln -s /tmp/weewx-realtime.txt /var/www/console/realtime.txt
aptitude install unzip
cd /var/www/console
unzip ~/
ln -s wconsole.html index.html
sed -i 's/var update_seconds=15;/var update_seconds=1;/g' /var/www/console/wconsole.js

# Bootstrap theme:
# note: this depends on fonts-freefont-ttf (installed earlier)
wee_setup install --extension v2.21.tar.gz
sed -i -e 's/    title = "The weather, in Royston"/    title = "MCP Weather Station"/g' -e 's/    location_href = "http:\/\/\/wiki\/Royston,_Hertfordshire"/    location_href = "http:\/\/\/"/g' -e 's/    footer = "© Ampelmann 2014"/    footer = "Merrillville Community Planetarium"/g' /etc/weewx/skins/Bootstrap/skin.conf
sed -i -e 's/        group_altitude     = meter/        group_altitude     = foot/g' -e 's/        group_degree_day   = degree_C_day/        group_degree_day   = degree_F_day/g' -e 's/        group_pressure     = mbar/        group_pressure     = inHg/g' -e 's/        group_rain         = mm/        group_rain         = inch/g' -e 's/        group_rainrate     = mm_per_hour/        group_rainrate     = inch_per_hour/g' -e 's/        group_temperature  = degree_C/        group_temperature  = degree_F/g' /etc/weewx/skins/Bootstrap/skin.conf
/etc/init.d/weewx stop ; /etc/init.d/weewx start

# attempt to address running out of memory:
sed -i -e 's/socket_timeout.*$/\0\n\n# how often garbage collection should be performed by the Python (in sec) - default 10800 (3 hrs)\ngc_interval = 3600/g' /etc/weewx/weewx.conf

aptitude --without-recommends install python-stdeb
pypi-install pyephem

# MCP Apt Proxy
echo 'Acquire::http { Proxy "http://apt.mcp.lcl:3142"; };' > /etc/apt/apt.conf.d/mcp-proxy

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

Part 4: Web Server

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
systemctl restart mini-httpd.service

Part 5: General systemd + Wheezy hacks

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

## 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 '' >> /etc/systemd/system/cron.service
echo '[Unit]' > /etc/systemd/system/ntp.service
echo 'Description=Network Time Protocol daemon' >> /etc/systemd/system/ntp.service
echo '' >> /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 '' >> /etc/systemd/system/ntp.service
echo '[Unit]' > /etc/systemd/system/ssh.service
echo 'Description=OpenBSD Secure Shell server' >> /etc/systemd/system/ssh.service
echo ' 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 '' >> /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 '' >> /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/' >> /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
# 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/' >> /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/
ln -sf /etc/systemd/system/getty\@.service /etc/systemd/system/\@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:

Part 6: systemd / weewx


Part 7: Overclock

# Medium overclocking to increase speed of JPEG retrieval/rotation
sed -i -e 's/^#*arm_freq=.*/arm_freq=900/g' /boot/config.txt
sed -i -e 's/^#*core_freq=.*/core_freq=333/g' /boot/config.txt
sed -i -e 's/^#*sdram_freq=.*/sdram_freq=450/g' /boot/config.txt
sed -i -e 's/^#*over_voltage=.*/over_voltage=2/g' /boot/config.txt

aptitude install sysfsutils
echo 'devices/system/cpu/cpu0/cpufreq/scaling_governor = ondemand' >> /etc/sysfs.conf
echo 'devices/system/cpu/cpufreq/ondemand/up_threshold = 60' >> /etc/sysfs.conf
computer/raspberry_pi_mcp-weather.1430702039.txt.gz · Last modified: 2015/05/03 20:13 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS