Skip to content

wenchen/pi-pm25-sensor-a4

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CP-15-A4-CG

Read Particulate Matter (PM) data with A4 Sensor. Added ability to intergrate with InfluxDB by using collectd.

Installation

Prerequisites

  • Python 2
  • pyserial, pip install pyserial

Quick Start

  1. Obtain the location of serial device (e.g. /dev/ttyUSB0)
  2. Update the last line of a4.py with that location
print air.read("/dev/ttyAMA0") // update device
  1. Test run
python a4.py

Intergrate with InfluxDB and collectd

  1. Install Collectd & influxDB
sudo apt install collectd influxdb
  1. Edit /etc/influxdb/influxdb.conf with following content:
[[collectd]]
  enabled = true
  bind-address = ":25827"
  database = "pm25_db"
  typesdb = "/etc/influxdb/pm25/"
mkdir -p /etc/influxdb/pm25
cp types.db /etc/influxdb/pm25
ln -s /etc/influxdb/pm25/types.db /usr/share/collectd/types.db
  1. Change /etc/collectd.conf with following content
LoadPlugin network
LoadPlugin python
<Plugin network>
    Server "127.0.0.1" "25827"
    Forward true
</Plugin>
<Plugin python>
    ModulePath "/home/pi/pi-pm25-sensor-a4"
    LogTraces true
    Interactive false
    Import "monitor_collectd"
    <Module monitor_collectd>
        hostname "room-3f"
        dev "/dev/ttyAMA0"
    </Module>
</Plugin>
  1. Restart collectd and Influxdb
sudo systemctl restart collectd
sudo systemctl restart influxdb

NOTE: While using Grafana, one may import dashboard from pm2.5.json

Usage

python a4.py [21, 32, 31, 947, 1963, 5959, 35, 0, 0]

[pm1, pm10, pm2.5, 0.3um, 0.5um, 1.0um, 2.5um, 5.0um, 10um]

Notes

  • Remember to remove any serial console related configurations from cmdline.txt
  • To stop any messages like sysrq: Sysrq : HELP : .....: echo 0 > /proc/sys/kernal/sysrq

About

read pm data from a4 sensor with python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%