# SolarMonitor-HackRF
A high-resolution radio frequency monitoring system designed for the Raspberry Pi. This project utilizes a HackRF One to scan the spectrum between 26 MHz and 80 MHz (Solar Radio) and 88 MHz to 108 MHz (FM Diagnosis), storing the data in a PostgreSQL database for real-time web visualization.
## Features
* **High-Resolution Scanning**: Uses `hackrf_sweep` with a 50 kHz bin width, capturing 1091 data points per scan.
* **Dual-Band Monitoring**: Automatically switches between Solar Radio monitoring and FM Diagnosis based on a time-window logic.
* **Interactive Web Interface**: Built with Flask and Plotly, allowing users to toggle between HackRF and legacy RTL-SDR data.
* **Time-Series Heatmaps**: Visualizes signal power (dB) over time with a precision of 0.01 MHz.
* **Systemd Integration**: Reliable automation using systemd timers instead of cron, ensuring consistent data collection and service recovery.
## Technical Architecture
### Database Schema
The system uses a PostgreSQL table named `frequency_spectrum` with the following fields:
* `timestamp`: Measurement time with time zone support.
* `band_name`: The specific band scanned (e.g., Solar_Radio).
* `frequency`: Precise frequency in MHz.
* `power`: Signal strength in dB.
* `receiver`: Identifier for the source hardware (hackrf/rtl).
## Installation
### 1. Prerequisites
Ensure you have a running PostgreSQL instance and the HackRF tools installed:
```bash
sudo apt update
sudo apt install hackrf postgresql python3-venv
Clone the repository and create a virtual environment:
git clone [https://github.com/kajoty/SolarMonitor-HackRF.git](https://github.com/kajoty/SolarMonitor-HackRF.git)
cd SolarMonitor-HackRF
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Create a .env file in the project root with your database credentials:
POSTGRES_HOST=your_ip
POSTGRES_DB=solarmonitor
POSTGRES_USER=admin
POSTGRES_PASSWORD=your_password
The scanner is triggered every minute via a systemd timer.
solar_scanner.timer
[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true
[Install]
WantedBy=timers.target
solar_web.service
This service runs the Flask web server on port 5000.
- Access the web interface at
http://<your-pi-ip>:5000. - Choose the time range (1h, 2h, 6h, 24h) and the receiver source from the navigation bar.
- Static heatmap images are generated every 3 hours and stored in the
recordings/directory.
---