Starting with a clean Raspbian Jessie Lite (Sep16) install...
- With
raspi-config:- Change the password
- Set approp locale/kb/tz
Set the hostnameWill be set later using Pi's serial number- Enable SPI
- Enable I2C
- Disable shell on serial port
- Enable SSH server (no longer on by default)
- Disable wait for network at boot
- Advanced > Update
- Reboot
sudo apt-get dist-upgrade- install basic utilities:
git tmux htop build-essential python-dev python-pip- update pip using
sudo pip install --upgrade pip
- update pip using
- Setup watchdog service
- install
watchdog - edit
/boot/config.txtto containdtoverlay=watchdog=onref - fixup the systemd service file thanks to:
edit
/lib/systemd/system/watchdog.serviceto contain:[Install] WantedBy=multi-user.target - edit
/etc/watchdog.confto contain refwatchdog-device = /dev/watchdog watchdog-timeout = 10 interval = 2 max-load-1 = 24 - enable service and start it using sytemctl
- finally, test it with a fork bomb:
:(){ :|:& };:the Pi should return a PID number, then hang, then reboot
- install
- Enable persistent system logs:
sudo mkdir -p /var/log/journalref - enable NPT stats: edit
/etc/ntp.confto uncomment line starting withstatsdir ... - Power down and install hardware. If you are working on a different Pi, put the SD card into the correct unit now. All hardware should be assembled as described in the Assembly notes. Once finished, supply power and proceed.
All hardware must be assembled and attached before proceeding.
- Enable real-time clock ref
- install:
python-smbus i2c-tools - edit
/boot/config.txtto containdtoverlay=i2c-rtc,ds3231 - reboot
- run
i2cdetect 1and verify 0x68=UU sudo apt-get -y remove fake-hwclocksudo update-rc.d -f fake-hwclock remove- edit
/lib/udev/hwclock-setto comment out#if [ -e /run/systemd/system ] ; then # exit 0 #fi - set clock (check for valid datetime first with
date):sudo hwclock -w(read back withsudo hwclock -D -r)
- install:
- Setup for K30 CO2 sensor
- install
python-serial enable the UART: edit/boot/config.txtto containenable_uart=1- http://elinux.org/RPi_Serial_Connection
- https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=141195
- raspberrypi/firmware#553 (comment)
- this step no longer necessary (?)
- install
- Setup for BMP280 T/P sensor
git clone https://github.com/bastienwirtz/Adafruit_Python_BMPcd Adafruit_Python_BMP && sudo python setup.py install
- Setup for HTU21DF RH/T sensor
git clone https://github.com/raspberrypi/weather-station- use relative imports to obtain the module
ref:
import sys sys.path.append('../weather-station/') import HTU21D
- Setup for OPC-N2 sensor
sudo pip install spidev py-opc
Follow these steps to enable network communications with the Pi Zero over its USB on-the-go (OTG) port.
- Enable Ethernet Gadget mode
- edit
/boot/config.txtto containdtoverlay=dwc2 - edit
/boot/cmdline.txtto containmodules-load=dwc2,g_etherdirectly afterrootwait - Reboot
- edit
Set static IP on device -- add toThis step superceded by/etc/network/interfacesinstall.sh.allow-hotplug usb0 iface usb0 inet static address 10.20.0.2 netmask 255.255.255.0 network 10.20.0.0 broadcast 10.20.0.255 gateway 10.20.0.1 # upstream computer
After enabling Ethernet gadget mode, the Pi Zero will appear to be a usb network adapter to other computers (hosts). It will have a static IP so other hosts can easily connect using standard TCP/IP protocols like SSH and HTTP. The only configuration necessary is to ensure your host is on the same subnet:
Assuming the Pi Zero uses static IP 10.20.0.2/24 per above, the host could
select
- IP address:
10.20.0.1 - IP subnet:
255.255.255.0
To share internet from another Linux computer (host), use dnsmasq per this SE answer.
- On the host computer, identify
- the interface with Internet access (assumed to be
eth0in this example) - the interface created by the Pi Zero (
usb0in this example)
- the interface with Internet access (assumed to be
- On the host computer, assign a static IP to the Pi Zero interface:
sudo nano /etc/network/interfacesallow-hotplug usb0 iface usb0 inet static address 10.11.12.1 netmask 255.255.255.0 network 10.11.12.0 broadcast 10.11.12.255 - Install
dnsmasqand enable it for the Pi Zero interface:sudo nano /etc/dnsmasq.confThen modify the dnsmasq service file so it continues running even if the network interface is not present:interface=usb0 listen-address=10.11.12.1 bind-interfaces server=8.8.8.8 # or whatever domain-needed bogus-priv dhcp-range=10.11.12.2,10.11.12.100,1hsudo nano /lib/systemd/system/dnsmasq.service[Service] ... Restart=always RestartSec=30 ``` - Enable packet forwarding
- edit
/etc/sysctl.confto enablenet.ipv4.ip_forward=1 - to set immediately:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
- edit
- Create iptables rules (NB results not saved after reboot; see ref for more
details)
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i usb0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o usb0 -j ACCEPT
For details on the testing configuration which included an Nginx reverse proxy, see this Gist.
For small projects, RPi-Monitor is a good quick-and-dirty solution that achieves:
- local system monitoring (cpu, disk space, uptime, etc)
- round-robin database storage (rrdtool)
- web interface (no SSH req'd for monitoring)
- plotting (with time zoom)
The documentation is not spectacular, but it's easy to get started (copied from the debian packaage install docs):
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2C0D3C0F
sudo wget http://goo.gl/vewCLL -O /etc/apt/sources.list.d/rpimonitor.list
sudo apt-get update
sudo apt-get install rpimonitor
Open a web browser and navigate to http://10.11.12.13:8888. There should
be a warning about "Update needed...". Pull updates and enable automatic
updates to keep current:
sudo /etc/init.d/rpimonitor update
sudo /etc/init.d/rpimonitor install_auto_package_status_update
Now copy the relevant modified template files into the appropriate folder.
Hasn't been integrated into the install script yet.
sudo cp etc/rpimonitor/* /etc/rpimonitor/
- replace manual log file creation with
loggingorlogbook- even better, store data into database instead of flat files
- use non-blocking timing mechanism
- replace
sleepwith recursively launched function - a threaded helper for each sensor?
- replace
- properness
turn off OPC-N2 at script exit
Notes from setting up update meeting demo unit.
- Prevent console screen from going blank (b/c there is no way to wake it up)
- Enable auto login to console
- print messages to terminal associated with HDMI display
(
/dev/tty1) instead of script's stdout - force HDMI output so display occurs even if HDMI cord missing at boot time
(edit
/boot/config.txtas approp) - auto-start at boot using
~/.bashrc; press ^C after login to exit prototype script
autostart options that don't work well:
- cron @reboot (maybe worth retrying)
- .bashrc (starts for every shell session)
- /etc/rc.local (no errors, no output)
- systemd service (can uncapture stdout but requires restart after boot to see output; oddly, can see output in boot messages but not once login presented?)