From 2c50e3fe784d2d815862e95e67fda0bbdfb231e5 Mon Sep 17 00:00:00 2001 From: Nis Wechselberg Date: Sun, 1 Sep 2019 19:44:33 +0200 Subject: [PATCH] First throw --- .gitignore | 124 ++++++++++++++++++++++++++ LICENSE | 21 +++++ README.md | 0 RadiationInfluxDaemon.py | 69 ++++++++++++++ RadiationInfluxDaemon.sublime-project | 8 ++ 5 files changed, 222 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 RadiationInfluxDaemon.py create mode 100644 RadiationInfluxDaemon.sublime-project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9ff3fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,124 @@ +###SublimeText### + +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + + +###Python### + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +.static_storage/ +.media/ +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7186abf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Nis Wechselberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/RadiationInfluxDaemon.py b/RadiationInfluxDaemon.py new file mode 100644 index 0000000..12073f4 --- /dev/null +++ b/RadiationInfluxDaemon.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# Python Radiation Logger +# Copyright (c) 2019 Nis Wechselberg +# +# This work is licensed under MIT license. You should have +# received a copy of the MIT license legalcode along with this +# work. If not, see . + +# pylint: disable=C0103 + +""" +Python Radiation Logger + +Small daemon script that parses the data from the MightyOhm Geiger-Mueller Counter. +The data is fed directly to an InfluxDB. +""" + +import argparse +import time +import os + +import serial + +# InfluxDB Client to allow easy submission to time series database +from influxdb import InfluxDBClient + +# Configure argument parsing +parser = argparse.ArgumentParser() +parser.add_argument("dev", help="Device node of the sensor (i.e. /dev/ttyS0)") +parser.add_argument("dbHost", help="Hostname/IP of the InfluxDB machine") +parser.add_argument("dbName", help="Name of the database to write to") + +parser.add_argument("-i", "--interval", help="Time between two measurements (sec)", + type=int, default=180) +parser.add_argument("-n", "--node", help="Node tag to mark the measurement", default="") + +args = parser.parse_args() + +# Make sure the device exists and is readable +if os.path.exists(args.dev): + + ser = serial.Serial(args.dev, 9600) + while True: + ser.flushInput() + ser.readline() + data = ser.readline() + splitdata = data.decode("UTF-8").split(",") + + # Prepare data for database + influxData = [ + { + "measurement": "feinstaub", + "tags": { + "node": args.node + }, + "fields": { + "radiation_cps": splitdata[1], + "radiation_cpm": splitdata[3], + "radiation_dose": splitdata[5] + } + } + ] + + # Send data to InfluxDB + influx = InfluxDBClient(host=args.dbHost, database=args.dbName) + influx.write_points(influxData) + time.sleep(args.interval) +else: + print("Device not found") diff --git a/RadiationInfluxDaemon.sublime-project b/RadiationInfluxDaemon.sublime-project new file mode 100644 index 0000000..24db303 --- /dev/null +++ b/RadiationInfluxDaemon.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "." + } + ] +}