# HG changeset patch # User drewp # Date 1580885867 28800 # Node ID 40deafea417420caef6d2e8cc1968f528a83110b # Parent 4322e8b1481f275caa5e1566151aac4dd56f407e rm old airquality client. using esphome and mqtt now Ignore-this: 3852b5ef88c31c5919aa5c4403b768e9 darcs-hash:5372e96f766108126910562ea7b90b800e447e0d diff -r 4322e8b1481f -r 40deafea4174 service/air_particles/Dockerfile --- a/service/air_particles/Dockerfile Tue Feb 04 22:41:51 2020 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -FROM bang6:5000/base_x86 - -WORKDIR /opt - -COPY requirements.txt ./ -RUN pip install -r requirements.txt - -COPY *.py ./ - - diff -r 4322e8b1481f -r 40deafea4174 service/air_particles/Dockerfile.pi diff -r 4322e8b1481f -r 40deafea4174 service/air_particles/air_particles.py --- a/service/air_particles/air_particles.py Tue Feb 04 22:41:51 2020 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -from __future__ import print_function -import sys -import logging -import serial -import time -from influxdb import InfluxDBClient - -logging.basicConfig(level=logging.INFO) -log = logging.getLogger() - -location, = sys.argv[1:] -min_period = 5 - -ser_port = "/dev/ttyUSB0" -ser = serial.Serial(ser_port, baudrate=9600, stopbits=1, parity="N", timeout=2) - -influx = InfluxDBClient('bang6', 9060, 'root', 'root', 'main') - -last_write = 0 -while True: - ser.flushInput() - s = map(ord, ser.read(32)) - if s[:2] != [0x42, 0x4d]: - log.warn('unknown packet header: %s' % s) - continue - - cs = (s[30] * 256 + s[31]) # check sum - check = 0 - for i in range(30): - check += s[i] - if check != cs: - log.warn('checksum mismatch: %s' % s) - continue - - sample = { - # PM1, PM2.5 and PM10 values for standard particle in ug/m^3 - 'pm1_0_std': s[4] * 256 + s[5], - 'pm2_5_std': s[6] * 256 + s[7], - 'pm10_0_std': s[8] * 256 + s[9], - - # PM1, PM2.5 and PM10 values for atmospheric conditions in ug/m^3 - 'pm1_0_atm': s[10] * 256 + s[11], - 'pm2_5_atm': s[12] * 256 + s[13], - 'pm10_0_atm': s[14] * 256 + s[15], - - # Number of particles bigger than 0.3 um, 0.5 um, etc. in #/cm^3 - 'part_0_3': s[16] * 256 + s[17], - 'part_0_5': s[18] * 256 + s[19], - 'part_1_0': s[20] * 256 + s[21], - 'part_2_5': s[22] * 256 + s[23], - 'part_5_0': s[24] * 256 + s[25], - 'part_10_0': s[26] * 256 + s[27], - } - - now = int(time.time()) - if now < last_write + min_period: - continue - if last_write == 0: - log.info('sending first sample: %s', sample) - last_write = now - influx.write_points([{'measurement': 'air_particles', - "fields": sample, - "time": now, - }], - tags=dict(location=location), - time_precision='s') diff -r 4322e8b1481f -r 40deafea4174 service/air_particles/makefile --- a/service/air_particles/makefile Tue Feb 04 22:41:51 2020 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -build_image: - docker build --network=host -t bang6:5000/air_particles_x86:latest . - docker push bang6:5000/air_particles_x86:latest - -build_image_pi: - docker build --file Dockerfile.pi --network=host -t bang6:5000/air_particles_pi:latest . - docker push bang6:5000/air_particles_pi:latest - - -shell: - docker run --rm -it --cap-add SYS_PTRACE --device=/dev/ttyUSB0 --net=host bang6:5000/air_particles_x86:latest /bin/sh - -local_run: - docker run --rm -it --cap-add SYS_PTRACE --device=/dev/ttyUSB0 --net=host bang6:5000/air_particles_x86:latest python air_particles.py local diff -r 4322e8b1481f -r 40deafea4174 service/air_particles/requirements.txt --- a/service/air_particles/requirements.txt Tue Feb 04 22:41:51 2020 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -influxdb==3.0.0 -pyserial==3.4