Raspberry Pi in a Case

πŸ“ Introduction

A Portable File-Sharing Device that turns your Raspberry Pi into a Wi-Fi hotspot and local web server, capable of serving files directly from a USB flash drive. The goal is simple: no internet needed β€” just power it up, connect to the hotspot, and access your files via a browser at http://192.168.4.1.

The device uses a USB flash drive as external storage, so all files you see and download through the browser are stored outside the Raspberry Pi, keeping things clean and easily swappable.

Whether you’re a student, teacher, developer, or just someone who loves tinkering with Raspberry Pi, this project is for you.

I’m also open to fresh ideas that can make this project work easier, faster, or smarter. If you have suggestions or improvements, I’d love to hear them!

You’re free to build and improve it β€” and credit goes to me, Ekene Agunechemba, as the original creator of this solution. For questions, collaborations, or shout-outs, feel free to reach me at: agunechemba@yahoo.com

Let’s build something useful!


πŸ”§ Project Goal

Build a portable file-sharing device that:

  • Creates a Wi-Fi hotspot
  • Hosts a local web server
  • Lists and serves files from a USB flash drive at http://192.168.4.1

🧰 What You’ll Need

Item Description
Raspberry Pi (3/4) With built-in Wi-Fi
MicroSD Card (8GB+) For the OS
USB Flash Drive Holds files to be served
Power Supply Power your Pi
HDMI/Monitor/Keyboard For initial setup (or use SSH)
Optional: Case To protect your Pi

πŸ“¦ Step 1: Prepare Your Raspberry Pi

  1. Download and flash Raspberry Pi OS Lite

    • Download Raspberry Pi Imager
    • Choose Raspberry Pi OS Lite (64-bit)
    • Flash it to your microSD card
    • Enable SSH (create an empty file named ssh in boot partition)
  2. Boot and connect

    • Insert the card, boot the Pi
    • Connect to Wi-Fi (temporarily) or access via HDMI/keyboard

🌐 Step 2: Set Up the Wi-Fi Hotspot

1. Install Required Tools

sudo apt update
sudo apt install hostapd dnsmasq

2. Configure Static IP

Edit /etc/dhcpcd.conf:

sudo nano /etc/dhcpcd.conf

Add at the bottom:

interface wlan0
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant

3. Configure hostapd

sudo nano /etc/hostapd/hostapd.conf

Paste:

interface=wlan0
driver=nl80211
ssid=OfflineServer
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

Edit /etc/default/hostapd:

sudo nano /etc/default/hostapd

Add:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

4. Configure dnsmasq

Backup old config:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Create new one:

sudo nano /etc/dnsmasq.conf

Paste:

interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h

πŸ’Ύ Step 3: Mount USB Flash Drive Automatically

  1. Plug in your flash drive
  2. Create mount point:
sudo mkdir /media/usb
  1. Find device name:
lsblk
  1. Add to /etc/fstab:
sudo nano /etc/fstab

Add (replace sda1 with your actual device):

/dev/sda1 /media/usb vfat defaults,nofail 0 0

🌐 Step 4: Build the HTTP File Server

Using Python + Flask

  1. Install Flask:
sudo apt install python3-pip
pip3 install flask
  1. Create app file:
mkdir ~/fileserver
nano ~/fileserver/server.py

Paste this:

from flask import Flask, send_from_directory, render_template_string
import os

app = Flask(__name__)
USB_PATH = "/media/usb"

@app.route("/")
def list_files():
    files = os.listdir(USB_PATH)
    return render_template_string('''
        <h1>Files on USB</h1>
        <ul></ul>
    ''', files=files)

@app.route("/files/<path:filename>")
def serve_file(filename):
    return send_from_directory(USB_PATH, filename)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=80)

πŸ” Step 5: Auto-Start Server on Boot

Create a systemd service:

sudo nano /etc/systemd/system/fileserver.service

Paste:

[Unit]
Description=Offline File Server
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/fileserver/server.py
WorkingDirectory=/home/pi/fileserver
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Enable it:

sudo systemctl enable fileserver

πŸ”„ Step 6: Reboot and Test

  1. Reboot:
sudo reboot
  1. Connect your phone or PC to OfflineServer Wi-Fi
  2. Open browser β†’ http://192.168.4.1
  3. You’ll see the files from the flash drive, clickable and downloadable!

βœ… Optional Extras

  • Add file type icons or previews
  • Add upload form (if you want users to upload files)
  • Add QR code that points to http://192.168.4.1

βœ… Best Choice: Raspberry Pi 4 Model B

Wi-Fi + dual-band (faster, more stable hotspot)

USB 3.0 ports (faster file access)

More RAM (1GB–8GB options)

Faster CPU β†’ handles Flask/Node.js better

πŸ‘ Good Choice: Raspberry Pi 3 Model B+

Built-in Wi-Fi (single band, but works)

Enough power for hotspot + Flask server

More affordable and less power-hungry


<
Previous Post
🧩 Python Enums: Making Code More Readable
>
Next Post
πŸ•’ Build a Digital Clock with JavaScript + Time-Based Greeting