Skip to content

megastef/AirPollutionTracker

Repository files navigation

Air pollution tracker

DIY IoT project for mobile air-pollution measurements and real-time analysis. Read my blog post for more details.

  • Mobile device collecting PM10, PM2.5 sensor data with GPS coordinates
  • Publishing air pollution data via MQTT
  • Storing sensor data as time series with GPS coordinates in Elasticsearch or Sematext Cloud
  • Node.js software for data collection with low memory and CPU footprint (<50 MB RAM, <2% CPU)
  • Device monitoring and log file collection for troubleshooting
  • Visualization
  • Alerts

Table of Contents

Architecture

Hardware

Software

On the device

In the Cloud

  • MQTT Broker mosquitto
  • Elasticsearch or Sematext Cloud Create in Sematext Cloud two logging apps. One for linux logs and one for sensor data. If you like to monitor the Node.js and device performance create a Node.js monitoring app. Dashboards and alerts can be managed in Sematext Cloud. Kibana is integrated. Alternative dashboard tools like Grafana could be used with the Elasticsearch data source for Sematext Cloud.

Kibana dashboard (integrated in Sematext Cloud UI)

Grafana Dashboard using data from Sematext Cloud / Elasticsearch API

On your desktop

  • IoT platforms with MQTT support: Node-Red or Octoblu
  • Web browser
  • SSH terminal

Banana-Pi setup

Wi-Fi setup

A smart phone will serve as mobile Wi-Fi hotspot.
Enable internet tethering (iPhone hotspot) on your mobile phone.

Insert WLAN USB device (if your device has no WLAN chip) Then configure Banana-Pi wlan interface:

  1. Use the WPA passphrase to calculate the correct WPA PSK hash for your SSID (Wi-Fi Network name) by altering the following example
apt-get install wpasupplicant

wpa_passphrase my-mobile-phone-hotspot-name my_very_secret_passphrase

network={
        ssid="myssid"
        #psk="my_very_secret_passphrase"
        psk=ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b
}

Then edit /etc/network/interfaces and enter your WLAN SSID and PSK:

auto wlan0
iface wlan0 inet dhcp
        wpa-ssid myssid
        wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b

Restart the wlan0 interface:

ifdown wlan0 && ifup wlan0

Nova SDS011 setup

Insert the Nova-SDS011 USB connector. Then search for new Ttty devices.

ls -l /dev/tty* | grep 'dialout'
# /dev/ttyUSB0

Note the name for the `input.novaSDS011.comPort setting in the Logagent configuration file.

GPS sensor setup

Insert the USB GPS dongle. Then search for new Ttty devices.

ls -l /dev/tty* | grep 'dialout'
# /dev/ttyACM0

Note the name input.gps.comPort setting in the Logagent configuration file.

Install Node.js

apt-get install build-essential
curl -sL https://deb.nodesource.com/setup_8.x | bash - 
apt-get install -y nodejs

Install Logagent

Install @sematext/logagent and relevant plugins

npm i -g --unsafe-perm @sematext/logagent 
npm i -g --unsafe-perm logagent-gps logagent-novasds
npm i -g --unsafe-perm @sematext/logagent-nodejs-monitor 

Create a system service and default configuration file '/etc/sematext/logagent.conf':

logagent-setup -t indexName -e http://localhost:9200  
service logagent stop

Adjust the Logagent configuration and check following settings:

  • input.novaSDS011.comPort
  • input.gps.comPort
  • input.nodejsMonitor.SPM_TOKEN
  • output.mqtt.url
  • output.elasticsearch.url
  • output.elasticsearch.indices

Test the configuration with

logagent --config logagent.yml 

Copy the working configuration file logagent-config.yml to /etc/sematext/logagent.conf and start the service with

service logagent start 

About

DIY IoT project for air-pollution measurement and real-time analysis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published