DH40 — Data flow

Deutsche Version · Project overview · VPS demo parity · VPS operations · Test lab: Mac edge + VPS

How sensor, app, and health data move through DeinHaus 4.0 — from a household Raspberry Pi to TH Deggendorf servers and research tooling.

Canonical stack: dh40-software-and-hardware-architecture-master/wohnung/docker/ (edge) and …/thd/ (central).


Overview

DH40 uses four parallel data paths (two at the household edge, one cloud-only health import, one Jetson research):

Path Store Purpose Consumers
Local time series InfluxDB 1.8 (sensors) Live charts, recent history on the tablet dh40-app Wohndaten, optional Chronograf
Central study pipeline HiveMQ → MariaDB Long-term study storage, exports, ML THD research, dh40-spark, Streamlit, etc.
Withings health Withings cloud → MariaDB (dh40_withings / database_science) Weight, sleep, activity from study devices THD research, Streamlit — not local Influx charts
Camera / emergency ML Local logs on Jetson (research only) Fall / presence / audio emergency prototypes Lab notebooks, thesis — not production Pi stack

The tablet and lab UIs read local sensor data (MQTT + Influx). Anonymised Z-Wave and button data replicate to THD over VPN + MQTT bridge. Withings bypasses the Pi data plane — see §3. Cameras are a separate research track on Jetson — see §4.

flowchart TB subgraph edge["Household edge (Raspberry Pi)"] ZW[zwavejs2mqtt / sensors] MQ[Mosquitto] TG[Telegraf] INFL[(InfluxDB)] CFG[config-provider] APP[dh40-app] LAB[laborvisualisierung] ZW -->|zwavejs2mqtt/… TCP 1883| MQ MQ --> TG --> INFL APP -->|Flux HTTPS :8087| INFL APP -->|mqtts WSS :8883| MQ APP -->|homeid, Withings config| CFG LAB -->|mqtts WSS :8883| MQ APP -->|app/button_*| MQ end subgraph uplink["Secure uplink"] VPN[OpenVPN client] CERTS[dh40-ca client + MQTT certs] end subgraph thd["TH Deggendorf"] HIVE[HiveMQ] H2D[MQTT → DB connectors] MDB[(MariaDB)] EXP[Exports / VPN portal] HIVE --> H2D --> MDB MDB --> EXP end subgraph research["Research (offline)"] SPARK[dh40-spark] SDS[sensor-data-science] ST[dh40-streamlit] EXP --> SPARK EXP --> SDS EXP --> ST end MQ -->|bridge TLS VPN| HIVE VPN --- edge CERTS --- MQ

1. Sensor data (edge)

Source

MQTT topics

Topics follow the zwavejs2mqtt/<gateway>/<node>/… pattern. Examples:

Topic pattern Example measured Used by
…/Air_temperature Room temperature Wohndaten chart, lab
…/Humidity Relative humidity Wohndaten, lab
…/+/Door_state Door/window contact Wohndaten table, lab
…/+/Motion_sensor_status PIR motion Wohndaten heatmap, lab
…/Power Smart plug watts Wohndaten chart
…/Volatile_Organic_Compound_level VOC Wohndaten chart
…/level, …/isLow Battery level Wohndaten table

Full bridge topic list: wohnung/docker/mosquitto2mosquitto/config/mosquitto.conf.

Message format

Telegraf mqtt_consumer expects JSON (see influxdb/telegraf/mytelegraf.conf):

{
  "time": 1719000000000,
  "value": "22.5",
  "nodeName": "Raumklimasensor",
  "nodeLocation": "Wohnzimmer"
}

topic_parsing adds tags: sensor_id, measured, measured_detail.

Into InfluxDB

MQTT (1883) → Telegraf → InfluxDB measurement mqtt_consumer

Into MariaDB (study)

Same MQTT stream is bridged to THD HiveMQ (TLS, client certificates, topic prefix data/<home_id>/). Connectors write to MariaDB database dh40 (raw).


2. Tablet app data (dh40-app)

