Compare commits

..

No commits in common. "67b0e4ebd7cf61f1705f5bb2be2adc559bd83d57" and "58bacd2f6df21d4ca59196818dc68c047196fdba" have entirely different histories.

11 changed files with 72 additions and 489 deletions

View File

@ -1,31 +0,0 @@
name: Build Docker Image (Podman)
on:
push:
branches: [ main ]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install Podman
run: sudo apt-get update && sudo apt-get install -y podman
- name: Checkout code
uses: actions/checkout@v3
- name: Set version in Cargo.toml
run: |
VERSION=$(cat VERSION)
sed -i "s/^version = \"__VERSION__\"/version = \"$VERSION\"/" Cargo.toml
- name: Build image with Podman
run: |
VERSION=$(cat VERSION)
podman build -t paramod:latest -t git.skaville.rocks/eneuber/paramod:$VERSION .
- name: Login to Gitea Registry
run: echo ${{ secrets.REGISTRY_TOKEN }} | podman login -u ${{ secrets.USER }} --password-stdin git.skaville.rocks
- name: Push image with version
run: |
VERSION=$(cat VERSION)
podman push git.skaville.rocks/eneuber/paramod:$VERSION
- name: Push image latest
run: podman push git.skaville.rocks/eneuber/paramod:latest

2
.vscode/launch.json vendored
View File

@ -5,7 +5,7 @@
"name": "Debug main.rs",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/target/debug/paramod",
"program": "${workspaceFolder}/target/debug/table-server",
"args": [],
"cwd": "${workspaceFolder}",
"sourceLanguages": ["rust"],

340
Cargo.lock generated
View File

