Raspberry Pi Payment-Triggered System Fix

Замовник: AI | Опубліковано: 29.11.2025
Бюджет: 30 $

PROJECT DESCRIPTION Overview I have a Raspberry Pi Zero 2 W running a simple payment-triggered lock/unlock system for a mini-fridge at a yoga studio. Customers scan a QR code, pay via Stripe Checkout, and the Pi unlocks the fridge for a set number of seconds. The core logic works and the hardware is correct. When I manually run the Python unlock function, the relay and LEDs toggle exactly as expected. However, when the same function is triggered from the Stripe webhook inside Flask, the GPIO actions do not execute. The HDMI display pipeline has been abandoned. This project is now strictly LED + relay, no screen. I need a programmer to stabilize the webhook → Python → GPIO flow and produce a clean, reliable service. System Environment Hardware Raspberry Pi Zero 2 W Relay module controlling a fridge lock Two LEDs (red = locked, green = unlocked) Software Raspberry Pi OS Bookworm Python 3.11 Flask server receiving Stripe webhooks RPi.GPIO for hardware control The server will run under systemd Current Python Code def safe_gpio_init(): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(RELAY_PIN, GPIO.OUT) GPIO.setup(RED_PIN, GPIO.OUT) GPIO.setup(GREEN_PIN, GPIO.OUT) GPIO.output(RELAY_PIN, GPIO.LOW) GPIO.output(RED_PIN, GPIO.HIGH) GPIO.output(GREEN_PIN, GPIO.LOW) def unlock_for_seconds(seconds=8): safe_gpio_init() GPIO.output(RELAY_PIN, GPIO.HIGH) GPIO.output(RED_PIN, GPIO.LOW) GPIO.output(GREEN_PIN, GPIO.HIGH) time.sleep(seconds) GPIO.output(RELAY_PIN, GPIO.LOW) GPIO.output(GREEN_PIN, GPIO.LOW) GPIO.output(RED_PIN, GPIO.HIGH) Webhook: @app.route("/stripe_webhook", methods=["POST"]) def stripe_webhook(): safe_gpio_init() if event_type in ("checkout.session.completed", "payment_intent.succeeded"): unlock_for_seconds() What Works The relay and LEDs toggle correctly when unlock_for_seconds() is run manually in a Python REPL. Stripe webhook reaches the Pi. Flask logs confirm that unlock_for_seconds() is being called. The Problem When called inside the Stripe webhook handler: Relay does not toggle LEDs do not change No GPIO activity occurs at all The same code works perfectly when executed manually. The issue began after display-related experiments, but the display system has been fully abandoned. The problem persists. What I Need Diagnose and fix why GPIO calls do not execute when run inside a Flask webhook under systemd. Ensure Flask (or Gunicorn) runs under the correct user and has GPIO permissions. Create a reliable systemd service that runs the server, logs errors, and restarts on failure. Add proper logging inside the webhook so permission or environment issues become visible. Ensure the following sequence works every time: Payment → Webhook → Relay unlocks for N seconds → LEDs update → Relay locks again. Clean up the Pi environment so it behaves consistently after reboots.