DataHub

Programs

Write sandboxed JavaScript that derives telemetry and publish results.

Programs (/programs) run sandboxed JavaScript on the platform to transform, aggregate, or derive telemetry values.

What you'll do

  1. Write program code in the built-in editor
  2. Debug with sample telemetry before starting
  3. Start the program to publish derived values to NATS

Create a program

  1. Go to ProgramsAdd
  2. Write JavaScript in the built-in editor
  3. Configure input tags and output tags
  4. Save, then Debug or Start

Lifecycle

StateActionPermission
DraftEdit codeprograms.update
RunningProcessing telemetryprograms.start
StoppedIdleprograms.stop

Programs publish derived values back to NATS using the standard telemetry event contract.

Run schedule

On the program detail page, Run mode controls how the runtime starts and stops:

ModeBehavior
ManualStart and stop from the editor toolbar (programs.start / programs.stop)
ContinuousKeeps running until you stop it manually
ScheduledRuns on a cron expression for a fixed duration, then stops automatically

For Scheduled mode, set a cron pattern (for example 0 * * * * every hour) and a run duration (1 minute to 1 hour). While scheduled, manual Run / Stop on the toolbar is ignored — the scheduler owns start/stop.

The programs list shows a schedule badge (Manual / Continuous / Scheduled) per instance.

Declared outputs

Programs publish derived tags under programs/<programCode>/outputs/<name>. The editor Declared outputs panel lists outputs inferred from your script (via datahub.publish(...)).

These paths appear in:

  • Debug results before you start in production
  • Tag pickers when binding dashboards widgets or rules
  • The program outputs catalog API (GET /api/programs/outputs) for integrators

Use declared outputs for KPIs you want to chart or alarm on — they behave like any other tag path in UNS and dashboards.

Debug workflow

Before starting in production, use Debug on the program detail page:

  1. Click Debug — compiles the script and runs it against recent telemetry samples
  2. Review compile status (success or error message)
  3. Inspect outputs (derived tag values the program would publish)
  4. Read debug logs from datahub.log(...) calls in your script
  5. Fix errors, then Start when outputs look correct

The Logs panel also shows runtime log lines while a program is running.

Sandboxing

Programs run in an isolated sandbox with limited API access. They cannot access the filesystem, network (except publishing telemetry), or other programs.

Available helpers include reading input tag values and publishing outputs — see inline hints in the program editor.

Templates

Program templates (templates permission) provide reusable starting points. Apply a template when creating a new program.

Tips

  • Test with simulator tags before connecting to production PLCs
  • Keep programs focused — one derivation per program is easier to debug
  • Monitor program status and logs on the detail page
  • Only one active derivation per output tag — avoid conflicting programs