(https://www.raspberrypi.org/downloads/raspbian/)
(https://sourceforge.net/projects/win32diskimager/)
Add following lines after the last line of config.sts to activate UART port of Raspberry Pi 3.
dtoverlay=pi3-disable-bt
enable_uart=1
- Black(GND) => Pin 6
- White(UART Rx) => Pin 8
- Green(UART Tx) => Pin 10
$ sudo raspi-config
- Change User Password => Change password of default account, pi
- Hostname => Modify as what you want
- Localisation Options => Change Timezone => To where you live
- Interfacing Options => SSH, SPI, I2C, Serial should be enabled
input following command to create rpisensor for execution of RPi_Airbox programs.
$ sudo useradd -r rpisensor
$ sudo mkhomedir_helper rpisensor
$ sudo usermod -aG dialout,gpio,i2c,spi rpisensor
$ sudo nano /etc/sudoers
Let rpisensor execute python script without any prompt of sudo password.
rpisensor ALL=(ALL) NOPASSWD: /usr/bin/python
You can do this through its LAN port or wifi module. It can obtain IP address through DHCP automatically, if you connect by LAN port. However, if you choose wifi, you neen some extra works. First of all, you must know every details of your wifi network.
$ iwconfig wlan0 # Check RPi wifi module
$ sudo iwlist wlan0 scan # Scan available wifi SSIDs
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf # Modiy RPi wifi config
Modify the wifi configuration file and add below lines.
network={
ssid="foo" # Input your wifi SSID
psk="1234567890123" # Your wifi pre-shared key
proto=RSN # Security mode - RSN => WPA2; WPA => WPA (default: "WAP RSN")
key_mgmt=WPA-PSK # WPA authentication - PSK => Pre-Shared Key; EAP => for AAA server ; None => plaintext or WEP (default: "WPA-PSK WPA-EAP")
pairwise=CCMP # AES pairwise - CCMP => AES, WPA2; TKIP => TKIP, WPA (default: "CCMP TKIP")
auth_alg=OPEN # 802.11 authentication algorithms - OPEN => WPA/WPA2; LEAP => LEAP/Network EAP, )
}
If you need to access Internet through proxy, please consider to configure following settings
- apt-get => /etc/apt/apt.conf.d
- git => sudo git config --global http.proxy [your proxy]
sudo git config --global https.proxy [your proxy]
- pip => export https_proxy=[your proxy]
sudo -E pip install [module]
input following command to do this.
$ sudo apt-get update
$ sudo apt-get install -y build-essential python-dev python-pip ntpdate git
$ sudo -HE pip install --upgrade pip
$ sudo -HE pip install psutil
$ cd /opt
$ sudo git clone https://github.com/Freeman3389/RPi_Airbox.git
Here is the Raspberry Pi 3 GPIO numbering diagram.
You can refer to the circuit diagram below to assemble your own RPi_Airbox.
- Display: SH1106(i2c)
- Sensor: MQ2 Smoke (via ADC), DHT22 Temp/Humi(GPIO)
- Output: snmp-passresist
Sample config file - settings.json.type1
- Display: LCD1602(i2c)
- Sensor: DHT22 Temp/Humi(GPIO), Neo6m GPS(UART), PMS3003 PM 2.5(UART)
- Output: snmp-passresit, MQTT, thingspeaks
Sample config file - settings.json
$ sudo mkdir /opt/RPi_Airbox/monitor_web/sensor_values
$ sudo systemctl stop ntp
$ sudo ntpdate [your NTP server]
sudo systemctl disable hciuart
$ sudo nano /opt/RPi_Airbox/settings.json
Check settings of global, especially sensor_location Check settings of each model. If you have the specific module in your RPi box, make sure the status set to 1 to let loader.py bring it up.
Before this part, you have to connect DHT22 sensor to your RPi correctly, and know what GPIO Pin that you connect to DHT22 data pin.
& cd /opt/RPi_Airbox/dht22
$ sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git
$ cd Adafruit_Python_DHT
$ sudo python setup.py install
After this, you can do a simple test by input "examples/AdafruitDHT.py 2302 [GPIO Pin #]". If you can see output like "Temp=26.3 Humidity=44.1%", your DHT22 should work.
- Modify settings.json. The gpio_pin should base on your wiring
- Make sure status of dht22 is 1
Before this part, you have to connect MQ2 sensor to your RPi correctly, and know which ADC channel that you connect to MQ2 Analog pin. (https://tutorials-raspberrypi.com/configure-and-read-out-the-raspberry-pi-gas-sensor-mq-x/)
$ sudo -HE pip install spidev
- mq_channel settings of mq2 in settings.json
- Make sure status of "mq2" is 1.
$ sudo python /opt/RPi_Airbox/mq2/example.py
Wait 5 minutes if no error message. If you can see the value in console, your MQ2 is ready to work.
Check possible serial port device name from output of command below.
$ dmesg | grep tty
By default, it should be /dev/ttyAMA0 or /dev/ttyS0.
Check serial_device of pms3003 settings in settings.json and "status" should be "1".
$ lsusb # confirm PL2302 connectivity
$ ls /dev/ttyUSB* # Make sure correct device name of USB
$ sudo cat /dev/ttyUSB0 # Make sure the connection of GPS module had been established
$ sudo apt-get install -y gpsd gpsd-clients # Install gpsd & client
$ sudo nano /etc/default/gpsd #Modify necessafy settings
Check and modify the following settings based on your environment
DEVICES="/dev/ttyUSB0" # Depend on the USB device name
GPSD_OPTIONS="-n"
GPSD_SOCKET=”/var/run/gpsd.sock”
$ sudo systemctl stop gpsd.socket
$ sudo systemctl disable gpsd.socket
$ sudo systemctl enable gpsd.socket
$ sudo systemctl start gpsd.socket
$ sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock
$ cgps -s
or
$ gpsmon
If you always see 'NO FIX' in cgps, but gpsmon can get your location, try to fix this issue by the following website. (http://wiki.dragino.com/index.php?title=Getting_GPS_to_work_on_Raspberry_Pi_3_Model_B)
Make sure status of neo6m is 1.
$ sudo apt-get install -y python-smbus i2c-tools
after wiring, use command below to check I2C address of LCD1602
$ i2cdetect -y 1
- Make sure status of lcd1602 is 1.
- Check i2c_bus and i2c_address settings in settings.json
Before this part, you have to connect SH1106 screen to your RPi correctly.
(https://luma-oled.readthedocs.io/en/latest/)
Because sh1106-upload.py will get the sensor values from the latest csv files from other sensors,
it should not work before those csv files presented.
$ sudo apt-get install -y i2c-tools python-smbus libfreetype6-dev libjpeg-dev
$ sudo -HE pip install --upgrade pip
$ sudo apt-get purge python-pip
$ sudo -HE pip install --upgrade luma.oled
After installed, input follow command to detect your SH1106 address. The last number in the command is the i2c port number.
$ i2cdetect -y 1
- "i2c_port" => "1" (Unless, your RPi is very old model, and you can try "0")
- "i2c_address" => "[SH1106 address]"
- "device_height" => "64" (By default, but you still have to check your specs)
- "status" => "1"
Because sh1106-upload.py will get the sensor values from the latest csv files from other sensors, it should not work before those csv files presented. Please DONT set its "status" to "1" in settings.json.
$ sudo -HE pip install snmp-passpersist
$ sudo apt-get install -y snmpd
If you have no idea how to modify it, you can refer to the snmpd.conf inside snmp-passpersist directory. However, you have to modify following settings of it according to your network.
rocommunity public 192.168.1.0/24 -V all
=>
rocommiuity [your ro community] [your NMS server] -V all
Add following line into the last of snmpd.conf
pass_persist .1.3.6.1.4.1.16813.1 /usr/bin/python -u /opt/RPi_Airbox/snmp-passpersist/snmp-passpersist-upload.py
Check each element of "sensor-readings-list" array in "snmp-passpersist" sections.
$ sudo usermod -aG snmp rpisensor
$ sudo service snmpd restart
After restarted, check the status of snmpd
$ sudo service snmpd status
$ netstat -ln
$ tail -f /var/log/syslog | grep snmp
- Make sure status of thingspeak is 1
- Modify api_key settings in settings.json
10. Set up MQTT upload to LASS (Please refer to http://lass-net.org/) module
sudo -HE pip install paho-mqtt
- "status" => "1"
- "debug-enable" => "0" # Not ready yet
- "client_id" => "RPiAirbox_[last 6 digits of your MAC address] #
- "username" # Preserve for Node-Red MQTT, not ready yet.
- "passwd" # Preserve for Node-Red MQTT, not ready yet.
sudo -HE pip install paho-mqtt
- "status" => "1"
- "debug-enable" => "0" # If you need to check output value, set to "1"
- "username" #
- "passwd" # Preserve for Node-Red MQTT, not ready yet.
Not ready yet
$ sudo chown -R rpisensor:rpisensor /opt/RPi_Airbox
$ cd /opt/RPi_Airbox
$ /usr/bin/sudo /usr/bin/python /opt/RPi_Airbox/RPi_Airbox_loader.py
You should see the result like below if everything goes well.
Finished checking RPi_Aribox scripts
Loader summary: Enabled - 3 ; Disabled - 6 ; Running - 0 ; Loading - 3
Enabled Modules - sh1106, mq2, dht22
Disabled Modules - thingspeak, global, snmp-passpersist, pms3003, lcd1602, neo6m
Running Modules -
Loading Modules - sh1106, mq2, dht22
RPi_Airbox_loader.py execution time = 46.0970 Secs
$ sudo nano /etc/rc.local
Add these 3 lines below into rc.local before "exit 0"
/usr/bin/sudo /usr/bin/python /opt/RPi_Airbox/RPi_Airbox_loader.py >/dev/null 2>&1
$ sudo crontab -e
Add following 2 lines into crontab, and it will execute the RPi_Airbox_loader.py every hour at 30 minutes,
30 * * * * /usr/bin/sudo /usr/bin/python /opt/RPi_Airbox/RPi_Airbox_loader.py >/dev/null 2>&1