Skip to content

Latest commit

 

History

History
162 lines (143 loc) · 6.28 KB

README.md

File metadata and controls

162 lines (143 loc) · 6.28 KB

RPi Power Controller

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.

amimation

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.

Hardware Architecture

hw-arch

Detailed hardware bill of material.

Software Architecture

sw-arch

Configuration

rpi-powercontroller requires external JSON configuration file in order to load initial configuration. Please check configuration manual for details.

Jobs, Tasks and Actions

rpi-powercontroller is capable of running autonomous tasks. Please check documentation for details.

Key Events

If quipped with keys / buttons rpi-powercontroller can be configured to submit a job on key press. Please check documentation for details.

REST APIs and Endpoints

  • Complete Postman collection

  • 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" }

REST Security

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

Build & Test on dev PC

RPi Power Controller is designed to be build and tested on PC. In this case
RPiSimulatedServiceImpl is used instead of real RPi hardware.

Development Environment

# build and test
gradle clean build test installDist distZip

# start RPi Power Controller in simulated mode
./build/install/rpi-powercontroller/bin/rpi-powercontroller

Install and Run on Raspberry PI

  1. Install Raspberry Pi OS Lite 2021-01-11
  2. Enable I2C bus sudo raspi-config
  3. Install I2C tools and wiringpi
    sudo apt-get install -y python-smbus i2c-tools
    sudo apt-get install -y wiringpi
    
  4. Check gpio and connected I2C devices
    gpio -v
    i2cdetect -y 1
    
  5. Install java, JRE 8 is enough.
  6. Create installation directory on target RPi device.
    sudo mkdir -p /opt/rpi-powercontroller
    sudo chown pi:pi /opt/rpi-powercontroller
    
  7. 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/
    
  8. Finish installation on target RPi device.
    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
    
    Edit JSON configuration file as required, follow configuration manual.
  9. Start, stop, get status of rpi-powercontroller service.
    sudo systemctl start rpi-powercontroller
    sudo systemctl stop rpi-powercontroller
    sudo systemctl status rpi-powercontroller
    

Enjoy !