2021-06-11 01:54:56 +00:00
#!/bin/bash
echo "Raspberry Pi Zero W Air Monitoring Setup Script"
echo "by J. Devine"
2021-06-11 02:05:13 +00:00
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
2021-06-11 01:54:56 +00:00
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"
2021-06-11 02:05:13 +00:00
cd /home/marsa
2021-06-11 01:54:56 +00:00
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.py https://gist.githubusercontent.com/pingud98/0f16f733e2c5a1a2ee1afd3879acd546/raw/3c7e72f12c2d6f0e1f8b3ac783f0c8d7e153c7c4/gistfile1.txt
wget -O CCS811_RPi.py https://gist.githubusercontent.com/xxlukas42/60ae08f75e68a0cfcdb7c9dd60145d34/raw/20bb1ef952c3be3f0c39d1ee49b2f04224b77ee7/CCS811_RPi.py
2021-06-11 02:05:13 +00:00
wget -O airmon.service https://gist.githubusercontent.com/pingud98/a65a5cbab9b008a32b2f7a1e84a04994/raw/feb5cadbad186d847f93ae9b8cb0f614f9685127/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
2021-06-11 01:54:56 +00:00
echo "slowing down I2C on Raspberry Pi to 10kbps, required for CCS811 sensor"
echo "dtparam=i2c_arm_baudrate=10000" | sudo tee -a /boot/config.txt
2021-06-11 02:05:13 +00:00
echo "All done!"
read -p "Press enter to reboot"
2021-06-11 01:54:56 +00:00
sudo reboot now