#!/usr/bin/env python # -*- coding: utf-8 -*- # # SDS011_Feinstaub_Sensor.py # # Copyright 2017 by luetzel # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # from __future__ import print_function import serial, struct, sys, time import socket,json,requests ser = serial.Serial() #ser.port = sys.argv[1] ser.port = "/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0" #ser.port = "/dev/ttyUSB5" ser.baudrate = 9600 sensebox_id="5cf8a49707460b001b43a245" sensebox_25="5cf8a49707460b001b43a247" sensebox_10="5cfc0d44a1ba9f001a6e57ae" url="https://ingress.opensensemap.org/boxes/%s/%s" pm=[0,0] pm_count=0 ser.open() ser.flushInput() def dump_data(d): print(' '.join(x.encode('hex') for x in d)) def process_frame(d): #dump_data(d) #debug r = struct.unpack(' 1: sensor_wake() time.sleep(30) ser.flushInput() pm25=0 pm10=0 pm_count=0 for n in range(5): pm_data=sensor_read() if(pm_data[0]>0): pm25=pm25+pm_data[0] pm10=pm10+pm_data[1] pm_count=pm_count+1 time.sleep(2) export_data(round(pm25/pm_count,1),round(pm10/pm_count,1)) # sensor_sleep() time.sleep(600) if __name__ == '__main__': import sys sys.exit(main(sys.argv))