BACK_TO_ROOT
/SciTech Edge Advance 1.1 – R&D Logs

Controlling Hardware: MQTT-Driven LED Automation on AWS Greengrass v2

Breaking the software barrier. A production log on controlling physical GPIO pins (LEDs) on the Raspberry Pi CM5 using AWS Greengrass v2, MQTT commands, and the LGPIO library.

TIMESTAMP
SIGNATUREJayanta Paul
Industrial IoTEdge ComputingAWS IoTMQTTGPIOLGPIO

Controlling Hardware: MQTT-Driven LED Automation on AWS Greengrass v2 — SciTech Edge Advance 1.1

Executive Summary

In our journey so far, we've established local IPC and a cloud MQTT bridge. But an Edge Device without I/O is just a server. Today, we break the software barrier and control physical hardware.

This log documents the integration of the LGPIO library on the Raspberry Pi CM5 to control LEDs via MQTT commands from the cloud. We address the critical "Permission Denied" errors associated with hardware access from inside a Greengrass container.


Hardware Stack

  • Edge Device: Raspberry Pi CM5
  • GPIO 17 (Pin 11): Red LED (Output)
  • GPIO 15 (Pin 10): Green LED (Output)
  • Circuit: Standard LED setup with current-limiting resistors.

Software & Tooling Stack

  • AWS IoT Greengrass v2 Core
  • LGPIO Library (Linux GPIO for ARM)
  • System Python Packages (No virtualenv isolation)

Technical Walkthrough

The Logic: Cloud -> MQTT -> GPIO

The workflow is straightforward but powerful:

  1. Cloud: User publishes a JSON command (e.g., {"red": 1, "green": 0}) to cmd/led.
  2. Core: Greengrass receives the message via the MQTT Bridge.
  3. Component: Python script parses the payload and toggles the GPIO pins using lgpio.

The Code (led_control.py)

We use lgpio instead of the older RPi.GPIO because the CM5 and newer kernels require standard Linux GPIO character device access.

python
import lgpio
import json
import awsiot.greengrasscoreipc

# Chip 0 is usually the default for Pi 4/CM4/CM5

h = lgpio.gpiochip_open(0)

# Setup Pins

RED_PIN = 17
GREEN_PIN = 15
lgpio.gpio_claim_output(h, RED_PIN)
lgpio.gpio_claim_output(h, GREEN_PIN)

def on_message_received(event):
payload = json.loads(event.message.decode('utf-8'))

  if "red" in payload:
      lgpio.gpio_write(h, RED_PIN, payload["red"])

  if "green" in payload:
      lgpio.gpio_write(h, GREEN_PIN, payload["green"])

LED Control Component Code

Python script for LGPIO control via MQTT.

Download_System

The "Rogue Insight"

Access Denied: 'Can't open GPIO chip'

We hit a hard stop immediately after deployment. The component crashed with Can't open GPIO chip.

The Problem: Greengrass runs components as the user ggc_user. This user does not have permission to access /dev/gpiochip* by default.

The Fix: We removed the pip installation from the recipe and relied on system-level packages. Then we added the Greengrass user to the gpio group using sudo usermod -aG gpio ggc_user.


Recipe Configuration (v1.0.9)

We updated the recipe to version 1.0.9. Note that we are not installing lgpio in the Install lifecycle script anymore. We assume the environment is prepared.

LED Control Recipe (v1.0.9)

Recipe configured for system-level GPIO access.

Download_System

Verification

We validated the control using the AWS IoT Core Test Client.

Topic: cmd/led

Payload 1 (Red ON):

text
{
  "red": 1
}

Result: Red LED lights up instantly.

Payload 2 (Both ON):

text
{
  "red": 1,
  "green": 1
}

Result: Both LEDs active.

Payload 3 (All OFF):

text
{
  "red": 0,
  "green": 0
}

Result: Complete blackout.


The Road Ahead

We have now connected the cloud to the physical world. This concludes the foundational setup for the Edge Advance 1.1 series.

Future logs will cover:

  • integrating industrial sensors (Modbus/RS485)
  • Real-time data visualization at the edge
  • OTA updates for the entire fleet
R&D LOG CONTINUITYSCITECH_ADVANCE_V1.1

Closing Note

Connecting a lightbulb to the internet is the "Hello World" of IoT, but doing it reliably via a managed edge runtime like Greengrass is a significant engineering milestone. We now have a secure, managed pipeline to control physical infrastructure from the cloud.

— DK Swami Founder, Scitech Industries

People Behind This Work

Jayanta Paul
Jayanta Paul
IoT & Edge Engineer
Scitech Industries
This work is part of
SciTech Edge Advance 1.1 – R&D Logs
Technical deep-dives and production logs from our internal Edge Computing R&D trials on ARM-based hardware.
D K Swami

D K Swami

Founder & Technical Lead, Scitech Industries

Also documenting the founder journey at Unscripted with DK Swami → Instagram