Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

πŸ”©πŸšͺ - A simple server to receive the Ruuvi station data and store it in databases

Notifications You must be signed in to change notification settings

ruuvi-friends/ruuvi-gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Status codecov

Ruuvi πŸ”© gateway πŸšͺ

A simple flask server to relay data from the ruuvi station

Intro

Ruuvi tags have a neat app that accesses the data of your ruuvi sensors. However the app does not have long term persistence, and you don't have any easy way to export long term data.

The app has, however, support for a gateway, that sends data as POST request to a server. -- The docs can be found here

This project acts as that gateway to push data to databases

Currently supported backends

  • InfluxDb
  • CSV file

Starting

  1. Change the configs or provide them them in the docker env
  2. Deploy the app somewhere
  3. Use <your_server_address>/station/v3/push in the Ruuvi station app

Authorization

CURRENTLY NOT SUPPORTED! - see issue in app repo

You might not want to have a server that anyone can push things into. You can add a layer of authentication through the settings

BASIC_AUTH_FORCE=True
BASIC_AUTH_USERNAME='user'
BASIC_AUTH_PASSWORD='pass'

After that you should add those to your Ruuvi mobile app gateway address like: https://user:pass@<yourserver>/station/v3/push

CSV Adapter

This is the simplest of use cases, which is to dump all the data to a CSV file. All you need to do is set the env variable: CSV_FOLDER with the folder (eg. /User/you/Desktop)

To keep the files from growing forever, there will be one file per day:

β”œβ”€β”€ CSV_FOLDER/
β”‚   β”œβ”€β”€ 20200101.csv
β”‚   β”œβ”€β”€ 20200102.csv
β”‚   β”œβ”€β”€ 20200103.csv
β”‚   └── ...

InfluxDB support

# INFLUXDB PARAMETERS

INFLUX_DB_NAME="ruuvi"  # Mandatory

# INFLUX_URL=           # defaults to 'localhost'
# INFLUX_PORT=          # defaults to 8086
# INFLUX_USER=          # defaults to none
# INFLUX_PASSWORD=      # defaults to none

Testing things

  1. To easily test things you can spin a docker container of influx+kapacitor
docker network create -d bridge ruuvi-influx
docker run -p 8086:8086 --network ruuvi-influx --name influxdb influxdb
docker run -p 8888:8888 --network ruuvi-influx chronograf
  1. Run the ruuvi-gateway:

    • Using docker

      • Change the configurations (see configs section)
      • docker build -t ruuvig-gateway .
      • docker run -p 5000:5000 -v --env-file docker_env.env --network ruuvi-influx ruuvig-gateway
      • OR
      • docker run -p 5000:5000 -v $(pwd)/instance:/app/instance --network ruuvi-influx ruuvi-gateway
    • Or Using your local environment

      • Change the configurations in instance/config.py
      • pipenv install
      • pipenv run pipenv run flask run --host=0.0.0.0
  2. When accessing chronograf on localhost:9092, you should also configure it with the influxdb address influxdb:8086

  3. You should start seeing data coming in

Configurations and deployment

Notes about Docker It's a bad practice to include the configurations inside the docker image. Especially if they contain secrets. To mitigate this you can either use env variables for the configuration, or you can map the instance folder into the docker container. Runing the container without any configurations will possibly result in the message NO GATEWAYS ARE CONFIGURED!. Your options are:

  • Give variables via docker run / docker compose, et

     `docker run -p 5000:5000 --env-file docker_env.env ...... ` 
    
     `docker run -p 5000:5000 --env INFLUX_DB_NAME=ruuvi --env INFLUX_URL=influxdb .....`
    
  • Map the instance folder (that is not originally in the image) which will override the defaults

A production ready image is published in sergioisidoro/ruuvi-gateway in docker hub

Contributing.

To add a new adapter, you should implement the methods is_ready, and connect_and_push_metrics. After that, import your adapter in gateway.py and it here:

def __init__(self, config):
        your_adapter = YourAdapter(config)
        ...
        self.adapters = [
            influx_adapter
            your_adapter
        ]

To see data, and add test cases, head over to /tests/fixtures.py

πŸ₯³ Authors

About

πŸ”©πŸšͺ - A simple server to receive the Ruuvi station data and store it in databases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published