ModPulse
ModPulse is a local-first Modbus TCP monitoring and control application. It polls configured stations and devices, converts register values into operator-readable measurements, records history in SQLite, evaluates rules, and presents live status in a browser-based console.
This README is the project’s single maintained guide for operators, controls engineers, integrators, and developers. Instructions and limits below describe the checked-in implementation; verify device-specific settings against the equipment manual before connecting real hardware.
Start here
What you need
- .NET SDK
10.0.302(the SDK selected byglobal.json; a compatible later 10.0 SDK is accepted). - Bash and
curlfor the local scripts. - For browser tests or the UI tour: Node.js 18+, npm dependencies, and Playwright’s Chromium browser.
- Docker Engine and Docker Compose only if using the container workflow.
Build on Windows with PowerShell
- Install the .NET 10 SDK. The repository pins SDK
10.0.302inglobal.json; install that version or a compatible later .NET 10 SDK. - Extract the ZIP to a writable folder (avoid deeply nested paths), then open PowerShell in the extracted
ModPulsefolder. - Build the whole solution:
dotnet --version
dotnet build .\ModPulse.sln -c Release --nologo
Or use the included build-only helper:
.\deploy.ps1 -DeploymentType build-only
If Windows blocks local scripts, run that command for this process only:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\deploy.ps1 -DeploymentType build-only
After building, run the bundled simulator and web app together with .\start.ps1 local; open http://localhost:5000 and stop with Ctrl+C. This runs in Development mode and does not seed the pilot dataset automatically. .\start.ps1 docker requires Docker Desktop with Compose. Native Windows builds use framework-dependent net10.0 outputs; this source archive does not include binaries.
The shareable source archive is generated locally as artifacts/ModPulse-windows-source.zip (git-ignored build output, not committed). It contains the current source tree and README, not Git history, local configuration/secrets, build outputs, or local databases. Generate it with git ls-files -z | tar --null -T - -czf artifacts/ModPulse-windows-source.tgz or the equivalent zip step, then verify no .env, *.db, or data/ contents are included.
Run a local simulator and app
From the repository root:
./start.sh local
This builds Release binaries, starts the bundled simulator, then runs the API/UI in the foreground. Open http://localhost:5000. The simulator exposes Modbus TCP at port 10502 and its health/control API at 5001. Press Ctrl+C to stop the API and its simulator child process.
The local run uses ./data by default. It is persistent: stopping the app does not erase configuration or history. For a clean demo, use a new data directory rather than deleting a directory whose contents you need:
DataDirectory=/tmp/modpulse-demo-data ./start.sh local
To load a ready-to-use pilot-plant configuration, start ModPulse first, then in another terminal run:
MODPULSE_API_URL=http://localhost:5000 \
SIMULATOR_ENDPOINT=localhost:10502 \
bash seed_uat_data.sh
This creates one plant-floor master, five simulated devices, their register maps, and two example conditional rules. It is safe to rerun against the same database. The seed writes to the API’s configured database; it does not clear existing data. Use a disposable DataDirectory if you want an isolated demo.
Confirm both processes are ready:
curl -fsS http://localhost:5001/health
curl -fsS http://localhost:5000/health
The first endpoint returns {"status":"Healthy"}; the API returns runtime and database metrics. A healthy service alone does not prove a field device or every configured tag is communicating.
Run with Docker Compose
./start.sh docker
The script generates an untracked .env file with a random key if one is absent, then builds and starts the Compose stack. The UI/API is at http://localhost:5000; simulator REST and Modbus TCP ports are 5001 and 10502. Stop with:
./start.sh down
The stack stores data in the named Docker volume modpulse-data. ./start.sh clean also removes local build/database output and Docker volumes; it is destructive and should only be used when you intentionally want to discard local data.
For an explicit environment setup, copy .env.example to .env, set a long random MODPULSE_API_KEY, then use docker compose up --build. Keep .env private and untracked. The Compose file fails instead of substituting a public default when the key is empty.
First operator workflow
The console is organized around the function keys F1–F5 (the corresponding buttons also work with a mouse):
| Page | What it is for |
|---|---|
| F1 Overview | Current point values, quality/status, alarms, station/device context, and change-rate window. |
| F2 Devices | Configure a station (Modbus master), its devices (unit/slave IDs), and each device’s register maps (tags). Test a configured register and perform supported writes. |
| F3 Discovery | Scan an authorized subnet for Modbus TCP hosts, scan a configured station for unit IDs, and optionally probe candidate registers. |
| F4 Trends | Select one device and one tag, choose a time window, query historical samples, and inspect the chart/table. |
| F5 System | Review/configure rules; view rule execution logs and audit history; export CSV; inspect client-link and queue status/settings. |
The System page has Rules, Event Log, Audit, Export, and Settings subpages. The app’s appearance can be toggled between light and dark in the header.
Configure real equipment
Start with the simulator and a small, read-only set of tags. Before connecting a production PLC, RTU, or gateway, verify its network route, firewall rules, Modbus TCP port, unit ID, register reference convention, function code, data type, word/byte order, and permissible polling rate with the device documentation and controls owner.
- On Devices, add a Station. Give it a recognizable plant/line name, choose the supported connection type, enter the Modbus endpoint (usually
host:502for standard Modbus TCP), and set a poll interval and timeout appropriate to the equipment. - Add a Device beneath that station. Its unit/slave ID must match the endpoint’s configured unit ID. Use a human name such as
Boiler Feed Pumprather than a generic label. - Add one Register per meaningful signal. Set name, function code, zero-based protocol address, count, data type, units, scale/offset, poll interval, historian deadband, maximum log interval, and active state.
- Save the map and use Test where available. Compare the raw/engineering result with a trusted display or a known simulator value before enabling a larger map.
- Confirm the point appears on Overview, updates, and has sensible quality/status. Use Trends after history samples have accumulated.
- Add conditional rules only after validating the point and safe action. Test alarms/actions with a simulator or an approved non-production target first.
Addressing: Modbus protocol addresses are generally zero-based, while vendor manuals often show references such as 40001. A common convention maps 40001 to protocol address 0, but vendors vary; do not blindly subtract one. For a 32-bit or 64-bit value, the map must request enough adjacent 16-bit registers. Confirm word order and floating-point representation for the particular device. ModPulse’s numeric converter interprets multi-register values in big-endian word order; it does not offer per-tag byte/word-swap configuration.
Scaling: The intended engineering calculation is decoded raw value × scale factor + offset. Apply scale only when the device map confirms it (for example, an integer tenths-of-a-degree register may use scale 0.1). Do not apply scale to a register already reported in engineering units.
Polling and history are different: The station poll interval sets the fastest scan cadence. A tag may poll more slowly. Historian deadband suppresses repeated near-identical samples, while maximum log interval forces periodic retention of a stable value. Live display updates are independent of whether every poll creates a history row.
Example pilot map
seed_uat_data.sh creates a simulator-backed example with:
| Simulated asset | Example tags |
|---|---|
| Press line PLC, unit 1 | CPU temperature/load, memory use, cycle time |
| Extruder drive, unit 2 | Motor speed/current, DC bus voltage |
| Barrel transmitter, unit 3 | Barrel-zone temperature |
| Hydraulic transmitter, unit 4 | Hydraulic pressure |
| Coolant flow meter, unit 5 | Flow rate and totalizer |
The simulator generates changing process-like values with device-specific operating ranges and noise. They are synthetic test data, not calibration values, safety limits, or evidence of real field-device compatibility.
Simulator use and fault testing
The .NET simulator provides deterministic sample devices with changing values and fault controls. Its defaults are Modbus TCP port 10502, REST port 5001, device count 25, seed 42, and update cadence 500 ms (the Docker image configures 10 devices). Runtime environment/configuration can override these values, including Simulator__Port, Simulator__DeviceCount, Simulator__Seed, and Simulator__UpdateCadenceMs.
Useful simulator endpoints:
curl http://localhost:5001/health
curl http://localhost:5001/devices
curl -X POST http://localhost:5001/devices/1/inject-failure \
-H 'Content-Type: application/json' \
-d '{"type":"timeout","duration":10}'
curl -X POST http://localhost:5001/devices/1/recover
curl -X POST 'http://localhost:5001/devices/1/registers/100?value=42.5'
The exact accepted failure modes are defined by src/ModPulse.Simulator; inspect that implementation before building automation around a fault type. Manual register overrides are temporary and the simulation resumes after the configured hold period. Keep the simulator and its REST endpoint on a trusted local/test network.
There is also a Python simulator under simulator/ with dependencies in simulator/requirements.txt; the primary scripts and current .NET integration/UAT runs use src/ModPulse.Simulator.
How the pieces fit
Modbus TCP devices <-> ModPulse Engine <-> SQLite config/history
^
|
Browser <-> API + static UI + SignalR
- Core (
src/ModPulse.Core/): domain models, enums, interfaces, numeric conversion, and request validation. - Data (
src/ModPulse.Data/): EF Core SQLite contexts and repositories. - Engine (
src/ModPulse.Engine/): polling, rule evaluation, logging/maintenance, Modbus communication, and notifications. - API (
src/ModPulse.Api/): CRUD/data/health/discovery endpoints, SignalR hub, and static UI serving. - Web (
src/ModPulse.Web/wwwroot/): browser application; it is served by the API and needs no separate frontend server. - Engine service (
src/ModPulse.EngineService/): headless host for background engine services. - Simulator (
src/ModPulse.Simulator/): Modbus TCP test server plus health, data, and fault-control REST endpoints.
Configuration and history are stored in config.db and logs.db under DataDirectory (default ./data). Keep backups of both databases. Stop writers or use SQLite’s supported backup mechanism rather than copying only a live database file; WAL sidecars may contain committed data not yet folded into the main file.
Configuration and safe sharing
Settings are read from appsettings JSON files and environment variables. Common settings:
| Setting | Purpose |
|---|---|
ASPNETCORE_ENVIRONMENT |
Development or Production; local start.sh defaults to Development. |
ASPNETCORE_URLS |
API or simulator HTTP bind address. |
DataDirectory |
Directory for the SQLite databases. |
MODPULSE_API_KEY |
Required to be non-empty at API startup outside Development. |
Webhook__Url / WEBHOOK_URL |
Optional rule notification destination. |
Simulator__Port / SIMULATOR_PORT |
Simulator Modbus TCP port (the UAT runner uses SIMULATOR_PORT). |
SIMULATOR_API_PORT |
Simulator REST API port used by repository scripts. |
Never commit .env, real API keys, certificates/private keys, database files, or customer-specific device maps. .env.example contains no credential. Deployment scripts create random .env keys; review generated configuration locally and manage production secrets through your deployment platform where available. Rotate any credential that has ever been committed or shared.
Security limitation: although the API requires MODPULSE_API_KEY to be set at production startup and the browser sends an X-API-Key header, the current API code does not validate that header on incoming requests. There is no user/role/permission system. Do not treat the setting as effective authentication or expose this build to an untrusted network; use an appropriately secured, restricted environment until access control has been implemented and tested. The bundled simulator’s REST control endpoints are also unauthenticated and must remain on a trusted network.
API quick reference
The source of truth is src/ModPulse.Api/Endpoints/ApiEndpoints.cs. CRUD collections use the listed GET, POST, PUT /{id}, and DELETE /{id} patterns unless noted.
| Area | Routes |
|---|---|
| Masters | /api/masters, /api/masters/{id} |
| Devices/slaves | /api/slaves, /api/slaves/{id}, /api/masters/{masterId}/slaves |
| Register maps | /api/registermaps, /api/registermaps/{id}, POST /api/registermaps/{id}/test, POST /api/registermaps/{id}/write |
| Templates | /api/templates, /api/templates/{id}, POST /api/slaves/{slaveId}/apply-template/{templateId} |
| Rules | /api/rules, /api/rules/{id}, POST /api/rules/{id}/trigger |
| Discovery | POST /api/discovery/network-scan?subnet=…&port=…, POST /api/discovery/scan/{masterId}, POST /api/discovery/probe/{masterId}/{slaveId}, POST /api/discovery/save/{masterId}, POST /api/discovery/autopopulate/{slaveId} |
| Data | GET /api/data/{slaveId}/{registerMapId}/latest, /history, /api/data/recent, /api/data/pulse-logs, /api/data/partitions |
| Audit/export | GET /api/audit, /api/audit/export, /api/data/{deviceId}/{regId}/export |
| Health | GET /health, GET /api/health |
| Realtime | SignalR hub /hub/modbus |
History defaults to the previous day and 1,000 rows; requested limits must be 1–10,000 and history windows cannot exceed five years. Discovery scans actively probe networks/devices: only run them on subnets and equipment you are authorized to scan.
Build, tests, and UI tour
Build the solution:
dotnet build ModPulse.sln -c Release --nologo
Run the .NET suite with a simulator:
./run-tests.sh
Run the complete browser suite:
./run_all_uat.sh
run_all_uat.sh builds unless SKIP_BUILD=1, starts isolated simulator/API processes with ephemeral ports and a temporary database, seeds the pilot plant, runs all uat/*.spec.js files serially in Chromium, and cleans up afterward. It leaves the default ./data databases and any separately running local app alone. If iterating after a successful build, SKIP_BUILD=1 skips only the build; the isolated services and data seed still run. Override browser concurrency with PLAYWRIGHT_WORKERS, but the default is one because journeys share mutable app state.
Run focused journeys:
./run_all_uat.sh uat/00-smoke-user-journeys.spec.js
./run_all_uat.sh uat/07-exploratory-operator-journeys.spec.js --reporter=list
./run-e2e-tests.sh
The .NET tests cover API contracts/validation, Modbus decoding and polling, persistence, rules, logging, and failure handling. Playwright tests cover smoke/onboarding journeys, operator workflows, responsive UI, trends, navigation, and deadlock/softlock behavior through browser interaction. Three intentionally skipped journeys document unimplemented product gaps: multi-tag trend overlays, bulk register-map import, and user/role management. A skipped workflow is not tested feature coverage.
The UI tour GIF above is generated from the running app against the simulator and seeded sample data. To install the browser dependency if missing:
npm ci
npx playwright install chromium
Repository map
src/ModPulse.Api/ API host, endpoints, SignalR
src/ModPulse.Core/ domain models, validation, conversion
src/ModPulse.Data/ SQLite contexts and repositories
src/ModPulse.Engine/ polling, logging, rules, Modbus
src/ModPulse.EngineService/Headless engine host
src/ModPulse.Simulator/ .NET Modbus TCP simulator
src/ModPulse.Web/ UI assets served by the API
simulator/ Optional Python simulator
tests/ .NET tests
uat/ Playwright browser journeys
deploy/ Container and service deployment files
Troubleshooting
Port is already in use: local quick start expects 5000, 5001, and 10502. Stop only the ModPulse process you started, or use the test harness, which chooses ephemeral ports. Do not kill unrelated processes to free ports.
Simulator health fails: check that the simulator process started and that 5001 is reachable; check the Modbus TCP port in the configured master and SIMULATOR_PORT.
API/UI does not open: check http://localhost:5000/health, API startup output, ASPNETCORE_URLS, and whether another process owns port 5000.
Live values are missing: confirm a master is active and points to the correct host/port; verify the device unit ID, active state, register function/address/count/type, and simulator/field-device reachability. Confirm the API’s DataDirectory is the database you seeded or configured. A successful health check does not guarantee a successful Modbus read.
No trend samples yet: history is created by polling and may be suppressed by deadband until the maximum log interval. Wait for collection, query a matching device/tag and date range, and confirm the tag is active.
Browser test cannot launch Chromium: install it with npx playwright install chromium and install the host OS dependencies if Playwright reports missing libraries.
Resetting a demo: point DataDirectory to a new disposable directory. Avoid ./start.sh clean unless you intend to remove local build/database artifacts and Docker volumes.
Project status
The simulator-backed build and tests are useful development and pilot evidence, not certification or proof of production readiness. Validate against target hardware and review deployment security, backups/restores, upgrade/rollback, monitoring, capacity, and operational support before production use.