Config (unlock + Withings)

Request Production Content
GET …/homeid.txt https://<pi>:8080/homeid.txt Study home ID (e.g. 01V56TVL) or DEMODEMO
GET …/config.json https://<pi>:8080/config.json Withings OAuth tokens (per household; legacy — see §3)

Served by config-provider (nginx). App maps home ID → study group → training video week.

Button log (activity protocol)

When the resident taps UI buttons, dh40-app publishes via MQTT over WebSocket:

Topic Payload
app/button_press { buttonId, timestamp } per tap
app/full_button_log Periodic bulk export of local button history

Production: mqtts://<pi>:8883. These topics are also bridged to HiveMQ for MariaDB.

Wohndaten charts

dh40-app queries InfluxDB Flux (not MQTT) for historical sensor charts:


3. Withings health data

Withings devices do not connect to the Raspberry Pi and do not use local MQTT or Influx. They pair with the participant’s phone and Withings’ cloud (Health Mate). The study imports health metrics via a central batch job on THD, parallel to but separate from the Z-Wave edge pipeline.

Repos: dh40-withings-mariadb-main, dh40-withings-auth-server-main, dh40_config_provider_poc-main, dh40-app-withings-poc-master (POC only).

flowchart TB subgraph participant["Participant"] DEV[Withings scale / watch / sleep mat] HM[Withings Health Mate app] DEV <-->|Wi‑Fi / BT| HM HM <-->|Withings cloud| WC[Withings REST API] end subgraph edge["Household edge (Pi) — config only"] CFG[config-provider :8080] APP[dh40-app tablet] APP -->|GET homeid.txt| CFG APP -.->|optional config.json POC| CFG APP -->|deep link withings://home| HM end subgraph setup["One-time OAuth (per home ID)"] AUTH[dh40-withings-auth-server] AUTH -->|refresh_token| TOK[Withings-Tokens/home_id/credentials.json] end subgraph thd["TH Deggendorf — daily import"] CRON[dh40-withings-mariadb cron] CRON -->|HTTPS + OAuth| WC CRON --> RAW[(MariaDB dh40_withings)] CRON --> WH[(MariaDB dh40_warehouse / database_science)] end WC --- participant TOK --> CRON

Devices and participant UX

