Skip to Content

← Systemd Services for a Solar Tracker on a Raspberry PLC

Two-axis solar trackersRaspberry PLC 21systemdInfrastructure

Systemd Services for a Solar Tracker on a Raspberry PLC — full example

Run a solar tracker control process and a WiFi hotspot as systemd services on a Raspberry PLC 21, with auto-restart, journald logs and Node-RED HMI.

Complete, runnable program for the Raspberry PLC 21 (solar-tracker.service): wiring header, requirements and integration notes included.

Download the full project pack — freeThis example + the related ones + bill of materials

Read-only preview.

# -----------------------------------------------------------------------------
# COMPLETE EXAMPLE — Tracker systemd services (control + button-activated AP)
#
# Device:    Raspberry PLC 21 (Industrial Shields)
# Based on:  dual-axis solar tracker project
#
# Service architecture on the PLC:
#   solar-tracker.service   main control process (this file):
#                           PyEphem + CANopen + TCP socket with Node-RED.
#   tracker-ap.service      watches the I0.5 button and brings up the WiFi
#                           hotspot (same scheme: change ExecStart to
#                           manage_ap.py).
#   Node-RED serves the dashboard (control, calibration, inverter and
#   configuration tabs) behind Authelia as the authentication layer.
#
# Installation (as root):
#   1. cp solar-tracker.service /etc/systemd/system/
#   2. systemctl daemon-reload
#   3. systemctl enable --now solar-tracker.service
#   4. Verify:  systemctl status solar-tracker.service
#               journalctl -u solar-tracker.service -f
#
# For the second service, copy this file as tracker-ap.service, change
# Description and ExecStart (/home/pi/tracker/access-point/manage_ap.py)
# and repeat steps 2-4.
# -----------------------------------------------------------------------------

[Unit]
Description=Solar tracker control (PyEphem + CANopen + TCP Node-RED)
# Starts once the network is up and the CAN bus is already configured
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
# Main tracker control script
ExecStart=/usr/bin/python3 /home/pi/tracker/main.py
WorkingDirectory=/home/pi/tracker
# Needs root for socketcan and GPIO
User=root

# Automatic restart if the process dies (CAN bus failure, exception, etc.)
Restart=always
RestartSec=10

# Logs to journald (check with journalctl -u solar-tracker.service)
StandardOutput=journal
StandardError=journal

# Avoid aggressive restart loops if something is truly broken
StartLimitIntervalSec=300
StartLimitBurst=10

[Install]
WantedBy=multi-user.target
Download the full project pack — freeThis example + the related ones + bill of materials