# Run an edge runtime next to eaxScada

> Register an eaxPLC edge runtime (eaxplc-rt) with eaxScada, run it with its own NATS identity, program and monitor it remotely, and write or force values.

Product: eaxPLC · Type: How-to guide · Editions: Free, Pro
Source: https://eaxware.com/docs/eaxplc/how-to/run-an-edge-runtime/
Status: migrated page, not yet verified against the current code.

`eaxplc-rt.exe` is the eaxPLC runtime without the Web Studio, for edge
devices. It runs the project, its I/O and UNS publishing, and is driven over
NATS: eaxScada works with it through its broker, and the Studio attaches to
it from any machine with `plc-server --attach`.

**Diagram: An edge runtime, the eaxScada broker and an attached Web Studio** (network topology)

The edge device runs eaxplc-rt with its fieldbus I/O and no HTTP listener. It connects out to the NATS broker on the eaxScada host with its own NKey identity, which may use only its own subjects, publish UNS telemetry and receive UNS commands. eaxScada is the sign-in and e-signature authority and raises an alarm when the PLC stops on a fault. An engineer runs plc-server --attach on another machine: it serves the Web Studio locally and carries every call to the runtime through the broker.

**Parts**

- **Edge device** (trust boundary)
- **eaxScada host** (trust boundary)
- **Engineer's machine** (trust boundary)
- **eaxplc-rt** (product, inside Edge device): runs the project; no HTTP listener; NKey \<id>.nk
- **Field devices** (field equipment, inside Edge device): over its fieldbuses
- **NATS broker** (service or process, inside eaxScada host): port 4222; a PLC identity uses its own subjects
- **eaxScada** (product, inside eaxScada host): --edge-plcs \<id>; sign-in and e-signatures; ALM-PLC-\<ID>-FAULT
- **plc-server --attach** (service or process, inside Engineer's machine): the Web Studio, served here; no PLC runs in it
- **Engineer** (person or role, inside Engineer's machine): a browser

**Connections**

- **eaxplc-rt → NATS broker** (data or telemetry): telemetry, replies. Opened by the runtime, outbound. It publishes on plc.\<id>.> and UNS telemetry.
- **NATS broker → eaxplc-rt** (command to equipment): API calls, UNS commands. On plc.\<id>.> and uns.command.>. Each request is checked like an HTTP request: the user's credential, the permission level, the e-signature, and the audit records the user.
- **eaxScada → NATS broker** (relation)
- **eaxScada → eaxplc-rt** (authentication): sign-in and e-signature authority. With --scada-url, users sign in with their eaxScada accounts and e-sign there; the runtime trusts eaxScada's token key, fetched once and pinned. With --standalone the runtime's own local users are the authority instead.
- **plc-server --attach ↔ NATS broker** (data or telemetry): every /api/ call, live values. Over plc.\<id>.api, with the browser's credential: the runtime signs in, checks and audits.
- **Engineer ↔ plc-server --attach** (data or telemetry): Studio
- **Field devices → eaxplc-rt** (data or telemetry): inputs
- **eaxplc-rt → Field devices** (command to equipment): outputs

Nothing listens on the edge device: every request reaches it through the broker, and is checked there like an HTTP request.

## 1. Register the PLC on the SCADA

Start eaxScada with the edge PLC ids (comma separated):

    eaxscada-<tier>.exe ... --edge-plcs edge-7,edge-8

On start eaxScada creates each PLC's broker identity,
`data\security\nkeys\<id>.nk`, and a built-in critical alarm
`ALM-PLC--FAULT` that turns on when that PLC stops on a fault (watchdog
or scan fault). With HA, provision the seeds once and give both nodes
`--edge-plc-seed-dir <dir>`.

Copy `<id>.nk` to the edge device (it is the device's credential: keep it
readable by the runtime's account only).

## 2. Run the runtime

    eaxplc-rt.exe --plc-id edge-7 --nats nats://<scada-host>:4222 --nats-nkey edge-7.nk ^
                  --scada-url http://<scada-host>:8080 --no-http --no-modbus --cpu eaxCPU-500

- `--nats-nkey`: the identity from step 1. The broker lets it use its own
  subjects only (`plc.edge-7.>`), publish UNS telemetry and receive UNS
  commands.
- `--scada-url`: users sign in with their eaxScada accounts, and deploys
  and watchdog changes are e-signed there. Forcing needs the `plc.force`
  right (Lead_Engineer, Administrator; never the AI co-pilot) and no
  e-signature; every force is audited. Writing a value once needs the
  `plc.write` right (Shift_Operator and above), see step 4. `--standalone` instead
  uses the runtime's own local users (`eaxplc-rt user add ...`).
- `--no-http`: nothing listens on the device; everything goes through the
  broker. Leave HTTP on (loopback by default) only if something local needs it.
- `--no-modbus`, or `-modbus-bind` to expose Modbus TCP (it has no
  authentication).

Every request over NATS is checked like an HTTP request: the user's
credential, the permission level, the e-signature, and the audit records the
user.

The runtime has no Windows service mode yet: run it at boot with Task
Scheduler ("At startup", "Run whether user is logged on or not") or a
service wrapper.

Soft real-time on Windows IoT Enterprise: see `rt\Enable-SoftRealTime.ps1`.

## 3. Program and monitor it

From any machine that reaches the broker:

    plc-server.exe --attach edge-7 --nats nats://<scada-host>:4222 ^
                   --nats-user <scada user> --nats-pass <password> -http 8086

then open http://127.0.0.1:8086. This runs the Web Studio only (no PLC):
sign in with your eaxScada account; online values, deploys, forces and the
flight recorder are the edge runtime's. `--nats-nkey <file>` can be used
instead of a user and password.

In eaxScada, the PLC flight recorder and PLC hardware views have a PLC
selector listing the local PLC and the edge PLCs.

## 4. Write a value once, or force it

The Studio's watch grid has two different actions on a value. Pick the
one you mean:

| | Write once | Force |
|---|---|---|
| What happens | The value lands once, at the next scan. The program may overwrite it on any later scan. | The value is held on every scan until someone unforces it, whatever the field or the program writes. |
| Who may do it | `plc.write` right: Shift_Operator, Process_Supervisor, Lead_Engineer, Administrator | `plc.force` right: Lead_Engineer, Administrator |
| Studio | **Write once** on a row, or **Write Recipe once** for every Recipe Preset | **Force**, **Change force**, **Unforce**, **Release Forces** |
| API | `POST /api/write` | `POST /api/force` |
| Audit | `IO_WRITE` / `WRITE`, `WRITE_DENIED`, `WRITE_REJECTED` | `IO_FORCE` / `FORCE`, `UNFORCE`, ... |

Neither action needs an e-signature. The AI co-pilot can do neither, even
when its account has an engineer role. The PLC refuses a caller without the
right (403) and records the refusal (`WRITE_DENIED`, `FORCE_DENIED`).

A write request carries one or more values and is applied all or none:

    POST /api/write
    {"writes": [{"address": "%MW10", "value": 1200},
                {"symbol": "Mixer_Speed", "value": 42.5},
                {"symbol": "Agitator_On", "value": true}],
     "reason": "recipe B", "source": "IDE"}

- A value is a direct address (`%QX0.1`, `%MW10`) or a variable of the
  running program (BOOL, integer, REAL, LREAL).
- The PLC checks every entry before it writes anything: the address must lie
  in the process image, the value must fit the type, the variable must
  exist, and no two entries may share a location. A request holds 1 to 256
  entries. If one entry fails, the PLC writes nothing and refuses the
  request with 400, naming the entry (`write N of M: ...`). A body that is
  not valid JSON, or not a write request, is also a 400.
- If a location is forced, the PLC refuses the whole request with 409 and
  names the force (who forced it, the value and since when). A write would
  not hold against a force, so the PLC does not accept it silently. Unforce
  first, or change the forced value.
- The ledger gets one `IO_WRITE` / `WRITE` record per value, all with the
  same request id. Each record holds the user and roles, the address and
  symbol, the live value before the write, the new value, the reason and the
  source (`HTTP` or `NATS`, plus the client's `source` tag).
- The ledger records refusals too:
  - 403 (no `plc.write` right) and 409 (forced location): one
    `WRITE_DENIED` record per requested value.
  - 400 (invalid request): one `WRITE_REJECTED` record per request, because
    nothing was written. The record holds the user and roles, the source,
    a request id, the failing entry and why it failed (`write N of M: ...`),
    and the address or symbol and value as the client sent them. For a body
    that does not parse, the record holds the parse error and the first 256
    bytes of the body, escaped. Long fields are truncated, so a record stays
    under 4 KB.

Over NATS, `plc.<id>.api` with path `/api/write` follows the same rules.
