Note
The description below applies to the current version 2 of SH-RPi. Version 2 is available for purchase at hatlabs.fi. The installation script also supports version 1 of SH-RPi even though most of the documentation below is for version 2.
SH-RPi, formally known as Sailor Hat for Raspberry Pi, is a Raspberry Pi smart power management board. The main features are:
- Power management with a 60 Farad supercapacitor that provides so-called last gasp energy for shutting down the device in a controlled fashion after the system power is cut.
- Peak power management: The same supercapacitor circuitry is able to provide peak current for power-hungry devices such as the Raspberry Pi 4B with SSD or NVMe drives, allowing those devices to be powered using current-limited subcircuits such as the NMEA2000 bus power wires.
- Protection circuitry: The board is protected against noisy 12V/24V voltages commonly present on vehicles or marine vessels.
- A battery-powered real-time clock circuit, allowing for the device to keep time even in the absence of GPS or networking.
shrpid is a power monitor and watchdog for the SH-RPi. It communicates with the SH-RPi device, providing the "smart" aspects of the operation. Supported features include:
- Blackout reporting if input voltage falls below a defined threshold
- Triggering of device shutdown if power isn't restored
- Supercap voltage reporting
- Watchdog functionality: if the SH-RPi receives no communication for 10 seconds, the SH-RPi will hard reset the device.
- RTC sleep mode: the onboard real-time clock can be set to boot the Raspberry Pi at a specific time. This is useful for battery powered devices that should perform scheduled tasks such as boat battery and bilge level monitoring.
The main use case for the service software is to have the Raspberry Pi shut down once the power is cut. This prevents potential file system corruption without having to shut down the device manually.
Copy and paste the following lines to your terminal to install the latest version of the daemon and to update the configuration files:
curl -L \
https://raw.githubusercontent.com/hatlabs/SH-RPi-daemon/main/install-online.sh \
| sudo bash
If you want to install the daemon from a specific branch, you can use the following command:
curl -L \
https://raw.githubusercontent.com/hatlabs/SH-RPi-daemon/BRANCH/install-online.sh \
| sudo bash -s -- https://github.com/hatlabs/SH-RPi-daemon BRANCH
Replace BRANCH with the desired branch name. Note that the BRANCH needs to be specified twice in the command.
If you prefer to use Docker to run the daemon, you can clone the repo and issue the following commands:
docker compose -f docker/docker-compose.yml build
docker compose -d -f docker/docker-compose.yml up
If you have previously installed the daemon using the install-online.sh script, you need to stop and disable the daemon on your system by issuing the following command:
sudo systemctl disable --now shrpid
Before starting the Docker container, you need to manually enable I2C on your Raspberry Pi by issuing the following command:
sudo raspi-config nonint do_i2c 0
Alternatively, it is possible to clone this repo on a Raspberry Pi device and run the install.sh script. This will install the daemon and the configuration files. If you want to define the desired configuration without going through the interactive dialogs, they can be defined on the command line as follows:
sudo ./install.sh --enable RTC,CAN
The above command will enable the RTC and CAN (NMEA 2000) features. The following features are available:
RTC: Enables the real-time-clockCAN: Enables the CAN (NMEA 2000) interfaceRS485: Enables the RS485 interfaceMAX-M8Q: Enables the u-blox MAX-M8Q GPS interface
The shrpid daemon can be configured using a configuration file.
The default configuration file location is /etc/shrpid.conf.
Note that no configuration file is created by default.
Instead, you need to create one at the given location.
The configuration file is in YAML format.
The configuration keys are the same as daemon command line arguments that can be seen by issuing the following command:
shrpid --help
For example, if you want to change the blackout time limit to 10 seconds andthe poweroff command to /home/pi/bin/custom-poweroff, you can edit the configuration file as follows:
blackout-time-limit: 10
poweroff: /home/pi/bin/custom-poweroff
For a more detailed SH-RPi documentation, please visit the documentation website.
Sh-RPi devices are available for purchase at shop.hatlabs.fi.
See the run script for common development tasks. The instructions below are for a generic poetry project.
Building a new version of the application contains steps:
- Bump the version of your package
poetry version <version>. You can pass the new version explicitly, or a rule such asmajor,minor, orpatch. For more details, refer to the Semantic Versions standard. - Make a commit to
GitHub. - Create a
GitHub release. - And... publish π
poetry publish --build
- Supports for
Python 3.9and higher. Poetryas the dependencies manager. See configuration inpyproject.tomlandsetup.cfg.- Automatic codestyle with
black,isortandpyupgrade. - Ready-to-use
pre-commithooks with code-formatting. - Type checks with
mypy; docstring checks withdarglint; security checks withsafetyandbandit - Testing with
pytest. - Ready-to-use
.editorconfig,.dockerignore, and.gitignore. You don't have to worry about those things.
GitHubintegration: issue and pr templates.Github Actionswith predefined build workflow as the default CI/CD.- Everything is already set up for security checks, codestyle checks, code formatting, testing, linting, docker builds, etc with
Makefile. More details in makefile-usage. - Dockerfile for your package.
- Always up-to-date dependencies with
@dependabot. You will only enable it. - Automatic drafts of new releases with
Release Drafter. You may see the list of labels inrelease-drafter.yml. Works perfectly with Semantic Versions specification.
- Ready-to-use Pull Requests templates and several Issue templates.
- Files such as:
LICENSE,CONTRIBUTING.md,CODE_OF_CONDUCT.md, andSECURITY.mdare generated automatically. Stale botthat closes abandoned issues after a period of inactivity. (You will only need to setup free plan). Configuration is here.- Semantic Versions specification with
Release Drafter.
pip install -U shrpidor install with Poetry
poetry add shrpidConda users can setup a development environtment with ideas stolen from Stack Overflow.
conda create --name shrpid --file conda-linux-64.lock
conda activate shrpid
poetry installand during regular use:
conda activate shrpidConda environment can be updated as follows:
# Re-generate Conda lock file(s) based on environment.yml
conda-lock -k explicit --conda mamba
# Update Conda packages based on re-generated lock file
mamba update --file conda-linux-64.lock
# Update Poetry packages and re-generate poetry.lock
poetry updateMakefile contains a lot of functions for faster development.
1. Download and remove Poetry
To download and install Poetry run:
make poetry-downloadTo uninstall
make poetry-remove2. Install all dependencies and pre-commit hooks
Install requirements:
make installPre-commit hooks coulb be installed after git init via
make pre-commit-install3. Codestyle
Automatic formatting uses pyupgrade, isort and black.
make codestyle
# or use synonym
make formattingCodestyle checks only, without rewriting files:
make check-codestyleNote:
check-codestyleusesisort,blackanddarglintlibrary
Update all dev libraries to the latest version using one comand
make update-dev-deps4. Code security
make check-safetyThis command launches Poetry integrity checks as well as identifies security issues with Safety and Bandit.
make check-safety5. Type checks
Run mypy static type checker
make mypy6. Tests with coverage badges
Run pytest
make test7. All linters
Of course there is a command to rule run all linters in one:
make lintthe same as:
make test && make check-codestyle && make mypy && make check-safety8. Docker
make docker-buildwhich is equivalent to:
make docker-build VERSION=latestRemove docker image with
make docker-removeMore information about docker.
9. Cleanup
Delete pycache files
make pycache-removeRemove package build
make build-removeDelete .DS_STORE files
make dsstore-removeRemove .mypycache
make mypycache-removeOr to remove all above run:
make cleanupYou can see the list of available releases on the GitHub Releases page.
We follow Semantic Versions specification.
We use Release Drafter. As pull requests are merged, a draft release is kept up-to-date listing the changes, ready to publish when youβre ready. With the categories option, you can categorize pull requests in release notes using labels.
| Label | Title in Releases |
|---|---|
enhancement, feature |
π Features |
bug, refactoring, bugfix, fix |
π§ Fixes & Refactoring |
build, ci, testing |
π¦ Build System & CI/CD |
breaking |
π₯ Breaking Changes |
documentation |
π Documentation |
dependencies |
β¬οΈ Dependencies updates |
You can update it in release-drafter.yml.
GitHub creates the bug, enhancement, and documentation labels for you. Dependabot creates the dependencies label. Create the remaining labels on the Issues tab of your GitHub repository, when you need them.