Piece Role
Withings hardware Scale, watch, sleep analyzer, etc.
Health Mate app Pairing and daily use; participant views their own metrics
dh40-app “Gesundheitsdaten” page Links to Health Mate (withings://home) — no Withings charts in dh40-app
Wohndaten charts Influx only (environmental Z-Wave sensors)

OAuth setup (once per study home ID)

  1. Research staff run dh40-withings-auth-server (Flask) or an equivalent OAuth flow.
  2. Participant authorizes the DH40 Withings application in the browser.
  3. Callback yields refresh_token and access_token.
  4. Tokens are stored on THD under Withings-Tokens/<home_id>/credentials.json (e.g. 01V56TVL).

The Pi config-provider may also serve config.json with OAuth fields — used by dh40-app-withings-poc (browser → Pi config → Withings API). In the main dh40-app, fetchWithingsConfig is disabled (App.tsx); production import does not depend on the tablet fetching tokens.

Central batch import (dh40-withings-mariadb)

Runs on THD Docker (docker-compose.yml), not on the Pi:

Schedule Script Action
Daily 17:00 withings_to_db.py For each Withings-Tokens/<home_id>/, call Withings API and append rows
Daily 00:00 sensor_data_transfer.py Unrelated to Withings — copies Z-Wave warehouse tables

withings_to_db.py calls the Withings API (refreshing tokens as needed):

API call MariaDB table Content
measure_get_meas withings_measures Weight, heart rate, body composition, …
sleep_get_summary withings_sleepsum Nightly sleep aggregates (duration, score, HR/RR stats, …)
sleep_get withings_sleep Time-series sleep states, HR, RR, snoring

Writes go to dh40_withings (raw) and dh40_warehouse / database_science (research warehouse).

Withings vs Z-Wave — quick comparison

Z-Wave sensors Withings health
Device → hub Z-Wave USB → Pi Phone → Withings cloud
Edge protocol MQTT on Pi None on Pi
Local store InfluxDB None
Tablet charts Wohndaten (Flux) Health Mate app only
Central store MQTT bridge → dh40 API pull → withings_* tables
Timing Near real-time Daily batch cron

Mosquitto bridge note

The Pi bridge config includes an inbound rule data/<home_id>/withings/# (HiveMQ → local Mosquitto). This is not the primary Withings import path; production data enters via withings_to_db.py on THD.

Research consumption

Withings tables in database_science feed batch tools: dh40-streamlit, sensor-data-science, dh40-spark — via THD VPN exports (https://dh40-vpn.th-deg.de:8443), same as other study data.


4. Camera and emergency detection (research)

Video and audio emergency detection in DH40 are research sidecars — they are not deployed in the standard household Pi stack (wohnung/docker/), not on the public VPS demo, and not integrated with dh40-app live charts or the HiveMQ study bridge in the archived code.

Repos: dh40-camera-module-master, dh40-emergency-detection-main, dh40-smart-mirror-2-main (trade-show emotion demo).

flowchart LR subgraph research["Research edge (Jetson Nano — optional)"] CAM[USB webcam /dev/video0] JET[Jetson Docker] MP[MediaPipe pose + fall rules] SSD[jetson-inference person detect] AUD[USB mic / ESP32 audio WIP] CAM --> JET JET --> MP JET --> SSD AUD -.-> JET MP -->|stdout / local| LOG[Console / future MQTT stub] SSD -->|CSV| LOG end subgraph prod["Production study stack — separate"] PI[Raspberry Pi MQTT + Influx] APP[dh40-app Wohndaten] PI --> APP end research -.-x prod

What exists in the repos

Project Hardware Input Output (today) Status
dh40-camera-module Jetson Nano + webcam Live video (/dev/video0) print('Fall detected'); commented MQTT stub in mediapipe/main.py Research prototype
dh40-camera-module / jetson Jetson + jetson-inference Video stream detections.csv (person count, confidence) Separate SSD demo
dh40-emergency-detection Jetson + mic + webcam Audio (ESC-50, fall sounds) + video (MediaPipe) Notebooks, local CSV/logs; compared audio vs video fall detection Ongoing research / MA
dh40-smart-mirror-2 Jetson + webcam Face video Emotion overlay on mirror display Trade-show demonstrator

dh40-camera-module flow (video fall detection)

Typical lab setup from the repo README:

  1. Jetson Nano with USB camera, Docker + NVIDIA runtime.
  2. mediapipe/start.sh runs pose estimation (pose_estimation.py / main.py).
  3. MediaPipe Pose extracts body landmarks per frame.
  4. FallDetector applies geometric rules (neck/COM movement, body angle, bounding-box aspect ratio) over a short frame window.
  5. On validated fall: logs to stdout (Fall detected). MQTT publish code exists but is commented out — no broker, topic, or Pi integration configured.

This is edge ML on Jetson, not streaming video to the tablet or THD.

dh40-emergency-detection flow (audio + video research)

Parallel research track (contactless emergency detection):

Track Approach
Audio Mel-spectrogram + CNN on ESC-50; extended with fall sound samples; live inference on Jetson
Video Reuses MediaPipe fall-detection logic; compared against audio in project 2
Future (MA) ESP32 microphone network instead of single Jetson device

No connection to Mosquitto, InfluxDB, or MariaDB in the archived codebase.

vs production DH40 and vs consumer surveillance

Production Pi stack Camera research sidecar Consumer surveillance (Ring, etc.)
Device Raspberry Pi Jetson Nano Vendor camera + cloud
Data MQTT JSON events Local video processing H.264 streams + clips
Tablet / phone dh40-app on LAN No integrated viewer Vendor mobile app
Study DB MQTT bridge → MariaDB Not wired in repo Vendor cloud
Purpose Ambient sensing study Fall / emergency ML R&D Security monitoring

Could cameras join the Pi MQTT bus?

In principle, a custom publisher could send events (e.g. fall_detected) to Mosquitto if someone implements the bridge — main.py even sketches paho.mqtt. Nothing in the canonical architecture repo does this today. Video itself is not stored in Influx or MariaDB.

Research consumption

Results stay in local logs, CSV, and notebooks on the Jetson or developer machine until manually exported. They do not flow through dh40-spark / Streamlit pipelines unless researchers add that separately.


5. Lab visualization

dh40-laborvisualisierung subscribes to the same MQTT broker (WebSocket) and updates floor-plan tiles in real time. It does not use Influx for the live view.


Mechanism Role
dh40-ca Issues OpenVPN client cert per home ID
OpenVPN Pi joins THD network (e.g. reach 10.8.0.1)
MQTT bridge certs ca.crt, <home_id>.crt/.key for HiveMQ TLS
Self-signed dh40_web.crt HTTPS on Pi (config-provider, Influx proxy, mqtts)

Without VPN + trusted certs, the Mosquitto → HiveMQ bridge does not run.


7. TH Deggendorf (central)

flowchart LR BR[Mosquitto bridge] -->|data/home_id/…| HIVE[HiveMQ] HIVE --> W2D[hivemq2db / connectors] W2D --> RAW[(MariaDB dh40)] W2D --> SCI[(MariaDB database_science)] WITH[dh40-withings-mariadb] --> SCI
Database Typical contents
dh40 Raw MQTT / sensor stream
database_science Cleaned features, app logs, Withings (withings_*)

Exports for researchers: https://dh40-vpn.th-deg.de:8443 (THD VPN required). See dh40-spark-main/data/README.md.


8. Research and analytics (batch)

Downstream tools work on exports, not live MQTT:

Project Input Role
dh40-spark dh40-raw/, dh40-science/ dumps Large-scale PySpark / Jupyter
sensor-data-science CSV exports Daily sensor features + sleep merge
dh40-streamlit Categorised CSV / Withings samples Interactive exploration

This path is orthogonal to the live household stack: no Influx on the research laptops unless you build a separate export.


9. Public VPS demo (_demo/)

The IONOS demo simulates the household edge for presentations. It does not connect to HiveMQ or MariaDB.

flowchart LR SIM[mqtt-simulator] MQ[Mosquitto] TG[Telegraf] INFL[(InfluxDB)] CADDY[Caddy HTTPS] APP[dh40-app /app] LAB[lab /lab] SIM -->|zwavejs2mqtt/…| MQ MQ --> TG --> INFL CADDY -->|/influx Flux| INFL CADDY -->|/mqtt WSS| MQ CADDY -->|/config| CFG[homeid + config.json] APP --> CADDY LAB --> CADDY
Production Demo equivalent
zwavejs2mqtt mqtt-simulator.py
config-provider :8080 Caddy /config/
influxdb-proxy :8087 Caddy /influx/
mqtts :8883 wss://<domain>/mqtt
30d Influx history influx-seed (one-shot)
OpenVPN + HiveMQ bridge Not deployed

Details: demo-production-parity.md, vps-operations.md.


10. Quick reference — who talks to what

Client Protocol Target Data
dh40-app HTTPS config-provider home ID, Withings config (legacy)
dh40-app Flux/HTTPS Influx proxy Wohndaten time series
dh40-app WSS/MQTT Mosquitto Button presses
dh40-app deep link Health Mate app Open Withings UI (no DH40 data transfer)
laborvis WSS/MQTT Mosquitto Live sensor tiles
Telegraf TCP/MQTT Mosquitto Subscribe all sensor topics
Mosquitto bridge TLS/MQTT HiveMQ (THD) Z-Wave + button study replication
dh40-withings-mariadb HTTPS REST Withings API Measures + sleep → MariaDB
Researcher HTTPS (VPN) dh40-vpn.th-deg.de DB exports (incl. withings_*)

See also