Telegram

Someone is Working on an Awesome Pi-hole Dashboard, Complete with an OLED Screen

Here at Magisk Modules, we’re constantly exploring innovative ways to enhance our digital lives, optimize network performance, and bolster online privacy. That’s why we’re incredibly excited to share a deep dive into a truly captivating project: an enhanced Pi-hole dashboard, beautifully complemented by an OLED screen for real-time monitoring. While many have implemented standard Pi-hole setups, this project takes the concept to a whole new level of elegance and functionality. Prepare to be inspired as we dissect the intricacies of this impressive endeavor.

Elevating Pi-hole: Beyond the Standard Web Interface

Pi-hole, the network-level advertisement and tracking blocker, is already a powerful tool. Its default web interface provides essential insights into network activity, blocked domains, and query logs. However, for users craving a more visually engaging and immediately accessible overview, a dedicated dashboard is a game-changer. This project transcends the limitations of the standard interface by offering:

The Allure of OLED: Why This Display Technology Matters

The choice of an OLED (Organic Light Emitting Diode) screen is no accident. OLED technology offers several advantages over traditional LCD displays, making it the ideal choice for this project:

Deep Dive: Components and Software Architecture

Building such a sophisticated dashboard requires a combination of hardware and software expertise. Let’s break down the key components and their roles:

Hardware Components

Software Architecture

The software side of the project involves several key components working in concert:

Implementation Details: From Code to Completion

Let’s delve into the practical aspects of building this enhanced Pi-hole dashboard.

Setting Up the Raspberry Pi

  1. Install Raspberry Pi OS: Start by installing the latest version of Raspberry Pi OS (formerly Raspbian) on an SD card. We recommend using the Raspberry Pi Imager tool for this process.

  2. Enable SSH: Enable SSH access to the Raspberry Pi so that you can connect to it remotely. This can be done during the initial setup process or later through the raspi-config tool.

  3. Connect to Wi-Fi: Configure the Raspberry Pi to connect to your Wi-Fi network.

  4. Update and Upgrade Packages: Run the following commands to update and upgrade the installed packages:

    sudo apt update
    sudo apt upgrade
    
  5. Install Pi-hole: Follow the official Pi-hole installation guide to install Pi-hole on your Raspberry Pi.

Connecting the OLED Screen

  1. Enable I2C (or SPI): Depending on the OLED screen’s connectivity, enable I2C or SPI in the raspi-config tool.

  2. Connect the Wires: Connect the OLED screen to the Raspberry Pi’s GPIO pins according to the screen’s documentation. For I2C, the typical connections are:

    • SDA (Serial Data) to GPIO2 (pin 3)
    • SCL (Serial Clock) to GPIO3 (pin 5)
    • VCC to 3.3V (pin 1)
    • GND to GND (pin 6)
  3. Install Required Libraries: Install the necessary libraries for communicating with the OLED screen. For example, if using the Adafruit SSD1306 library, run:

    sudo pip3 install adafruit-circuitpython-ssd1306
    sudo apt-get install python3-pil
    

Writing the Data Collection and Display Script (Python Example)

import time
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import requests

# Pi-hole API endpoint (replace with your Pi-hole's IP address)
PIHOLE_API_URL = "http://pi.hole/admin/api.php"

# OLED screen dimensions
WIDTH = 128
HEIGHT = 64

# Initialize OLED display (I2C)
RST = None  # Reset pin (can be set to None if not used)
DC = 23
SPI_PORT   = 0
SPI_DEVICE = 0
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# Initialize library.
disp.begin()

# Clear display.
disp.clear()
disp.display()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
image = Image.new('1', (WIDTH, HEIGHT))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Load default font.
font = ImageFont.load_default()

def get_pihole_data():
    try:
        response = requests.get(PIHOLE_API_URL)
        response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
        data = response.json()
        return data
    except requests.exceptions.RequestException as e:
        print(f"Error fetching data from Pi-hole API: {e}")
        return None

while True:
    # Get Pi-hole data
    pihole_data = get_pihole_data()

    # Clear the image
    draw.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0)

    if pihole_data:
        # Extract data from the API response
        domains_blocked = pihole_data.get('domains_being_blocked', 'N/A')
        dns_queries_today = pihole_data.get('dns_queries_today', 'N/A')
        ads_blocked_today = pihole_data.get('ads_blocked_today', 'N/A')
        percentage_blocked = pihole_data.get('ads_percentage_today', 'N/A')

        # Format the data for display
        line1 = f"Total Queries: {dns_queries_today}"
        line2 = f"Blocked: {ads_blocked_today}"
        line3 = f"Percentage: {percentage_blocked}%"
        line4 = f"Domains Blocked: {domains_blocked}"

        # Draw the text on the image
        draw.text((0, 0), line1, font=font, fill=255)
        draw.text((0, 16), line2, font=font, fill=255)
        draw.text((0, 32), line3, font=font, fill=255)
        draw.text((0, 48), line4, font=font, fill=255)
    else:
        draw.text((0, 0), "Error fetching data", font=font, fill=255)

    # Display image.
    disp.image(image)
    disp.display()

    # Wait for a specified time (in seconds)
    time.sleep(10)

Running the Script Automatically

To ensure the dashboard is always running, you can add the script to cron:

  1. Open the crontab editor: crontab -e

  2. Add the following line to run the script every minute:

    * * * * * python3 /path/to/your/script.py
    

    Replace /path/to/your/script.py with the actual path to your Python script.

Advanced Customization and Enhancements

Troubleshooting Common Issues

Conclusion: A Powerful and Elegant Solution

Building an enhanced Pi-hole dashboard with an OLED screen is a rewarding project that combines functionality, aesthetics, and technical expertise. It provides a visually appealing and immediately accessible overview of network activity, empowering users to monitor their network security and optimize their online privacy. By following the steps outlined in this guide, you can create your own custom Pi-hole dashboard and elevate your network monitoring experience to a whole new level. We at Magisk Modules encourage exploration and innovation in the pursuit of a more secure and efficient digital world. For further Magisk Modules exploration, please visit Magisk Module Repository.

Explore More
Redirecting in 20 seconds...