Push live values in realtime over the cloud socket.io feed #11

Merged
nexus merged 1 commit from feature/realtime-socketio into main 2026-07-30 15:11:54 +02:00
Owner

Realtime socket.io feed as the primary source of live values

Polling on an interval steps right over dosing pumps that run in short bursts of a few seconds. The vendor cloud pushes every change over a socket.io (Engine.IO v4) feed, so this subscribes to it and publishes changes the moment the controller reports them.

What's new

  • internal/realtime — Engine.IO v4 / socket.io client over websocket to the /harmopool namespace, authenticated with the same connect.sid session cookie. Reconnects with backoff.
  • Client-driven ping — the server drops a connection that only answers server pings after ~30s.
  • watchChanges per domain + activeDevice for every pumpwatchChanges alone only sees a relay every ~35–110s; activeDevice brings it to ~10s (the fastest the hardware telemeters). Both pumps stream at once on one socket.
  • Calibration — the socket ships the raw analog value (getStats returns it calibrated), so the realtime path applies the io calibration from getInfo.

Wiring

  • Realtime is primary; getStats stays on as a seldom backfill (WIFIPOOL_REALTIME_BACKFILL_INTERVAL, default 15m) plus one baseline poll at startup.
  • Updates funnel through a channel into the poller on the main goroutine, so channel state keeps a single writer. Publishing is event-driven — only a real value change or a stale transition triggers a publish.
  • Freshness is judged by the socket (WIFIPOOL_REALTIME_STALE_AFTER); a realtime update counts as a successful poll for readiness.

Config

WIFIPOOL_REALTIME_ENABLED / _STALE_AFTER / _PUBLISH_INTERVAL / _BACKFILL_INTERVAL / _ACTIVE_DEVICES, validated and documented in .env.example and the README. Set WIFIPOOL_REALTIME_ENABLED=false for the previous pure-polling behaviour.

Docs

docs/wifipool-api.md rewritten as a standalone reference covering both the HTTP and realtime APIs.

Verification

Verified live against a real installation: pump power transitions captured within ~10s, connection stable past the 30s drop point, calibration correct (pH 7.2, redox 544 mV). go build, go test ./..., -race, and golangci-lint v2.12.2 all clean. CI green on the feature branch.

## Realtime socket.io feed as the primary source of live values Polling on an interval steps right over dosing pumps that run in short bursts of a few seconds. The vendor cloud pushes every change over a socket.io (Engine.IO v4) feed, so this subscribes to it and publishes changes the moment the controller reports them. ### What's new - **`internal/realtime`** — Engine.IO v4 / socket.io client over websocket to the `/harmopool` namespace, authenticated with the same `connect.sid` session cookie. Reconnects with backoff. - **Client-driven ping** — the server drops a connection that only answers server pings after ~30s. - **`watchChanges` per domain + `activeDevice` for every pump** — `watchChanges` alone only sees a relay every ~35–110s; `activeDevice` brings it to ~10s (the fastest the hardware telemeters). Both pumps stream at once on one socket. - **Calibration** — the socket ships the raw analog value (getStats returns it calibrated), so the realtime path applies the io `calibration` from `getInfo`. ### Wiring - Realtime is primary; `getStats` stays on as a seldom backfill (`WIFIPOOL_REALTIME_BACKFILL_INTERVAL`, default 15m) plus one baseline poll at startup. - Updates funnel through a channel into the poller on the main goroutine, so channel state keeps a single writer. Publishing is event-driven — only a real value change or a stale transition triggers a publish. - Freshness is judged by the socket (`WIFIPOOL_REALTIME_STALE_AFTER`); a realtime update counts as a successful poll for readiness. ### Config `WIFIPOOL_REALTIME_ENABLED` / `_STALE_AFTER` / `_PUBLISH_INTERVAL` / `_BACKFILL_INTERVAL` / `_ACTIVE_DEVICES`, validated and documented in `.env.example` and the README. Set `WIFIPOOL_REALTIME_ENABLED=false` for the previous pure-polling behaviour. ### Docs `docs/wifipool-api.md` rewritten as a standalone reference covering both the HTTP and realtime APIs. ### Verification Verified live against a real installation: pump `power` transitions captured within ~10s, connection stable past the 30s drop point, calibration correct (pH 7.2, redox 544 mV). `go build`, `go test ./...`, `-race`, and `golangci-lint v2.12.2` all clean. CI green on the feature branch.
Push live values in realtime over the cloud's socket.io feed
All checks were successful
CI / test (push) Successful in 2m32s
CI / image (push) Successful in 1m1s
CI / publish-commit-tag (push) Has been skipped
CI / publish-version-tag (push) Has been skipped
CI / test (pull_request) Successful in 2m21s
CI / image (pull_request) Successful in 58s
CI / publish-commit-tag (pull_request) Has been skipped
CI / publish-version-tag (pull_request) Has been skipped
16e35159e0
Polling on an interval steps right over dosing pumps that run in short
bursts of a few seconds. The vendor cloud pushes every change over a
socket.io (Engine.IO v4) feed, so subscribe to it and publish changes the
moment the controller reports them.

New internal/realtime package:
- Engine.IO v4 / socket.io client over websocket to the /harmopool
  namespace, authenticated with the same connect.sid session cookie.
- Client-driven ping, because the server drops a connection that only
  answers server pings after ~30s.
- watchChanges per domain plus activeDevice for every pump: watchChanges
  alone only sees a relay every ~35-110s, activeDevice brings it to ~10s,
  which is the fastest the hardware telemeters. Both pumps stream at once.
- dataChange "device" pushes are decoded via each channel's io key and
  calibrated (the socket ships raw analog; getStats returns it calibrated).

Wiring:
- Realtime is the primary source; getStats stays on as a seldom backfill
  (WIFIPOOL_REALTIME_BACKFILL_INTERVAL, default 15m).
- Updates funnel through a channel into the poller on the main goroutine,
  so channel state keeps a single writer. Publishing is event-driven:
  only a real value change or a stale transition triggers a publish.
- Freshness is judged by the socket (WIFIPOOL_REALTIME_STALE_AFTER) and a
  realtime update counts as a successful poll for readiness.

Config: WIFIPOOL_REALTIME_ENABLED/STALE_AFTER/PUBLISH_INTERVAL/
BACKFILL_INTERVAL/ACTIVE_DEVICES, validated and documented in .env.example
and the README. docs/wifipool-api.md rewritten as a standalone reference
covering both the HTTP and realtime APIs.
nexus merged commit 99ec4029c2 into main 2026-07-30 15:11:54 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nexus/WifiPoolToMQTT!11
No description provided.