#!/bin/bash echo "Raspberry Pi Zero W Air Monitoring Setup Script" echo "by J. Devine" echo "*** For use on a fresh installation! 10/6/21 ***" echo "First we set a secure password!" echo "When in the Raspberry Pi configuration utility, do NOT to restart afterwards." read -p "Press enter to continue" sudo raspi-config echo "install influxdb for Raspberry Pi Zero" wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor > /etc/apt/trusted.gpg.d/influxdb.gpg #export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc) echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/debian buster stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list sudo apt-get update && sudo apt-get install -y influxdb rsync git screen i2c-tools iptables-persistent sudo systemctl unmask influxdb.service sudo systemctl start influxdb sudo netstat -naptu | grep LISTEN | grep influxd echo "install Grafana for Raspberry Pi Zero" sudo apt-get install -y adduser libfontconfig1 wget https://dl.grafana.com/oss/release/grafana-rpi_8.0.0_armhf.deb sudo dpkg -i grafana-rpi_8.0.0_armhf.deb echo "installing avahi zeroconf daemon" sudo apt-get install -y avahi-utils avahi-daemon #echo "domain-name=local" | sudo tee -a /etc/avahi/avahi-daemon.conf #echo "publish-hinfo=yes" | sudo tee -a /etc/avahi/avahi-daemon.conf #echo "publish-workstation=yes" | sudo tee -a /etc/avahi/avahi-daemon.conf sudo systemctl enable avahi-daemon.service sudo systemctl start avahi-daemon.service sudo systemctl enable grafana-server.service sudo systemctl start grafana-server.service echo "switching to Python3" sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 echo "installing python3 influxdb module" sudo apt-get install -y python3-influxdb echo "installing pip for python 3 and influxdb library" sudo apt-get install -y python3-pip pip3 install --upgrade influxdb echo "installing log2ram" git clone https://github.com/azlux/log2ram.git cd log2ram chmod +x install.sh sudo ./install.sh echo "redirecting port 3000 to port 80 for Grafana" sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 3000 sudo iptables-save > /etc/iptables/rules.v4 echo "installing BME680 library and MQTT client" pip3 install bme680 paho-mqtt echo "setting up I2C_LCD, CSS811 and air monitoring script" cd /home/pi mkdir airmon cd airmon wget -O I2C_LCD_driver.py https://gist.githubusercontent.com/vay3t/8b0577acfdb27a78101ed16dd78ecba1/raw/6cc9bc9989e549c97b32b9df44fe17b1db5a8950/I2C_LCD_driver.py wget -O airmon_if.py https://gist.githubusercontent.com/pingud98/48062767e93534b0bb2e049bba131df0/raw/e3c021bc8e30b58c5c1a9cd1bb3188a6707f184e/airmon_if.py wget -O CCS811_RPi.py https://gist.githubusercontent.com/pingud98/f21b44db4a646da267f964396b41c017/raw/99550ee263091a371de7d423cfd6a0860678aef3/CCS811_RPi.py wget -O airmon.service https://gist.githubusercontent.com/pingud98/a65a5cbab9b008a32b2f7a1e84a04994/raw/f263c0939c6676b64c7614d82a14d4fe43566f2f/airmon.service sudo cp airmon.service /etc/systemd/system/airmon.service sudo systemctl daemon-reload sudo systemctl enable airmon.service sudo systemctl start airmon.service echo "Enabling and slowing down I2C on Raspberry Pi to 10kbps, required for CCS811 sensor" echo "dtparam=i2c_arm=on" | sudo tee -a /boot/config.txt echo "i2c-dev" | sudo tee -a /etc/modules echo "dtparam=i2c_arm_baudrate=10000" | sudo tee -a /boot/config.txt echo "All done!" read -p "Press enter to reboot" sudo reboot now