This project describes how to build AC power switching device controlled remotely over HTTP / REST interface. The device is based on RaspberryPI and compatible hardware peripherals.
Key features:
- 4 AC power ports - controlled remotely via HTTP / REST (ON | OFF).
- sensor data - measures temperature, relative humidity and atmospheric pressure.
- task execution - execute one-at-a-time tasks based on pre-defined job (switching sequence)
- simple security - client-id / client-secret, basic access authentication.
- 4 keys to trigger jobs - trigger pre-defined jobs using 4 hardware keys / buttons.
Detailed hardware bill of material.
- Tiny software stack, 32 MB of heap space to run.
- Java 11 compatible.
- undertow.io as web server.
- com.fasterxml.jackson for JSON processing.
- Raspbian Lite, WiringPi, pi4j
- No frameworks, plain java.
rpi-powercontroller requires external JSON configuration file in order to load initial configuration. Please check configuration manual for details.
rpi-powercontroller is capable of running autonomous tasks. Please check documentation for details.
If quipped with keys / buttons rpi-powercontroller can be configured to submit a job on key press. Please check documentation for details.
-
Get system information like device id, uptime, ...
GET/system/info
-
Get sensor data (temperature, rel. humidity, atm. pressure)
GET/system/measurements
-
Get post states (ON | OFF) and port types (INPUT | OUTPUT)
GET/system/state
-
Set OUTPUT port state (ON=true | OFF=false)
PUT/system/port
{ "port": 0, "state": true }
-
Get available pre-configured jobs.
GET/system/jobs
-
Get id of killAll tasks job.
GET/system/jobs/killalljobid
-
Get task queue (waiting, in-progress, finished) tasks.
GET/system/tasks
-
Get filtered task queue (waiting, in-progress, finished) tasks.
GET/system/tasks
{ "statuses": [ "WAITING", "IN_PROGRESS" ] }
-
Submit job to task execution - returns task-id of submitted job.
PUT/system/tasks/submit
{ "id": "job-001" }
-
Cancel task execution by task-id.
PUT/system/tasks/cancel
{ "id": "task-001" }
-
Stop all running tasks and execute selected 'killAllTaskId'.
PUT/system/tasks/cancel/all
-
Clean task queue, remove all tasks in terminal state.
PUT/system/tasks/clean
-
Wait for task execution to finish or task to be cancelled.
PUT/system/tasks/wait/termination
{ "id": "task-001" }
-
Wait for task execution to be started.
PUT/system/tasks/wait/started
{ "id": "task-001" }
All REST endpoint require HTTP basic authorization header to be used, valid client-id / client-secret. Check configuration section.
curl -u <client-id>:<client-secret> http://<server>:<port>/uri
RPi Power Controller is designed to be build and tested on PC. In this case
RPiSimulatedServiceImpl
is used instead of real RPi hardware.
- OpenJDK 11.
- Gradle 7.0 or later.
# build and test
gradle clean build test installDist distZip
# start RPi Power Controller in simulated mode
./build/install/rpi-powercontroller/bin/rpi-powercontroller
- Install Raspberry Pi OS Lite 2021-01-11
- Enable I2C bus
sudo raspi-config
- Install I2C tools and wiringpi
sudo apt-get install -y python-smbus i2c-tools sudo apt-get install -y wiringpi
- Check gpio and connected I2C devices
gpio -v i2cdetect -y 1
- Install java, JRE 8 is enough.
- Raspberry Pi Zero WH 32bit Oracle JRE 8 for ARM
- Raspberry Pi 2, 3 or later
sudo apt install openjdk-8-jdk
- Create installation directory on target RPi device.
sudo mkdir -p /opt/rpi-powercontroller sudo chown pi:pi /opt/rpi-powercontroller
- Build distribution zip and copy the zip and init scripts to target RPi device.
gradle clean build test installDist distZip scp build/distributions/rpi-powercontroller-2.0.0.zip pi@<ip-address>:/opt/rpi-powercontroller/ scp -r scripts/* pi@<ip-address>:/opt/rpi-powercontroller/ scp src/main/resources/rpi-configuration.json pi@<ip-address>:/opt/rpi-powercontroller/
- Finish installation on target RPi device.
Edit JSON configuration file as required, follow configuration manual.
cd /opt/rpi-powercontroller unzip rpi-powercontroller-2.0.0.zip chmod 755 controller-start.sh chmod 755 controller-stop.sh sudo cp rpi-powercontroller.service /etc/systemd/system/ sudo chown root:root /etc/systemd/system/rpi-powercontroller.service sudo systemctl daemon-reload sudo systemctl enable rpi-powercontroller touch /opt/rpi-powercontroller/rpi-powercontroller.log
- Start, stop, get status of rpi-powercontroller service.
sudo systemctl start rpi-powercontroller sudo systemctl stop rpi-powercontroller sudo systemctl status rpi-powercontroller
Enjoy !