Scripts to monitor and report power outages at a campsite using a Linux laptop
Find a file
2026-08-10 11:54:43 +01:00
oasis-away Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
oasis-back Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
oasis-offgrid Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
oasis-ongrid Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
oasis-power-watcher Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
oasis-power-watcher.service Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
power-report.sh Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00
README.md Initial commit: campsite power outage monitoring scripts 2026-08-10 11:54:43 +01:00

campsite-power-monitor

Scripts to monitor and report power outages at a campsite, running on a Linux laptop that detects interruptions in its mains power supply.

How it works

The laptop detects when it switches from mains power to battery (and back) via systemd journal kernel messages. A watcher service triggers an immediate report on every power event, and a cron job updates the report every 15 minutes as a fallback.

Reports are generated as HTML and uploaded to a web server via rsync/ssh. A daily file is created per day and a running index page lists all available reports.

Features

  • Detects power outages and restorations in real time
  • Generates daily HTML reports with per-outage duration
  • Handles outages that cross midnight between two days
  • Maintenance windows: mark periods where the laptop is intentionally off mains (e.g. being carried to the meter) so false outages are excluded
  • Away mode: displays a prominent banner on the index page when monitoring is suspended
  • GoAccess-compatible (separate nginx access log for visitor stats)

Requirements

  • Linux with systemd
  • bash, rsync, ssh
  • User must be in the systemd-journal group:
    sudo usermod -aG systemd-journal $USER
    
    (log out and back in for group membership to take effect)
  • SSH key-based authentication to the web server (no password prompts during automated uploads)
  • nginx on the web server with a dedicated access log per vhost

Scripts

power-report.sh

Generates a daily HTML report of outages and uploads it to the web server. Edit REMOTE_HOST and REMOTE_DIR at the top to match your setup.

oasis-offgrid

Marks the start of a maintenance window. Run this before intentionally disconnecting from mains (e.g. carrying the laptop elsewhere) so that period is excluded from outage reports.

oasis-ongrid

Closes the current maintenance window and logs it.

oasis-power-watcher

Watches the systemd journal for power events (Charging: 0 / Charging: 1) and triggers power-report.sh immediately on each event.

oasis-power-watcher.service

systemd unit file for the watcher. Install to /etc/systemd/system/ and enable with:

sudo systemctl daemon-reload
sudo systemctl enable --now oasis-power-watcher

oasis-away

Sets a red banner on the web index page indicating monitoring is suspended. Run before leaving for an extended period.

oasis-back

Removes the away banner. Run on return.

Installation

sudo cp power-report.sh oasis-offgrid oasis-ongrid oasis-power-watcher oasis-away oasis-back /usr/local/bin/
sudo chmod +x /usr/local/bin/power-report.sh \
              /usr/local/bin/oasis-offgrid \
              /usr/local/bin/oasis-ongrid \
              /usr/local/bin/oasis-power-watcher \
              /usr/local/bin/oasis-away \
              /usr/local/bin/oasis-back
sudo cp oasis-power-watcher.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now oasis-power-watcher

Add to crontab as fallback (every 15 minutes):

*/15 * * * * /usr/local/bin/power-report.sh

Departure checklist

  1. oasis-offgrid — start maintenance window
  2. oasis-away — set away banner on web index
  3. Take laptop

Return checklist

  1. oasis-back — remove away banner
  2. oasis-ongrid — close maintenance window

License

MIT