danacr / server-restarter

Flask enabled USB relay to restart my server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server Restarter

working

Completely overkill solution to restart my NAS using an external relay. All of this could have been solved with one ethernet connected relay, but I happened to have all the other parts in a storage box collecting dust. (Except for the relay, thank you very much @Jogi!

I reused the flask web app from busylight with a different button (and api call) to restart my server.

Web Interface

web

This is all hosted on a Radxa Rock Pi S which I have left over from the flying Kubernetes cluster project.

The Pi uses Armbian Bullseye because Radxa stopped releasing updates to the OS images 2 years ago and DietPi does not upgrade kernels. pi

The QYF-UR01 USB HID relay board is not really documented, so I took the bytes that I need to pipe to /dev/hidraw0 from here.

The systemctl service was setup using this guide

To run:

sudo python3 main.py

To trigger:

curl -X POST http://localhost

Everything is stuck using double-sided tape in an old iPhone box, the reset cables coming through the cdrom slot:

iPhone box

To keep the functionality of the existing reset button, I just tied the cables together using scotch tape

Cables

The final result

final

Home Assistant

To add my relay as a switch to HomeAssistant, I had to add the follwoing content to my configuration.yaml:

switch:
  - platform: rest
    resource: http://192.168.1.100/
    method: 'POST'

If you have the HomeKit integration on HomeAssistant, it will make the switch available on your iPhone as well.

Room

Room

Switch

Switch

Docker:

How to build an arm64 image on an x86 machine:

docker buildx build \
    --platform=linux/arm64 --tag test .

I had to modify the usbrelay.rules from 0660 to 0666 so that any user could write to that path.

To run:

docker compose up -d

About

Flask enabled USB relay to restart my server

License:The Unlicense


Languages

Language:HTML 63.3%Language:Python 21.9%Language:Dockerfile 14.8%