Skip to content

Konfigurowalne piny GPIO przez gpio.json i endpoint /api/secure/gpio#2

Open
koder95 wants to merge 2 commits into
gpio-sm-featuresfrom
codex/add-gpio-port-configuration-support
Open

Konfigurowalne piny GPIO przez gpio.json i endpoint /api/secure/gpio#2
koder95 wants to merge 2 commits into
gpio-sm-featuresfrom
codex/add-gpio-port-configuration-support

Conversation

@koder95

@koder95 koder95 commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Umożliwić zmianę numerów portów GPIO bez modyfikacji kodu źródłowego przez plik konfiguracyjny i interfejs HTTP dla administratora.
  • Pozwolić na zastosowanie zmian GPIO w czasie działania sterownika bez restartu urządzenia i zaktualizować dokumentację instalacji/obsługi.

Description

  • Dodano plik gpio.json z domyślnymi wartościami { "pixel":19, "sensor":18, "off":20 } oraz wpis w README opisujący jego format i użycie.
  • W utils.py dodano helpery normalize_gpio_config, load_gpio_config i save_gpio_config z walidacją zakresu (0–28) i domyślnymi wartościami.
  • WaterflowDriver teraz ładuje konfigurację GPIO przy inicjalizacji, używa wartości z gpio.json dla pinu strip/sensor/off, dodał metody configure_gpio i reload_gpio oraz stosuje zmiany w runtime (przełączenie pinów / rekreacja instancji WaterflowPixel).
  • Dodano administracyjny endpointy GET /api/secure/gpio oraz PUT|PATCH /api/secure/gpio w myhttp.py, które wymagają roli admin, walidują wejście, zapisują znormalizowaną konfigurację i aplikują ją do działającego sterownika.
  • Zaktualizowano README.md o opis gpio.json, dokumentację endpointu api/secure/gpio oraz przykładowe polecenie curl i listę plików konfiguracyjnych.

Testing

  • python3 -m py_compile main.py myhttp.py waterflowdriver.py waterflowpixel.py auth.py utils.py config.py ktime.py neopixel.py — zakończono pomyślnie (syntax checks passed).
  • python3 -m json.tool gpio.json — plik gpio.json jest poprawnym JSON-em (succeeded).
  • Lokalny test normalizacji GPIO uruchomiony pod CPython z tymczasowymi stubami dla modułów MicroPython (machine, network) na PYTHONPATH=lib wykazał poprawne działanie normalize_gpio_config dla zestawu przypadków (succeeded).

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d324a53c16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread waterflowdriver.py
if previous.get('sensor') != self.gpio['sensor']:
self.sensorPin = Pin(self.gpio['sensor'], Pin.IN, Pin.PULL_UP)
if previous.get('pixel') != self.gpio['pixel']:
self.waterflow.removeAll()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Flush the old LED strip before switching pins

When an admin changes pixel while LEDs are lit, this only clears the old WaterflowPixel object's in-memory buffer. WaterflowPixel.removeAll() does not call show(), and the next line replaces the object with one bound to the new GPIO, so the old data line never receives zeros and any lit LEDs can remain latched on until that old pin is driven again. Flush the cleared buffer on the old instance before constructing the replacement.

Useful? React with 👍 / 👎.

Comment thread myhttp.py
Comment on lines +195 to +196
if not isinstance(value, int) or value < 0 or value > 28:
return json.dumps({"message": "Bad Request"}), 400, {"Content-type": "application/json"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject boolean GPIO values before applying them

For JSON bodies containing booleans, this validation accepts them because bool is an int subclass in Python/MicroPython, so a request like {"pixel": true} passes the documented integer check and is then persisted/applied as GPIO 1. That makes malformed API input silently remap hardware pins; reject bool explicitly before calling configure_gpio().

Useful? React with 👍 / 👎.

@koder95 koder95 changed the base branch from master to gpio-sm-features May 30, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant