University Capstone Project — Open source Linux embedded power control unit with a Python REST API for control and monitoring.
This project is a comprehensive solution for controlling power outlets and monitoring power consumption via a Raspberry Pi. It features a custom hardware interface, a Python backend, and a RESTful API designed for reliability and ease of use in embedded environments.
- Smart Control — independent toggle of 8 relays via GPIO.
- Real-time Monitoring — voltage, current, and power measurement via MCP3008 ADC.
- REST API — full programmatic control using Flask and JWT authentication.
- System Optimization — RAM disk storage for high-frequency logs to prevent SD card corruption.
- Automated Services — self-healing background services managed via cron and Pipenv.
Follow these steps to set up the Power Control Unit from a fresh Raspberry Pi installation.
- Use Raspberry Pi Imager to write Raspbian Lite OS on your SD card.
- Connect the Pi to a screen and keyboard for initial setup.
Update the system:
sudo apt-get update
sudo apt-get upgradeRun the config tool:
sudo raspi-config- System Options — set a new password and the PCU hostname.
- Interface Options — enable SPI and SSH.
- Localisation — set local system time (critical for logs).
- Reboot — restart the system.
Install Python pip, network utils, and bridge-utils:
sudo apt-get install python3-pip bridge-utils
pip3 install pipenvTo prevent SD card wear from frequent log writes, create a temporary RAM disk.
Create the directory:
mkdir /var/tmpEdit fstab:
sudo nano /etc/fstabAdd this line at the end (400MB RAM disk):
tmpfs /var/tmp tmpfs nodev,nosuid,size=400M 0 0
Mount the disk:
sudo mount -aClone the repository or copy files via SCP. For Windows (using SCP), replace {hostname} with your Pi hostname:
scp -prq software/pcu pi@{hostname}.local:/home/piSet up the Python environment:
cd pcu
python3 -m pipenv installUse cron to launch PCU services at boot:
crontab -eAdd these commands at the end of the file:
@reboot cd /home/pi/pcu && python3 -m pipenv run init_gpio > /home/pi/gpio_log.txt
@reboot cd /home/pi/pcu && python3 -m pipenv run adc > /home/pi/adc_log.txt
@reboot cd /home/pi/pcu && python3 -m pipenv run serve > /home/pi/serve_log.txt
@reboot cd /home/pi/pcu && python3 -m pipenv run logger > /home/pi/logger_log.txt
Add ethernet bridge configuration to the end of /etc/network/interfaces:
auto br0
iface br0 inet dhcp
bridge_ports eth0 eth1
- Hardware — Hardware Pinout
- API — API Documentation