Git Product home page Git Product logo

sds-sensor-reader's Introduction

SDS Sensor Reader

This python script can be used to read the data from the SDS011/SDS18/SDS021 and upload it to the aqicn.org server.

The script continuously reads the data from the SDS sensor, and, every minute, uploads the average, median and standard deviation to the server.

For more information, refer to https://aqicn.org/data-feed/upload-api/

Installation

Make sure to update the USB port and sensor ID configuration in the script, lines 9 to 12:

LOCATION = {'latitude': 28.7501, 'longitude': 77.1177}
TOKEN    = "dummy-token-for-test-purpose-only"
SENSORID = "YOUR-SENSOR-ID"
USBPORT  = "/dev/ttyUSB0"

For the TOKEN, you can get one from this page: https://aqicn.org/data-platform/token/

For the SENSORID, you can use any name less than 128 characters. This ID is only used for you to help if you have multiple sensors.

For the USBPORT, you need to check on which USB port is the serial USB converter mounted. Check https://learn.sparkfun.com/tutorials/terminal-basics/connecting-to-your-device for more information.

Running the script

Just use: python sds-reader.py

Output example:

Starting reading sensor YOUR-SENSOR-ID on port /dev/ttyUSB0
Reading [ 1]: {'pm2.5': 6.174900567257725, 'pm10': 3.1934677522143726}
Reading [ 2]: {'pm2.5': 7.555017736539956, 'pm10': 7.020834793042507}
Reading [ 3]: {'pm2.5': 0.3844247110354293, 'pm10': 7.771734774405182}
Reading [ 4]: {'pm2.5': 3.22681824227835, 'pm10': 2.3183160649668055}
Reading [ 5]: {'pm2.5': 6.571437982807612, 'pm10': 8.10732336965939}
Reading [ 6]: {'pm2.5': 2.215579055773339, 'pm10': 8.498171362504383}
Reading [ 7]: {'pm2.5': 8.027524718085807, 'pm10': 5.8429776102899025}
Reading [ 8]: {'pm2.5': 6.2517504261702515, 'pm10': 2.263619703316302}
...
Reading [60]: {'pm2.5': 5.775826608467894, 'pm10': 2.6825255819326377}
Uploading: {
    "token": "dummy-token-for-test-purpose-only",
    "station": {
        "id": "YOUR-SENSOR-ID",
        "location": {
            "latitude": 28.7501,
            "longitude": 77.1177
        }
    },
    "readings": [
        {
            "specie": "pm2.5",
            "min": 0.3844247110354293,
            "max": 9.881988173998357,
            "median": 5.775826608467894,
            "value": 5.370915456820213,
            "stddev": 2.6854456309512917
        },
        {
            "specie": "pm10",
            "min": 0.016951997552983045,
            "max": 9.79528005515607,
            "median": 5.114991470114239,
            "value": 4.877448712778561,
            "stddev": 2.8556849925322383
        }
    ]
}
Data successfully posted: {u'status': u'ok', u'station': 1000003}    

sds-sensor-reader's People

Contributors

florentinbulotaq avatar lpmi-13 avatar ronanj avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sds-sensor-reader's Issues

queue file read/write problem

Very useful and well maintainable code - thank you for sharing. - I have made amendments and run this as a system service and redirect stdout (>) and stderr (2>) to /mnt/ram (a ramdisk in a RasPi to further reduce flash wear) and caught the following error after about an hour of runtime - issue 1:

Traceback (most recent call last):
  File "sds-reader.py", line 229, in <module>
    loop(USBPORT)
  File "sds-reader.py", line 223, in loop
    uploader.postValues(reader.read(60))
  File "sds-reader.py", line 191, in postValues
    self.file_put_contents(filePath2,pickle.dumps(values))
  File "sds-reader.py", line 162, in file_put_contents
    with open(filename,'w') as f:
IOError: [Errno 13] Permission denied: 'pending.30c1.2017-09-01-14-25-09.pickle'

Issue 2: During an http 200 OK posting I get this message that I do not really understand (I have however increased the POST payload):

Posting 33680 bytes -> 200 OK
http-post: error. <type 'exceptions.ValueError'>
upload not ok... there are now 58 entries pending (/mnt/ram/30c1.pickle).

For sensor type SDS011, I had do divide the PM10 and PM2.5 values by 10.

On smartgart.com/pm10, I have started to aggregate the measurements with Yahoo JSON weather data to include weather condition (like rain), wind direction, wind speed, atmospheric pressure for the purpose of monitoring pollution from a nearby waste incineration plant, and in the future perhaps to try to correlate the values (like: if ... more incoming wind, less rain, higher atmospheric pressure ... then ... more PM10 dust).

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.