Skip to content

Commit

Permalink
Update docker-compose.yml and README (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanthoss authored Jun 20, 2021
1 parent 58962cd commit a734b4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Air Quality -> InfluxDB Bridge

This Flask-based server accepts particulate matter/temperature/humidity data from a [sensor.community sensor](https://sensor.community/en/sensors/airrohr) and writes it to a InfluxDB2 instance. It also calculates the Air Quality Index (AQI) with [hrbonz/python-aqi](https://github.com/hrbonz/python-aqi).
This Flask-based server accepts particulate matter/temperature/humidity data from a [sensor.community sensor](https://sensor.community/en/sensors/airrohr) and writes it to a InfluxDB 2.0 server. It also calculates the Air Quality Index (AQI) with [hrbonz/python-aqi](https://github.com/hrbonz/python-aqi).

## Requirements

This project uses Python 3. Install required dependencies with
This project uses Python 3. Install the required dependencies with

```shell
pip install -r requirements.txt
```

## Configuration

The InfluxDB connection is configured via the environment variables `INFLUXDB_V2_URL`, `INFLUXDB_V2_TOKEN`, and `INFLUXDB_V2_ORG`. Other configuration parameters are documented in the [influxdb-client-python README](https://github.com/influxdata/influxdb-client-python#via-environment-properties).
The InfluxDB connection is configured via the environment variables `INFLUXDB_V2_URL`, `INFLUXDB_V2_TOKEN`, and `INFLUXDB_V2_ORG`. Other configuration parameters for InfluxDB are documented in the [influxdb-client-python README](https://github.com/influxdata/influxdb-client-python#via-environment-properties).

Use `INFLUXDB_BUCKET` to configure the bucket (`db0` by default) and `INFLUXDB_MEASUREMENT` to configure the measurement name (`feinstaub` by default).
Use `INFLUXDB_BUCKET` to configure the bucket (default: `sensors`) and `INFLUXDB_MEASUREMENT` to configure the measurement name (default: `air_quality`).

## Development

Expand All @@ -24,27 +24,26 @@ Launch the app locally in development mode and access it at <http://localhost:50
export INFLUXDB_V2_URL="https://localhost:8086"
export INFLUXDB_V2_TOKEN="my-token"
export INFLUXDB_V2_ORG="my-org"
export INFLUXDB_V2_VERIFY_SSL="False"
export INFLUXDB_BUCKET="my-bucket"
export INFLUXDB_MEASUREMENT="feinstaub"
export INFLUXDB_MEASUREMENT="air_quality"
python main.py
```

If everything is configured correctly, executing `curl -X GET http://localhost:5000/info` should return a JSON object that indicates the InfluxDB client is ready.

## Deployment

Build the Docker image:
If you want to build the Docker image locally, execute:

```shell
docker build -t air-quality-influxdb-bridge:devel .
```

Change the environment variables in `docker-compose.yml` and start the Docker service:
## Deployment

```shell
docker-compose up
```
The Docker image from the repository gets automatically build and published to the GitHub Container Registry as [ghcr.io/stefanthoss/air-quality-influxdb-bridge](https://github.com/stefanthoss/air-quality-influxdb-bridge/pkgs/container/air-quality-influxdb-bridge).

The best way to deploy the application is with Docker Compose. Download the `docker-compose.yml` file, change the environment variables according to your local setup, and start the Docker service with `docker-compose up`:

If your InfluxDB server doesn't use a trusted SSL certificate, you'll have to add the environment variable `INFLUXDB_V2_VERIFY_SSL=False`.

## Sample Payload

Expand Down Expand Up @@ -97,7 +96,7 @@ From the sensor firmware version `NRZ-2020-129`:

## Sensor Configuration

In the *Configuration* section of your sensor:
In the *Configuration* section of your air quality sensor:

* Set *Server* to the IP of your deployment.
* Activate *Send data to custom API* and *HTTPS*.
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ version: "3"

services:
air-quality-influxdb-bridge:
image: air-quality-influxdb-bridge:devel
image: ghcr.io/stefanthoss/air-quality-influxdb-bridge:master
container_name: air-quality-influxdb-bridge
restart: unless-stopped
ports:
- "5000:5000"
environment:
- INFLUXDB_V2_URL=https://localhost:8086
- INFLUXDB_V2_TOKEN=my-token
- INFLUXDB_V2_ORG=my-org
- INFLUXDB_V2_VERIFY_SSL=False
- INFLUXDB_BUCKET=my-bucket
- INFLUXDB_MEASUREMENT=feinstaub
- INFLUXDB_MEASUREMENT=air_quality
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/info"]
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
(300, 500): "Hazardous",
}

influxdb_bucket = os.environ.get("INFLUXDB_BUCKET", "db0")
influxdb_measurement = os.environ.get("INFLUXDB_MEASUREMENT", "feinstaub")
influxdb_bucket = os.environ.get("INFLUXDB_BUCKET", "sensors")
influxdb_measurement = os.environ.get("INFLUXDB_MEASUREMENT", "air_quality")

app = Flask(__name__)

Expand Down

0 comments on commit a734b4a

Please sign in to comment.