diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 7c866b4..4a98879 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -12,10 +12,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set version in Cargo.toml - run: | - VERSION=$(cat VERSION) - sed -i "s/^version = \"__VERSION__\"/version = \"$VERSION\"/" Cargo.toml - name: Build image with Podman env: BUILDAH_ISOLATION: chroot diff --git a/Dockerfile b/Dockerfile index 2f6ad6c..b743352 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,14 @@ WORKDIR /usr/src/app COPY Cargo.toml ./ COPY Cargo.lock ./ +COPY VERSION ./ COPY src ./src COPY templates ./templates COPY static ./static -RUN cargo build --release +RUN VERSION=$(cat VERSION) \ + && sed -i 's/^version = "__VERSION__"/version = "'"$VERSION"'"/' Cargo.toml \ + && cargo build --release # Runtime Stage FROM debian:bookworm-slim diff --git a/README.md b/README.md index a6cd369..1fdc692 100644 --- a/README.md +++ b/README.md @@ -1,190 +1,103 @@ -# Tabellen Webserver +# Paramod -Ein einfacher Rust-Webserver, der eine editierbare 3x3-Tabelle bereitstellt und in einer JSON-Konfigurationsdatei persistiert. - -## Projektstruktur - -``` -paramod/ -├── src/ -│ └── main.rs -├── templates/ -│ ├── index.html -│ └── settings.html -├── static/ -│ ├── style.css -│ ├── script.js -│ └── settings.js -├── Cargo.toml -├── Dockerfile -├── .gitignore -└── README.md -``` +Rust-Webserver zur Anzeige und Bearbeitung von Modbus-Tabellen mit Persistierung in `paramod.yaml`. ## Funktionen -- **3 separate Tabellen** für verschiedene Sensor-Gruppen -- **Navigation** mit aktivem Status-Indikator -- **Header mit Logo** für professionelles Erscheinungsbild -- **Zeilen hinzufügen/löschen** dynamisch zur Laufzeit -- **Einstellungsseite** für MQTT und InfluxDB Konfiguration -- Editierbare Textfelder (Bezeichnung, Adresse, Type, Faktor) -- Toggle-Schalter für Boolean-Werte (MQTT, InfluxDB) -- **Zentrale JSON-Persistierung** für alle Tabellen und Einstellungen -- REST-API für Daten-Management -- Docker-Unterstützung -- Responsive Design +- Tabellen für `modbus_input_register`, `modbus_holding_register` und `modbus_coils` +- Web-UI zum Bearbeiten und Speichern der Tabellen +- Einstellungsseite für `default`, `modbus`, `mqtt` und `influxdb` +- MQTT/Influx-Integration gemäß Konfiguration +- Speicherung aller Änderungen in `paramod.yaml` ## Lokale Entwicklung ### Voraussetzungen -- Rust (Version 1.75 oder höher) -- Cargo +- Rust + Cargo -### Installation und Start +### Start ```bash -# Projekt erstellen -cargo new paramod -cd paramod - -# Dependencies installieren und starten cargo run ``` -Der Server läuft dann auf `http://localhost:8080` +Server: `http://localhost:8080` -## Docker +## Docker (Podman) -### Container bauen +### Image bauen ```bash -podman build -t paramod . +podman build -t paramod:latest . ``` ### Container starten ```bash -poddman run -p 8080:8080 -v $(pwd)/data:/app/data paramod +podman run --rm -p 8080:8080 -v "$(pwd)/paramod.yaml:/app/paramod.yaml" paramod:latest ``` -Mit Volume-Mount bleibt die Konfigurationsdatei auch nach Container-Neustarts erhalten. - -## Verwendung - -1. Öffne `http://localhost:8080` im Browser -2. Navigiere zwischen den Tabellen über das Menü: - - **Tabelle 1, 2, 3**: Verschiedene Sensor-Gruppen - - **⚙️ Einstellungen**: MQTT und InfluxDB Konfiguration -3. In den Tabellen: - - **➕ Zeile hinzufügen**: Neue Sensor-Einträge erstellen - - **🗑️ Löschen**: Einzelne Zeilen entfernen - - **Felder bearbeiten**: - - Bezeichnung: Name des Sensors - - Adresse: IP-Adresse oder Identifier - - Type: Sensor-Typ (z.B. Temperatur, Luftfeuchtigkeit) - - Faktor: Numerischer Korrekturfaktor - - MQTT: Toggle-Schalter für MQTT-Aktivierung - - InfluxDB: Toggle-Schalter für InfluxDB-Aktivierung -4. **💾 Speichern**: Änderungen persistieren -5. Alle Daten werden zentral in `paramod.yaml` gespeichert - ## API Endpoints -- `GET /` - Zeigt Tabelle 1 -- `GET /table/table2` - Zeigt Tabelle 2 -- `GET /table/table3` - Zeigt Tabelle 3 -- `GET /settings` - Zeigt Einstellungsseite -- `POST /api/save` - Speichert eine Tabelle -- `POST /api/save-settings` - Speichert die Einstellungen -- `GET /static/*` - Statische Dateien (CSS, JS) +- `GET /` +- `GET /table/modbus_input_register` +- `GET /table/modbus_holding_register` +- `GET /table/modbus_coils` +- `GET /settings` +- `GET /api/config` +- `POST /api/save` +- `POST /api/save-settings` -### Beispiel API-Request (Tabelle speichern) +## API-Beispiel: Tabelle speichern + +Beispiel für Holding-Register: ```bash curl -X POST http://localhost:8080/api/save \ -H "Content-Type: application/json" \ -d '{ - "table_id": "table1", + "table_id": "modbus_holding_register", "rows": [ { - "bezeichnung": "Sensor 1", - "adresse": "192.168.1.100", - "type": "Temperatur", - "faktor": "1.0", - "mqtt": true, - "influxdb": false + "TVsoll": { + "addr": 2, + "type": "INT16", + "factor": 0.1, + "write": true, + "mqtt": true, + "influxdb": true, + "comment": "Vorlauf Soll" + } } ] }' ``` -### Beispiel API-Request (Einstellungen speichern) +Beispiel für Coils: ```bash -curl -X POST http://localhost:8080/api/save-settings \ +curl -X POST http://localhost:8080/api/save \ -H "Content-Type: application/json" \ -d '{ - "mqtt_broker": "localhost", - "mqtt_port": "1883", - "influxdb_url": "http://localhost:8086", - "influxdb_token": "your-token-here" + "table_id": "modbus_coils", + "rows": [ + { + "MgtSystem": { + "addr": 0, + "write": true, + "mqtt": true, + "influxdb": false, + "comment": "Leitsystem aktiv" + } + } + ] }' ``` -## Konfigurationsdatei +## Konfiguration -Die komplette Anwendungskonfiguration wird in `table_config.json` gespeichert: - -```json -{ - "table1": [ - { - "bezeichnung": "Temp Sensor 1", - "adresse": "192.168.1.100", - "type": "Temperatur", - "faktor": "1.0", - "mqtt": true, - "influxdb": false - }, - { - "bezeichnung": "Temp Sensor 2", - "adresse": "192.168.1.101", - "type": "Temperatur", - "faktor": "1.0", - "mqtt": false, - "influxdb": true - } - ], - "table2": [ - { - "bezeichnung": "Humidity Sensor 1", - "adresse": "192.168.1.200", - "type": "Luftfeuchtigkeit", - "faktor": "0.5", - "mqtt": true, - "influxdb": true - } - ], - "table3": [ - { - "bezeichnung": "Pressure Sensor 1", - "adresse": "192.168.1.300", - "type": "Druck", - "faktor": "2.0", - "mqtt": true, - "influxdb": false - } - ], - "settings": { - "mqtt_broker": "localhost", - "mqtt_port": "1883", - "influxdb_url": "http://localhost:8086", - "influxdb_token": "" - } -} -``` +Die komplette Konfiguration liegt in `paramod.yaml`. ## Lizenz