Giter VIP home page Giter VIP logo

growlab-data-logger's Introduction

BME280 Data Logger with faasd

This data logger writes measurements from a Bosch BME280 or BMP280 sensor into a InfluxDB time-series database.

Deployment

You will run faasd on your Raspberry Pi 2, 3 or 4 to store data readings and to run OpenFaaS and Grafana.

On your Raspberry Pi Zero, or whichever host has a sensor connected to it, you'll run the sender app.

Deploy faasd

Deploy faasd to your Raspberry Pi 3 or 4 using these instructions

Customise the password, and update /var/lib/faasd/docker-compose.yaml

  influxdb:
    image: docker.io/library/influxdb:1.8
    environment:
      - INFLUXDB_DB=defaultdb
      - INFLUXDB_ADMIN_USER=admin
      - "INFLUXDB_ADMIN_PASSWORD=PASSWORD"
      - INFLUXDB_USER=user
      - "INFLUXDB_USER_PASSWORD=PASSWORD"
      - INFLUXDB_REPORTING_DISABLED=true
      - INFLUXDB_HTTP_AUTH_ENABLED=true
      - INFLUXDB_HTTP_BIND_ADDRESS=0.0.0.0:8086
    volumes:
      # we assume cwd == /var/lib/faasd
      - type: bind
        source: ./influxdb/
        target: /var/lib/influxdb
    user: "1000" 
    cap_add:
      - CAP_NET_RAW
    ports:
      - "0.0.0.0:8086:8086"

Make a directory for InfluxDB:

mkdir -p /var/lib/faasd/influxdb
chown 1000:1000 /var/lib/faasd/influxdb

Then reload and restart:

sudo systemctl daemon-reload \
  && sudo systemctl restart faasd

Deploy the function

Create a secret for the InfluxDB user:

export PASSWORD=""

faas-cli secret create influx-password --from-literal $PASSWORD
faas-cli secret create influx-user --from-literal admin

Set the influx_db env-var in stack.yml i.e. 192.168.0.21

Next, deploy the function:

faas-cli deploy

Build if you like:

faas-cli publish -f stack.yml --platforms linux/arm/7

Deploy the sender onto your Raspberry Pi with a sensor

On your Raspberry Pi with the sensor, you'll run the "sender" app.

Enable i2c and change the hostname as required using the raspi-config tool.

If you haven't installed the main growlab app for live-previews, then install the below dependencies:

sudo apt update -qy && \
  sudo apt install -qy python3 \
  i2c-tools \
  python3-pip \
  git \
  tmux

Clone the growlab app:

git clone https://github.com/alexellis/growlab
cd growlab/data-logger/sender/

Install any pip modules required for the sender app:

pip3 install -r requirements.txt

Then run the sender app:

FUNCTION_URL=http://192.168.1.42:8080/function/submit-sample \
  SENSOR=bme280 \
  python3 main.py

Note: if you're using a BMP280 sensor then add an addition environment variable of SENSOR=bmp280

A sensor reading will be submitted to faasd every 30 seconds. You can alter this sample interval by editing sender/main.py.

Going further with a dashboard

Deploy Grafana to faasd using the instructions in the eBook Serverless For Everyone Else

Then create yourself a simple dashboard for the measurements you see in the "readings" database.

Once you have it up and running, create a datasource, then import the dashboard.json file and open the dashboard to view your sensor readings.

A very cold shed

My very cold shed - measured overnight!

growlab-data-logger's People

Contributors

felipecruz91 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.