Skip to Content

← All functionalities

Two-axis solar trackersRaspberry PLC 21WiFiGPIOInfrastructure

A push-button WiFi hotspot for field commissioning on a PLC

Solar plants rarely offer WiFi, yet every tracker needs occasional on-site configuration. This example turns a physical button on input I0.5 of a Raspberry PLC 21 into a temporary WiFi access point: press it, and the PLC raises an nmcli-managed hotspot for 15 minutes so a technician can reach the local dashboard from a phone. Taken from a real two-axis solar tracker deployment, it combines a GPIO interrupt, NetworkManager profiles and an auto-shutdown timer.

Interrupt-driven, not polled

GPIO.add_event_detect registers a falling-edge callback on the button input, so the main loop just sleeps. The callback re-reads the pin after a short debounce delay to discard electrical noise — important on a structure full of motor cables. This pattern costs zero CPU while waiting, which matters when the same PLC is also running the tracking process, the CAN bus and the dashboard.

nmcli does the heavy lifting

Instead of hostapd and dnsmasq configuration files, the script drives NetworkManager: one connection profile in AP mode with WPA2 and shared IPv4, created on first use and reused afterwards. Bringing the hotspot up or down is a single nmcli command with a timeout, and SSID and password stay as placeholders (AP_SSID, AP_PASSWORD) so each installation sets its own credentials at deployment time.

The 15-minute safety timer

An open access point on a remote site is a liability, so a threading.Timer shuts the hotspot down after 15 minutes. Pressing the button again while the AP is active cancels and restarts the timer, extending the session naturally. The technician never has to remember to turn anything off, and the radio footprint of the plant returns to zero by itself.

A snippet from the implementation

Straight from the example as deployed on the Raspberry PLC 21 — copy it freely:

def nmcli(*args, timeout=15):
    """Runs nmcli and returns the CompletedProcess (no exception on failure)."""
    return subprocess.run(["nmcli", *args], capture_output=True,
                          text=True, timeout=timeout)

The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.

Frequently asked questions

Why use NetworkManager instead of hostapd directly?

nmcli ships with most modern Linux images, manages the DHCP side automatically with ipv4.method shared, and keeps the AP as a named profile you can audit. It removes two daemons and their config files from the deployment.

Can the button input be a standard PLC digital input?

Yes. On the Raspberry PLC the I0.5 input maps to a GPIO pin of the Raspberry Pi inside, so RPi.GPIO interrupts work with industrial 24 V wiring through the PLC's input conditioning.

What does the technician see after connecting to the hotspot?

The PLC serves its local Node-RED dashboard, so once associated to the AP the technician browses to the PLC address and gets control, calibration and inverter tabs protected by authentication.

Related functionalities