Coder Social home page Coder Social logo

jarvissan22 / opc-n3_python Goto Github PK

View Code? Open in Web Editor NEW
12.0 7.0 8.0 15.13 MB

Python repository for OPCN3 and OPCN2 on RPI3

License: GNU General Public License v3.0

Python 74.58% C 14.60% JavaScript 10.02% CSS 0.09% HTML 0.71%
opc opc-n3 opcn3 opcn2 opc-n2 alphasense airquality-sensor sds011 gps

opc-n3_python's Introduction

OPC N3 Python repository

Author: Daniel Jarvis Contacts: [email protected]

Python library for the Aplhasense OPC-N3, and OPC-N2, connected through an SPI interface to a raspberry pi.

  • Additonal support for SDS011 added 28/05/2019
  • Dashboard server added, in AQ/rpi3webserver, for live plotting using a Flask based web server (Let me know if it works) (23/10/2019)

OPC-N3

Repository details

Basic functions scripts "OPCN3_test.py" for direct control of the OPCN3 functions. Basics log scripts "OPCN3_rec.py" to log the data to a CSV and a more advanced functional library under AQ currently operation at the University of Leed and Summit site in Greenland. The AQ library designed to work for multiple OPC attached to the same RPI3 logging all the data to one CSV file.

Dashbord "AQ/AQplotter" ( see repository for further instructions). Dashboard shows diffrent varaibles, as well as options for GPS maps and static maps, what work for multiple sensors in diffrent location. (More updates coming soon) Dashboard

OPCscripts details:

  • opcn3_rec.py OPCN3 functions script
  • opcn2_rec.py OPCN2 function script
  • variables.py sensors operation varaibles, for attaced sensors names and ports, log interval time, opration type (log or GPS) and location name with latitude and longitude coardinets
  • start.py Start oprataion scripts. RUN all sensors attaced and specified in variables.py
  • status.py Checks RPI3 status, logging data on time, IP address, and update RPI time if internet is corrected
  • /DHT DHT Sensors libary by Adafuit
  • DHT.py DHT scripts to be called in start.py to log data to csv
  • GPS.py edits of python GPS scripts by Dan Mandle to be called in start.py to log data to csv
  • AQ/MulOPCData.py script to read the csv output, accounting for multiple OPC attaced to one RPI3

Bascis Function list:

  • initOPC(): , initionate SPI connection with OPCN3
  • fanOn() , turn on fan
  • fanOff(): , turns fan off
  • LazOn(): , turns lazer on
  • LazOff():, turns lazer off
  • RHcon(): , converts RH bytes into RH by RH=100*(bytes/(2^16-1))
  • Tempcon(): , converts OPC Temperature bytes to Temprature (C) by Temp=-45+175*(bytes/(2^16+1))
  • combine_bytes(LSB,MSB): combines upper and lower bytes for bin data
  • getHist(): , gest hist data from OPC
  • getdata(): , gets just PM data from OPC
  • Hisdtdata(): , get outbut from gethist and convert it into the varaible information

AQ repositroy structure:

  • /AQ
  • /AQ/OPCData Directory for log data to be stored
  • /AQ/OPCscripts Scripts to run OPCN3, OPCN2 with options for DHT11 or DHT22 Temprature and RH sensors and GPS attachment.
  • /AQ/AQPlotter Dashboard plotting scripts
  • /AQ/teamviewer-host_14.1.18533_armhf.deb RPI3 installer package for teamviewer allowing romote over a WIFI connection.

AQ set up

Once RPI3 is set up and connected to wifi
default set up packagesexample GPS Plotter scipts in "AQ/AQplotter"

'sudo apt-get update'

'sudo pip install psutil' used to check wifi in status.py

'sudo pip install ntplib' used to check time RPI3 and update it in status.py

Optional Installs

DHT install 'sudo python3 AQ/OPCscripts/DHT/setup.py install'

GPS install GPS used is G-mouse USB Gps Dongle, GPS set up on RPI3 follows those found on this youtube vid by KM4ACK, setting the GPS up as the RPI3 clock as well.

