Skip to content

🌑️Smart environmental monitoring for Pine A64 - I2C sensors, πŸ“Š charts, 🚨 alerts, πŸ’Ύ SQLite storage

Notifications You must be signed in to change notification settings

neogib/pine64-temp-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Pine A64 Temperature & Humidity Monitor πŸŒ‘οΈπŸ’§

A comprehensive monitoring system for the Pine A64 that reads temperature and humidity data from an I2C sensor, stores measurements in a database, generates visualizations, and sends email alerts when temperature thresholds are exceeded.

πŸ“‹ Table of Contents

✨ Features

  • Real-time Monitoring: Continuous temperature and humidity measurements via I2C
  • Data Persistence: SQLite database storage
  • Visual Analytics: Automated chart generation with statistical summaries
  • Smart Alerts: Email notifications when temperature drops below threshold
  • Professional Logging: Comprehensive logging to both file and console
  • Modular Design: Clean, object-oriented architecture for easy maintenance
  • Configuration Management: External config file for email settings

πŸ”§ Hardware Requirements

Primary Components

  • Pine A64 (or compatible single-board computer)
  • Temperature/Humidity Sensor: I2C-compatible sensor
  • Jumper Wires: For I2C connections (SDA, SCL, VCC, GND)

Wiring Diagram

Pine A64          Sensor
--------          ------
Pin 3 (SDA)   β†’   SDA
Pin 5 (SCL)   β†’   SCL
Pin 4 (3.3V)  β†’   5V
Pin 6 (GND)   β†’   GND

Based on the Pine A64 Pi-2 Connector.

πŸš€ Installation

  1. Clone the repository:

    git clone https://github.com/Gibirizon/pine64-temp-sensor.git
    cd pine64-temp-sensor
  2. Install dependencies:

    uv sync

    Or for pip users:

    pip install -r requirements.txt
  3. Verify sensor connection:

    sudo i2cdetect -y 0

    You should see your sensor at address 40.

βš™οΈ Configuration

Email Setup

Create a config.ini file in the project root:

[MAIL]
sender = your-email@gmail.com
password = your-app-password
server = smtp.gmail.com
port = 465
recipient = alert-recipient@gmail.com

Configuration Parameters

The config.py file contains the following (and more) parameters:

Parameter Description Default
i2c_bus I2C bus number 0
device_address Sensor I2C address 0x40
measurement_delay Delay between measurements (seconds) 0.5
LOWER_TEMP_THRESHOLD Temperature alert threshold (Β°C) 1

Gmail Setup (Recommended)

  1. Enable 2-factor authentication on your Google account
  2. Generate an App Password: Google Account β†’ Security β†’ App passwords
  3. Use the App Password in your config.ini file

🎯 Usage

Basic Operation

# Run a single measurement cycle
python main.py -s config.ini

Command Line Arguments

python main.py [OPTIONS]

Options:
  -s, --setup_file PATH  Configuration file path (required)
  -h, --help            Show help message

πŸ“ Project Structure

pine-a64-monitor/
β”œβ”€β”€ main.py                 # Entry point and CLI interface
β”œβ”€β”€ config.ini              # Email configuration (create this)
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ measurement.log         # Application logs
β”œβ”€β”€ measurements.db         # SQLite database
β”œβ”€β”€ charts/                 # Generated visualizations
β”‚   β”œβ”€β”€ temperature.png
β”‚   └── humidity.png
└── src/
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ measurement_system.py  # Main orchestration logic
    β”œβ”€β”€ database.py           # SQLAlchemy models and DB management
    β”œβ”€β”€ chart_generator.py    # Matplotlib chart generation
    β”œβ”€β”€ mailer.py            # Email notification system
    β”œβ”€β”€ email_templates.py   # HTML/text email templates
    └── config.py            # Configuration constants and dataclasses

Core Components

  • MeasurementSystem: Orchestrates the complete workflow
  • DatabaseManager: Handles SQLite operations with context management
  • ChartGenerator: Creates publication-quality matplotlib visualizations
  • Mailer: Sends formatted email alerts with HTML templates

πŸ“Š Data Visualization

The system automatically generates two charts after each measurement:

Chart Customization

Charts are configured via the ChartConfig dataclass in src/config.py:

🚨 Alert System

Temperature Alerts

Automatic email notifications are sent when:

  • Temperature drops below LOWER_TEMP_THRESHOLD (default: 1Β°C)
  • Configurable threshold in src/config.py

Modify thresholds in src/config.py to change alert behavior:

LOWER_TEMP_THRESHOLD = 1  # Change this value

πŸ—„οΈ Database Schema

Measurement Table

Column Type Description
id INTEGER Primary key (auto-increment)
temperature FLOAT Temperature in Celsius
humidity FLOAT Relative humidity percentage
timestamp DATETIME Measurement time (auto-generated)

πŸ™ Acknowledgments

  • Pine64 community for hardware support
  • SQLAlchemy team for excellent ORM
  • Matplotlib developers for visualization tools
  • smbus2 maintainers for I2C communication

About

🌑️Smart environmental monitoring for Pine A64 - I2C sensors, πŸ“Š charts, 🚨 alerts, πŸ’Ύ SQLite storage

Topics

Resources

Stars

Watchers

Forks

Languages