data-hydenv / pmserver

small flask app to read a SDS011

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PM Server

Driver needed. Windows and Mac users with older OS versions might need a driver to read the sensor over the serial console. From what I have experienced so far, the drivers for CH34x devices are fine. There are various available like: https://sparks.gogo.co.nz/ch340.html

Description

PM Server is a Python application that can be used to monitor particualte matter measurements from a nova SDS011 sensor connected to the computer. The application is still experimental and more or less only tested on a ubuntu 18 .04 OS. However, CIs are compiling the application into various executables for Linux, Windows and Mac OSX. These files can be found in the Github Release section.

There are two in this repository, either available as Python script or as executable:

  • pm2csv.py command line tool for saving particulate matter measurements into a CSV file
  • pmserver a browser based graphical application for monitoring particulate matter. The Python module is called pmserver, while the application itself is called pmMonitor.

Releases

Both applications can either be used as Python modules or as executables. The main advantage of Python is, that the Github version is always up-to-date, while the executable are only build for a new release. If you are familiar with Python, you can easily modify the code and reuse it. The main advantage of the executables is that you do not need Python installed at all to run the application. However, error handling will be more complicated with the bundled versions.

Find the build status of the different versions below:

EnvironmentStatus
Linux / OSX
Windows

latest build: https://github.com/data-hydenv/pmserver/releases

Installation

In case you want to use one of the executables, just navigate to the latest release and download the executable suitable for your operation system: https://github.com/data-hydenv/pmserver/releases

The other option is to download the source files from the latest release, or clone the whole repository (recommended). Cloning the repository will download the latest version of pmserver:

git clone https://data-hydenv/pmserver.git

Optionally, you can also download the full repository from github as a .zip and unzip the folder.

Next, you need to install the dependencies listed in requirements.txt:

cd pmserver
pip install -r requirements

Now, you can run the pm2csv.py with the same Python environment like:

python pm2csv.py /dev/ttyUSB0

The graphical monitoring version can either be started by serv.py in the root directory or by pmserver/app.py. The main difference is that serv.py will additionally open a web-browser for you and point to the correct URL. Unfortunately, this sometimes failes and I have no idea why. Then, you'll have to use pmserver/app.py open the browser and point to http://localhost:5000 yourself.

Usage

pmMonitor

The pmMonitor just has to be started. Sometimes the application does not open a web browser automatically. Then, with the application running, you'll have to open a brwoser yourself and point to http://localhost:5000.

pm2csv

pm2csv needs at least one argument passed, which is the device address of the nova SDS011. In Windows, this is something like COM1, COM2 and so on. In Unix, the USB devices are mounted at /dev/ttyUSB0, /dev/ttyUSB1 and so on. Plug the sensor in and out to see which address is appeaing and disappearing. That's the one you need.

To use the script, open a console at the location of the Python script or executable and run it.

python pm2csv.py /dev/ttyUSB0

Will start recording measurements every 15 seconds into a file called pm.csv at the same location. The new data will be appended. Additionally the measurements will be printed to the screen. Help for the usage can be view by using the --help (-h) flag:

python pm2csv.py --help

This will output something similar to:

usage: pm2csv [-h] [-b BAUDRATE] [-o OUTPUT] [-s STEP] [-q] device_path

Command line tool for saving particulate-matter measurements from a nova
SDS011 into a CSV file.

positional arguments:
  device_path           Device path of the sensor. Typically 'COM1' on Windows
                        or '/dev/ttyUSB0' on Linux.

optional arguments:
  -h, --help            show this help message and exit
  -b BAUDRATE, --baudrate BAUDRATE
                        Device baudrate for serial communication. Typical
                        values are 9600 or 57600. Defaults to 9600.
  -o OUTPUT, --output OUTPUT
                        Output file name. The new readings will be appended to
                        this file in CSV format. Defaults to 'pm.csv'.
  -s STEP, --step STEP  Step width for the measurements in seconds. It is not
                        recommended to use values smaller than 3 seconds.
                        Defaults to 15 [secs].
  -q, --quiet           Suppress printing values to the screen.

About

small flask app to read a SDS011


Languages

Language:HTML 54.5%Language:Python 45.5%