@ -8,7 +8,7 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a"
dependencies = [
"bitflags 2.10.0",
"bitflags",
"bytes",
"futures-core",
"futures-sink",
@ -29,7 +29,7 @@ dependencies = [
"actix-service",
"actix-utils",
"actix-web",
"bitflags 2.10.0",
"bitflags",
"bytes",
"derive_more",
"futures-core",
@ -53,7 +53,7 @@ dependencies = [
"actix-service",
"actix-utils",
"base64 0.22.1",
"bitflags 2.10.0",
"bitflags",
"brotli",
"bytes",
"bytestring",
@ -300,12 +300,6 @@ version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.10.0"
@ -407,10 +401,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [
"iana-time-zone",
"js-sys",
"num-traits",
"serde",
"wasm-bindgen",
"windows-link",
]
@ -699,32 +690,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "futures-channel"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-macro"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.31"
@ -744,7 +715,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
"futures-core",
"futures-macro",
"futures-sink",
"futures-task",
"pin-project-lite",
@ -804,7 +774,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757"
dependencies = [
"bitflags 2.10.0",
"bitflags",
"ignore",
"walkdir",
]
@ -864,17 +834,6 @@ dependencies = [
"itoa",
]
[[package]]
name = "http-body"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
dependencies = [
"bytes",
"http",
"pin-project-lite",
]
[[package]]
name = "http-range"
version = "0.1.5"
@ -902,44 +861,6 @@ dependencies = [
"libm",
]
[[package]]
name = "hyper"
version = "0.14.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7"
dependencies = [
"bytes",
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"socket2 0.5.10",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590"
dependencies = [
"futures-util",
"http",
"hyper",
"rustls",
"tokio",
"tokio-rustls",
]
[[package]]
name = "iana-time-zone"
version = "0.1.64"
@ -1098,29 +1019,6 @@ dependencies = [
"hashbrown 0.16.0",
]
[[package]]
name = "influxdb"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "601aa12a5876c044ea2a94a9443d0f086e6fc1f7bb4264bd7120e63c1462d1c8"
dependencies = [
"chrono",
"futures-util",
"http",
"lazy_static",
"regex",
"reqwest",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "ipnet"
version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
[[package]]
name = "itoa"
version = "1.0.15"
@ -1317,26 +1215,6 @@ dependencies = [
"hashbrown 0.14.5",
]
[[package]]
name = "paramod"
version = "0.3.0"
dependencies = [
"actix-files",
"actix-web",
"chrono",
"config",
"influxdb",
"rumqttc",
"serde",
"serde_derive",
"serde_json",
"serde_yaml",
"tera",
"tokio",
"tokio-modbus",
"toml",
]
[[package]]
name = "parking_lot"
version = "0.12.5"
@ -1593,7 +1471,7 @@ version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
"bitflags 2.10.0",
"bitflags",
]
[[package]]
@ -1631,47 +1509,6 @@ version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
[[package]]
name = "reqwest"
version = "0.11.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
dependencies = [
"base64 0.21.7",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"hyper",
"hyper-rustls",
"ipnet",
"js-sys",
"log",
"mime",
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"system-configuration",
"tokio",
"tokio-rustls",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"webpki-roots",
"winreg",
]
[[package]]
name = "ring"
version = "0.17.14"
@ -1693,7 +1530,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
dependencies = [
"base64 0.21.7",
"bitflags 2.10.0",
"bitflags",
"serde",
"serde_derive",
]
@ -1821,7 +1658,7 @@ version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [
"bitflags 2.10.0",
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
@ -2032,12 +1869,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "synstructure"
version = "0.13.2"
@ -2050,24 +1881,21 @@ dependencies = [
]
[[package]]
name = "system-configuration"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
name = "table-server"
version = "0.1.0"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
dependencies = [
"core-foundation-sys",
"libc",
"actix-files",
"actix-web",
"config",
"rumqttc",
"serde",
"serde_derive",
"serde_json",
"serde_yaml",
"tera",
"tokio",
"tokio-modbus",
"toml",
]
[[package]]
@ -2270,12 +2098,6 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
[[package]]
name = "tower-service"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "tracing"
version = "0.1.41"
@ -2308,12 +2130,6 @@ dependencies = [
"once_cell",
]
[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "typenum"
version = "1.19.0"
@ -2402,15 +2218,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
"try-lock",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
@ -2439,19 +2246,6 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0"
dependencies = [
"cfg-if",
"js-sys",
"once_cell",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.105"
@ -2484,22 +2278,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "web-sys"
version = "0.3.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "webpki-roots"
version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "winapi-util"
version = "0.1.11"
@ -2568,15 +2346,6 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
@ -2604,21 +2373,6 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
@ -2652,12 +2406,6 @@ dependencies = [
"windows_x86_64_msvc 0.53.1",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
@ -2670,12 +2418,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
@ -2688,12 +2430,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
@ -2718,12 +2454,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
@ -2736,12 +2466,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
@ -2754,12 +2478,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
@ -2772,12 +2490,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
@ -2799,16 +2511,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
"windows-sys 0.48.0",
]
[[package]]
name = "wit-bindgen"
version = "0.46.0"

View File

@ -1,6 +1,6 @@
[package]
name = "paramod"
version = "__VERSION__"
name = "table-server"
version = "0.1.0"
edition = "2021"
[dependencies]
@ -19,5 +19,3 @@ serde_derive = "1.0"
tokio-modbus = "0.7"
rumqttc = "0.23"
influxdb = "0.7"
chrono = { version = "0.4", features = ["serde"] }

View File

@ -1,33 +1,44 @@
# Build Stage
FROM rust:1.81 as builder
FROM rust:1.75 as builder
WORKDIR /usr/src/app
# Copy manifest files
COPY Cargo.toml ./
COPY Cargo.lock ./
# Copy source code and templates
COPY src ./src
COPY templates ./templates
COPY static ./static
# Build the application
RUN cargo build --release
# Runtime Stage
FROM debian:bookworm-slim
# Install required dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /usr/src/app/target/release/paramod /app/paramod
# Copy the binary from builder
COPY --from=builder /usr/src/app/target/release/table-server /app/table-server
# Copy templates and static files
COPY --from=builder /usr/src/app/templates /app/templates
COPY --from=builder /usr/src/app/static /app/static
COPY paramod.yaml /app/paramod.yaml
# Create directory for config file
RUN mkdir -p /app/data
# Expose port
EXPOSE 8080
ENV CONFIG_PATH=/app/paramod.yaml
# Set environment to use the data directory
ENV CONFIG_PATH=/app/data/table_config.json
CMD ["/app/paramod"]
# Run the binary
CMD ["/app/table-server"]

View File

@ -5,7 +5,7 @@ Ein einfacher Rust-Webserver, der eine editierbare 3x3-Tabelle bereitstellt und
## Projektstruktur
```
paramod/
table-server/
├── src/
│ └── main.rs
├── templates/
@ -46,8 +46,8 @@ paramod/
```bash
# Projekt erstellen
cargo new paramod
cd paramod
cargo new table-server
cd table-server
# Dependencies installieren und starten
cargo run
@ -60,17 +60,39 @@ Der Server läuft dann auf `http://localhost:8080`
### Container bauen
```bash
podman build -t paramod .
docker build -t table-server .
```
### Container starten
```bash
poddman run -p 8080:8080 -v $(pwd)/data:/app/data paramod
docker run -p 8080:8080 -v $(pwd)/data:/app/data table-server
```
Mit Volume-Mount bleibt die Konfigurationsdatei auch nach Container-Neustarts erhalten.
### Docker Compose (optional)
Erstelle eine `docker-compose.yml`:
```yaml
version: '3.8'
services:
table-server:
build: .
ports:
- "8080:8080"
volumes:
- ./data:/app/data
restart: unless-stopped
```
Starten mit:
```bash
docker-compose up -d
```
## Verwendung
1. Öffne `http://localhost:8080` im Browser
@ -88,7 +110,7 @@ Mit Volume-Mount bleibt die Konfigurationsdatei auch nach Container-Neustarts er
- 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
5. Alle Daten werden zentral in `table_config.json` gespeichert
## API Endpoints

View File

@ -1 +0,0 @@
0.3.0

View File

@ -14,7 +14,7 @@ influxdb:
measurement: ParadigmaModbus
org: skaville
token: i-sXFQbEkSC1XVzqFEaFwXwzasbsEIciVlK4SaAUOEvk0VjQPkD3fr8d7_3SPeyseTZkqj7ZMZU78b3n2F6_SQ==
url: http://192.168.178.2:8086
url: 192.168.178.2:8086
modbus:
host: 192.168.178.10
port: 502

View File

@ -1,112 +0,0 @@
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use crate::config::{AppConfig, ModbusValueMaps};
use influxdb::{Client, WriteQuery, Timestamp};
use chrono::Utc;
use tokio::runtime::Runtime;
pub fn start_influx_thread(config: Arc<Mutex<AppConfig>>, values: Arc<Mutex<ModbusValueMaps>>) {
let influx_config = {
let cfg = config.lock().unwrap();
cfg.influxdb.clone()
};
let url = influx_config.url.clone();
let bucket = influx_config.bucket.clone();
let _org = influx_config.org.clone();
let token = influx_config.token.clone();
let measurement = influx_config.measurement.clone().unwrap_or_else(|| "modbus".to_string());
let location = influx_config.location.clone().unwrap_or_else(|| "default".to_string());
thread::spawn(move || {
let client = Client::new(url, bucket).with_token(token);
let rt = Runtime::new().unwrap();
loop {
let mut points = Vec::new();
{
let values = values.lock().unwrap();
// Input Register
for (name, val) in &values.modbus_input_register_values {
if let Some(v) = val {
if should_write(&config, name, "input_register") {
let point = WriteQuery::new(Timestamp::from(Utc::now()), measurement.clone())
.add_field(name, *v)
.add_tag("type", "input_register")
.add_tag("location", location.as_str())
.to_owned();
points.push(point);
}
}
}
// Holding Register
for (name, val) in &values.modbus_holding_register_values {
if let Some(v) = val {
if should_write(&config, name, "holding_register") {
let point = WriteQuery::new(Timestamp::from(Utc::now()), measurement.clone())
.add_field(name, *v)
.add_tag("type", "holding_register")
.add_tag("location", location.as_str())
.to_owned();
points.push(point);
}
}
}
// Coils
for (name, val) in &values.modbus_coils_values {
if let Some(v) = val {
if should_write(&config, name, "coils") {
let point = WriteQuery::new(Timestamp::from(Utc::now()), measurement.clone())
.add_field(name, *v)
.add_tag("type", "coils")
.add_tag("location", location.as_str())
.to_owned();
points.push(point);
}
}
}
}
if !points.is_empty() {
let res = rt.block_on(client.query(points));
if let Err(e) = res {
eprintln!("Influx write error: {}", e);
}
}
thread::sleep(Duration::from_secs(10));
}
});
}
fn should_write(config: &Arc<Mutex<AppConfig>>, name: &str, reg_type: &str) -> bool {
let cfg = config.lock().unwrap();
match reg_type {
"input_register" => {
if let Some(regs) = &cfg.modbus_input_register {
for map in regs {
if let Some(reg) = map.get(name) {
return reg.influxdb.unwrap_or(false);
}
}
}
}
"holding_register" => {
if let Some(regs) = &cfg.modbus_holding_register {
for map in regs {
if let Some(reg) = map.get(name) {
return reg.influxdb.unwrap_or(false);
}
}
}
}
"coils" => {
if let Some(coils) = &cfg.modbus_coils {
for map in coils {
if let Some(coil) = map.get(name) {
return coil.influxdb.unwrap_or(false);
}
}
}
}
_ => {}
}
false
}

View File

@ -10,7 +10,6 @@ mod config;
mod modbus;
mod app_state;
mod mqtt;
mod influx;
pub mod modbus_types;
use crate::config::{AppConfig, ModbusValueMaps};
use crate::modbus_types::{ModbusInputRegisterConfig, ModbusHoldingRegisterConfig, ModbusCoilsConfig};
@ -255,12 +254,6 @@ async fn main() -> std::io::Result<()> {
mqtt::start_mqtt_thread(Arc::clone(&app_state.config), value_maps);
}
// Starte InfluxDB-Thread
{
let value_maps = Arc::clone(&app_state.value_maps);
influx::start_influx_thread(Arc::clone(&app_state.config), value_maps);
}
println!("Server läuft auf http://0.0.0.0:8080");
HttpServer::new(move || {

View File

@ -9,6 +9,7 @@ pub struct ModbusCoilsConfig {
pub comment: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ModbusInputRegisterConfig {
pub addr: u16,