Skip to content

Gaston202/Plugjuice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Plugjuice

A Raspberry Pi Zero energy-monitoring project that reads current/voltage/power from an INA219 sensor, streams the data to InfluxDB, and visualizes it in Grafana — with a relay on GPIO for load control.

Plugjuice turns a Raspberry Pi Zero into a low-cost power-monitoring node. An INA219 current sensor measures the consumption of a connected load over I2C; a Python script periodically writes the readings to a local InfluxDB time-series database; Grafana then dashboards the data in real time. A separate relay script demonstrates switching a load on/off via GPIO.


✨ Features

  • 📡 Current, voltage & power sensing via the Adafruit INA219 (I2C)
  • 🗄️ Time-series storage in InfluxDB (consommation_energie measurement)
  • 📊 Real-time dashboards in Grafana
  • 🔌 Relay control over a load through a GPIO pin (BOARD pin 13)
  • 🪶 Lightweight — designed to run on Raspberry Pi Zero with Raspberry Pi OS Lite

🧱 Tech Stack

Layer Technology
Board Raspberry Pi Zero (Raspberry Pi OS Lite)
Sensor Adafruit INA219 current/voltage/power sensor (I2C)
Actuator Relay module on GPIO (BOARD pin 13)
Language Python 3
Sensor lib adafruit-circuitpython-ina219, busio, board (CircuitPython)
GPIO RPi.GPIO
Database InfluxDB 1.x (via python3-influxdb)
Visualization Grafana

📁 Project Structure

File Purpose
read_current.py Standalone diagnostic tool — prints current (A), voltage (V), and power (W) from the INA219 to the console every 2 s. Use it to verify your wiring before enabling streaming.
send_data.py Main script — reads current from the INA219 and writes a data point to InfluxDB every 1 s.
relay.py Proof-of-concept — toggles the relay (BOARD pin 13) HIGH for 1 s then LOW. Use as a starting point for load-control logic.

🔌 Hardware Setup

Components

  • Raspberry Pi Zero (or any Pi with I2C + GPIO)
  • Adafruit INA219 breakout board
  • Relay module
  • The load you want to monitor (and optionally switch)

Wiring

Component Raspberry Pi pin Notes
INA219 SCL I2C SCL (GPIO 3 / pin 5) Enable I2C via sudo raspi-config → Interfacing Options → I2C
INA219 SDA I2C SDA (GPIO 2 / pin 3)
INA219 VCC / GND 3.3 V / GND
Relay signal BOARD pin 13 (BCM GPIO 27) relay.py uses GPIO.setmode(GPIO.BOARD)

Verify the I2C device is visible: sudo i2cdetect -y 1 — the INA219 typically shows up at address 0x40.


🚀 Getting Started

1. Clone the repository

git clone https://github.com/Gaston202/Plugjuice.git
cd Plugjuice

2. Enable I2C on the Pi

sudo raspi-config   # Interfacing Options → I2C → enable, then reboot
sudo apt-get install -y i2c-tools
i2cdetect -y 1       # confirm the INA219 appears (default 0x40)

3. Install Python dependencies

pip install adafruit-circuitpython-ina219
# CircuitPython busio/board are part of the bundle and usually preinstalled

sudo apt-get install -y python3-rpi.gpio
sudo apt-get install -y python3-smbus
sudo apt-get install -y python3-influxdb

4. Set up InfluxDB

sudo apt-get install -y influxdb
sudo systemctl unmask influxdb.service
sudo systemctl start influxdb
sudo systemctl enable influxdb.service

Create the database that send_data.py writes to (default name ma_base_de_donnees):

influx
> CREATE DATABASE ma_base_de_donnees
> exit

5. Set up Grafana

# The original README installs a specific old build:
sudo dpkg -i --force-all grafana_6.0.1_armhf.deb
sudo service grafana-server start
# (Recommended: install a current Grafana release from the official APT repo instead.)

Open Grafana at http://<pi-ip>:3000, add InfluxDB as a data source (database ma_base_de_donnees), and build a dashboard querying the consommation_energie measurement.

6. Configure & run

The InfluxDB connection is defined at the top of send_data.py — adjust to match your setup:

hote_influxdb = "localhost"
port_influxdb = 8086
base_de_donnees_influxdb = "ma_base_de_donnees"
mesure_influxdb = "consommation_energie"

Run the scripts:

python read_current.py   # quick sanity check of sensor readings
python send_data.py       # start streaming to InfluxDB (Ctrl+C to stop)
python relay.py           # test the relay toggle

🔄 Data Flow

INA219 (I2C) ──► Raspberry Pi Zero ──► send_data.py ──► InfluxDB ──► Grafana dashboard
                                        (1 s interval)   (localhost:8086)
            relay.py ──► GPIO pin 13 ──► relay ──► load

📜 Scripts Reference

Script Reads Writes Interval
read_current.py INA219 current/voltage/power stdout (console) 2 s
send_data.py INA219 current (mA) InfluxDB consommation_energie measurement 1 s
relay.py GPIO BOARD pin 13 (HIGH 1 s → LOW) one-shot

⚠️ Known Issues & Roadmap

  • Unit bug in send_data.py — the comment says "Convert mA to A" but the function returns ina219.current unchanged (which is in mA), so the value stored in InfluxDB is in milliamps. Either divide by 1000 to store amps, or update the field name/comment to reflect mA.
  • Hardcoded DB config — move InfluxDB host/database/measurement into environment variables or a config.py/.env file; avoid committing real credentials.
  • No requirements.txt — add one (or a Pipfile) to make setup reproducible.
  • Relay is not integrated with the sensing loop — wire relay control to a threshold (e.g., cut power above N W).
  • Grafana version — the README pins Grafana 6.0.1 (2019); install a current release instead.
  • Add a ready-to-import Grafana dashboard JSON.

🤝 Contributing

This is a personal/learning project, but contributions are welcome.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is open-source and available under the MIT License.


👤 Author

GastonGitHub @Gaston202

Built as a Raspberry Pi IoT project to practice hardware sensing, time-series databases, and data visualization.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages