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.
- Features
- Hardware Requirements
- Installation
- Configuration
- Usage
- Project Structure
- Data Visualization
- Alert System
- Database Schema
- 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
- Pine A64 (or compatible single-board computer)
- Temperature/Humidity Sensor: I2C-compatible sensor
- Jumper Wires: For I2C connections (SDA, SCL, VCC, GND)
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.
-
Clone the repository:
git clone https://github.com/Gibirizon/pine64-temp-sensor.git cd pine64-temp-sensor
-
Install dependencies:
uv sync
Or for pip users:
pip install -r requirements.txt
-
Verify sensor connection:
sudo i2cdetect -y 0
You should see your sensor at address
40
.
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
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 |
- Enable 2-factor authentication on your Google account
- Generate an App Password: Google Account β Security β App passwords
- Use the App Password in your
config.ini
file
# Run a single measurement cycle
python main.py -s config.ini
python main.py [OPTIONS]
Options:
-s, --setup_file PATH Configuration file path (required)
-h, --help Show help message
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
- 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
The system automatically generates two charts after each measurement:
Charts are configured via the ChartConfig
dataclass in src/config.py
:
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
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) |
- Pine64 community for hardware support
- SQLAlchemy team for excellent ORM
- Matplotlib developers for visualization tools
- smbus2 maintainers for I2C communication