RPI3 external clock if the GPS is not attached to the Adafruit PiRTC is recommended to be attached to the RPI3 to stop the RPI3 time drifting when the internet is lost. Setup instructions

Getting the kit running

in OPCscripts 'cd/OPCscripts'

update varaibles.py 'nano variables.py'

Update the RPI3 name (RPINAME)

operation location (LOC), desired MODE: "LOG" or "GPS" or "TEST". "LOG" is for static site recording to csv, "GPS" added the lat, lon and altitude to csv allowing for mobile usage. "TEST" will create a new data file ever time "start.py" is run

RUNNING sensors (RUNSEN) (Note: multiple OPC sensors can be added) The connection ports (RUNPORTS), if your not sure what port it is 'cd /dev/' then unplug and replug the OPC cable DHT setting, if DHT is connected set "DHTON" to "ON", and insert the DHT name in (DHTNAMES) and connected RPI pin in (DHTPINS)

variables

With all variables now set up hopefully correctly by just running start.py the attached OPC sensors will start logging

'python3 start.py'

This command can be added to crontab to get the sensors running on startup. 'sudo nano crontab -e'

'@reboot python3 AQ/OPCscripts/start.py'

SDS011 support

With an plugged in SDS011, in 'variables.py' add "/dev/ttyUSB0" as the first variable in RUNPORTS and do the same for the name (i.e DSO11_1) in RUNSEN. run 'python start.py' (for some currently unknown reason python3 does not work with the SDS, will fix soon). This will add a columns for the SDSO11s; sds-pm2.5, sds-pm10 and the other unkownvalue (assumed to be TSP) reading.

SDSsetup

Error log:

  • 30/05/2019 Added failed attemt varaible for OPCN3 scripts. Found on Summit by Heather Guy, OPN3 was sending enoguh data using a 5m wire, by increasing the failed attemts in OPCN3_rec.py from 20 to 40 the OPC send the data.

To do:

  • add OPCN3 live databoard, working on the RPi3
  • add functions to change default bin weighting
  • Implement new PM10, PM2.5 and PM1 calculation

Case

opc-n3_python's People

Contributors

jarvissan22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

opc-n3_python's Issues

"self" variable in OPC-N3_rec.py

Hello,

Inside the OPC-N3_rec.py, a lot of the def includes two variable (self, somethingelse). however when ever they are called in the main loop, it only has one variable. As well as there is something called "self.initOPC(ser)" What exactly does it do as this is not found in the OPC-N3_test.py.

Is it something that is required? I"m looking to just run just the OPC-N3 on my pi and finally getting the test version to work, it seemed quite promising.

Thanks!

Keyerror: 'time'

Hello Daniel,
first..very nice job!
I'm facing with the following error after I started the web server:Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/flask/app.py", line 2309, in call
return self.wsgi_app(environ, start_response)
File "/usr/lib/python3/dist-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/usr/lib/python3/dist-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/lib/python3/dist-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3/dist-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/lib/python3/dist-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/pi/OPC-N3_python/AQ/rpiWebServer/interface.py", line 141, in start
data, sens = readrpi3data()
File "/home/pi/OPC-N3_python/AQ/rpiWebServer/interface.py", line 48, in readrpi3data
data["time"] = dateparse(data["time"])
File "/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py", line 2995, in getitem
indexer = self.columns.get_loc(key)
File "/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py", line 2899, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc

File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc

File "pandas/_libs/hashtable_class_helper.pxi", line 1607, in pandas._libs.hashtable.PyObjectHashTable.get_item

File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'time'

Do you have any idea why is not working...I guess is locale setting...
Thanks Marco

python 3 versus 2

Hello Daniel,

Your work has been a godsend! I'm trying to replicate what you've done almost exactly, however I'm having the issue that the start.py code throws up an error when run in python 2, but runs happily in python 3, however when I set GPS mode, the GPS code only runs in python 2.....

any suggestions?

SPI on GPIO

Hi Daniel,
thanks for your great job, do you know why the OPC can't start with /dev/spidev0.0?
I connected it directly with SPI GPIO instead of USB...
Thanks
Best regards Marco

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.