Code Monkey home page Code Monkey logo

raspberry-sensor-collector's Introduction

Raspberry sensor collector service

Description

Java service which runs on Raspberry PI and collects data from multiple sensors using PI4J library.

Includes Ansible playbook which can deploy application on Raspberry PI and configure Grafana dashboard for sensor metrics.

Tested on Raspberry PI 2 model B.

The result looks like this:

GrafanaDashboard

Author

  • Bruno Hemar

Sensors

Following sensors are supported:

Temperature and humidity sensor (DHT11)

DHT11

Motion sensor

MotionSensor

Laser sensor

LaserSensor

By default, application will read data from all sensors. If you don't have all sensors, disable missing ones through property file (application.yml)

Connecting sensors with Raspberry PI

If you are not familiar with GPIO pin numbering, check documentation.

Connect signal sensor pins with following Raspberry GPIO pins:

Sensor Raspberry GPIO pin
DHT11 Temperature & humidity sensor 7
Laser 2
Motion 29

GPIO signal pins can be changed in application.yml property file.

Building the project and deploying on Raspberry PI

Prerequisites

Building the project

  • Maven 3
  • Java 11 JDK

Running the application on Raspberry PI

  • Java 11 JRE installed (included in Ansible playbook)
  • wiringpi library installed (included in Ansible playbook)

Build the project

git clone https://github.com/bhemar/raspberry-sensor-collector.git
cd sensor-collector-service
mvn clean install

Deploy on Raspberry manually (without Ansible)

"Target" folder will contain executable jar "sensor-collector-service-1.0.0-SNAPSHOT.jar". Copy jar on Raspberry PI and run it:

cd target
scp sensor-collector-service-1.0.0-SNAPSHOT.jar [email protected]:/tmp/
ssh [email protected]
java -Dpi4j.debug -Dpi4j.linking=dynamic -jar /tmp/sensor-collector-service-1.0.0-SNAPSHOT.jar

Replace 192.168.0.20 with your Raspberry IP address. Of course, you should not use /tmp directory for jar location, this is just an example.

Deploy on Raspberry automatically (using Ansible)

If you have Ansible installed, you can deploy application on Raspberry PI and run it with a single command.

Before running Ansible playbook, check sensor_collector_service_jar_location variable in:

  • ansible/sensor_collector_service/roles/sensor-collector-service/defaults/main.yml

Default is ~/IdeaProjects/sensor-collector-service/target

Run Ansible playbook:

cd ansible/sensor_collector_service/
ansible-playbook raspberry.yml -i hosts -u pi -k -K --tags "sensor-collector-service" -D

Enter your Raspberry password.

Endpoints

The metrics are exposed in Prometheus format:

http://raspberry-pi:9111/actuator/prometheus

Control laser sensor:

http://raspberry-pi:9111/laser/toggle
http://raspberry-pi:9111/laser/blink

Scrape metrics using Prometheus

Add job in prometheus.yml:

scrape_configs:

  - job_name: 'sensor-collector-service'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['raspberry-pi:9111']

Create dashboard for sensor metrics using Ansible

Preconditions:

  • Grafana 5.0 or higher
  • Dashboard provisioning enabled in /etc/grafana/provisioning/dashboards/

Run Ansible playbook with grafana tag:

cd ansible/sensor_collector_service/
ansible-playbook raspberry.yml -i hosts -u pi -k -K --tags "grafana"

Find Raspberry sensors dashboard in Grafana.

raspberry-sensor-collector's People

Contributors

bhemar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.