Skip to content

Examples

See what you can build.

Real examples, each a few steps. Find the one closest to your plant, see what you do and what you get, and follow the guide when you are ready.

Connect equipment

Watch a pump station.

A controller with an OPC UA server runs the pumps and tanks. You want its values on an operator screen, and an alarm on a tank level.

What you do

  1. Add the controller under Connections as an OPC UA server, with its address, and test the connection.

  2. Browse its data blocks and create a tag from each variable you need. Every tag follows its variable live.

  3. Draw an operator screen in the browser, or start from the example plant, and bind the widgets to your tags.

  4. Add an alarm to a level tag, with a severity and a setpoint.

What you get

Live values with quality and timestamps, an operator screen and an alarm list. The OPC UA driver has read one real Siemens S7-1500 this way. Other controllers have not been tried.

Read the guide The OPC UA driver

An operator screen of the example water-treatment plant: a process diagram with tanks, pumps and valves, a trend and live values.An operator screen of the example water-treatment plant: a process diagram with tanks, pumps and valves, a trend and live values.
An operator screen of the example water-treatment plant.

Alarms

Know when something goes wrong.

You want to see what needs attention, acknowledge it, and be told elsewhere, in a chat or a paging service, when a serious alarm goes active.

What you do

  1. Add an alarm to a tag: a condition, a setpoint, a deadband and a severity.

  2. Watch it go active in the alarm list and acknowledge it. Every change is kept in the history.

  3. Under Alarms, Pipelines, add a pipeline that sends when an alarm goes active, at or above a severity, after a wait.

  4. Give it your webhook address and send a test message.

What you get

An alarm list with severity, acknowledgement and history, and a message posted to your webhook when an alarm goes active and is still active after the wait. Every send is logged.

Read the guide

The Scadex active alarms page, showing three alarms for a pump station with severity, source, value and acknowledge actions.The Scadex active alarms page, showing three alarms for a pump station with severity, source, value and acknowledge actions.
The active alarm list: severity, source, value and acknowledge.
The Scadex notification pipelines page: a pipeline that sends a webhook when an alarm goes active, its settings beside the list, and the log of recent sends.The Scadex notification pipelines page: a pipeline that sends a webhook when an alarm goes active, its settings beside the list, and the log of recent sends.
A pipeline that calls a webhook when an alarm goes active.

Telegraf

Bring in a plant PC with Telegraf.

A PC on the plant floor already runs Telegraf, or you want it to. Its measurements should be tags, with alarms, screens and history like any other.

What you do

  1. Make an API key with the operator role, under Gateway, Security, API keys.

  2. Add the agent as a Telegraf connection. The dashboard shows the configuration to copy, with the gateway's address already in it.

  3. Paste it into the agent's configuration with the key, and restart Telegraf. Nothing is installed on the agent.

  4. Browse the measurements it sends, tick the ones you want and create the tags.

What you get

Host metrics, and in principle anything else Telegraf reads, as tags with live values, alarms, screens and history. Only host memory and a command input have been tried so far, with Telegraf 1.34.

Read the guide The Telegraf driver

The Browse tab of a Telegraf connection named Plant PC, listing the measurements the agent sends, such as cpu, disk, mem and net.The Browse tab of a Telegraf connection named Plant PC, listing the measurements the agent sends, such as cpu, disk, mem and net.
The connection lists the measurements the agent sends.
TOML · telegraf.conf
[[outputs.influxdb_v2]]
  urls = ["https://<your gateway>/api/v1/modules/io.scadex.driver.telegraf/ingest/<connection id>"]
  token = "<an API key with the operator role>"
  organization = "scadex"
  bucket = "scadex"

InfluxDB

Keep history in InfluxDB.

You run InfluxDB already, or want the plant's values there for other tools.

What you do

  1. Under Connections, Databases, add an InfluxDB connection with its host, organization, bucket and token, and test it.

  2. Under Automation, Event streams, add a stream that sends to that connection.

  3. Choose the tags, for example every tag under Plant.*, and how often to send: after a number of seconds or of changes.

  4. Send a test batch, then check the recent batches.

What you get

Every change of the chosen tags written to your bucket as one point, with the tag's path and quality. When InfluxDB is down the batches are kept and sent again every 10 seconds, in memory, so a gateway restart loses what is waiting. The same stream can write into a Telegraf listener, so Telegraf can pass the values on to its own outputs. Tried with InfluxDB 2.7 and Telegraf 1.34 only.

Read the guide Event streams reference

The Scadex event streams page: a stream named Plant history to InfluxDB with its settings, and the list of recent batches, all sent.The Scadex event streams page: a stream named Plant history to InfluxDB with its settings, and the list of recent batches, all sent.
An event stream that writes to InfluxDB, and its recent batches.
Line protocol · one written point
scadex,path=[default]Plant.Pump1.Flow,quality=Good value=42.7 1794488466123456700

Scheduling

Run a task every morning.

A counter should be reset, or a value written, at the start of every shift, without a change in the PLC.

What you do

  1. Under Automation, Scripts, create a new job.

  2. Set the schedule: every day at 06:00, in the plant's time zone. As a cron expression that is 0 6 * * *.

  3. Write the script: read a tag, write a tag, log what you did.

  4. Try it without writing, run it by hand once, and name a failure tag so a failed run can raise an alarm.

What you get

A job that runs on time, with every run recorded: when it ran, how long it took, what it logged and what it wrote. If the gateway is down at 06:00 the run is recorded as missed, and with catch-up on it runs once afterwards.

Read the guide

The Scadex Scripts page: two scheduled jobs, one that resets the shift counters every day at 06:00, with their last runs.The Scadex Scripts page: two scheduled jobs, one that resets the shift counters every day at 06:00, with their last runs.
A scheduled job and the record of its runs.
TypeScript · the job's script
const before = tag('Line1.Counter');
writeTag('Line1.Counter', 0);
console.log(`Counter was ${before} at reset`);
return before;

Open interfaces

Open your data to your own tools.

Your own code, a report or another system needs the same live values the operators see, and sometimes needs to write one.

What you do

  1. Make an API key under Gateway, Security, API keys: a viewer key reads, an operator key can also write.

  2. Read a tag's current value over REST with the key, as in the first snippet.

  3. Or open Gateway, MQTT broker, turn it on, make a login and turn on publishing: every tag becomes a topic.

  4. Subscribe from any MQTT client, as in the second snippet.

What you get

The same values, qualities and timestamps in your own tools. REST can write as well, with an operator key. The broker has been tested with Mosquitto's tools, and until the compose file says otherwise it is reachable from the gateway machine only.

Read the REST guide Read the MQTT broker guide The MQTT driver

Shell · read a tag over REST
curl -H "Authorization: Bearer <api key>" \
  https://<your gateway>/api/v1/runtime/tags/Plant.Line1.Setpoint/current
Shell · subscribe over MQTT
mosquitto_sub -h <gateway host> -p 1883 -u <login> -P <password> \
  -t 'scadex/default/Plant/Line1/#'

React SDK

Build your own screen in React.

You want a screen that is yours, with your layout and your words, fed by the plant's live values. The SDK gives a React app live values, alarms and writes through hooks, and people sign in with the gateway's own accounts.

What you do

  1. Add the SDK to your project as a package. It is not on npm yet, and the guide shows how.

  2. Serve your page on the gateway's address, with /api and /sync passed on to the gateway.

  3. Connect and sign in, then show a value and write a setpoint.

  4. Show many values and the alarms, as in the five steps below.

What you get

A page of your own that runs on its own host or inside your own tools, signs in with the gateway's accounts, and shows live values with their quality, a setpoint you can write, and alarms with Acknowledge. The gateway decides who may write. The SDK is for React 18, and one operator page runs on it today.

Read the guide SDK reference The live socket

A small React page built from these examples: tank level 84, a level setpoint field showing 60, a table of three live values and two active alarms with Acknowledge buttons.A small React page built from these examples: tank level 84, a level setpoint field showing 60, a table of three live values and two active alarms with Acknowledge buttons.
The page the code below makes, running against a gateway.

The code, in five steps

  1. Connect

    Make a client for the gateway's own address, show a sign-in form until the person is signed in, then hand the client to the provider.

    React (TSX) · main.tsx
    import { createRoot } from "react-dom/client";
    import { createAuthClient, ScadexClient } from "@scadex.io/sdk";
    import { ScadexProvider, useAuth } from "@scadex.io/sdk/react";
    import { Plant } from "./Plant";
    import { SignIn } from "./SignIn";
    
    // The page and the gateway share an origin, so the sign-in cookie is all the SDK needs.
    const origin = window.location.origin;
    const auth = createAuthClient(origin);
    const client = new ScadexClient(origin);
    
    function App() {
      const { isAuthenticated, isLoading } = useAuth(auth);
      if (isLoading) return null;
      return isAuthenticated
        ? <ScadexProvider client={client}><Plant /></ScadexProvider>
        : <SignIn auth={auth} />;
    }
    
    createRoot(document.getElementById("root")!).render(<App />);
    React (TSX) · SignIn.tsx
    import { useState, type FormEvent } from "react";
    import type { createAuthClient } from "@scadex.io/sdk";
    
    export function SignIn({ auth }: { auth: ReturnType<typeof createAuthClient> }) {
      const [error, setError] = useState<string | null>(null);
    
      async function submit(event: FormEvent<HTMLFormElement>) {
        event.preventDefault();
        const form = new FormData(event.currentTarget);
        const { error } = await auth.signIn.email({
          email: String(form.get("email")),
          password: String(form.get("password")),
        });
        if (error) setError("The sign-in did not work. Check the name and the password.");
        else window.location.reload();
      }
    
      return (
        <form onSubmit={submit}>
          <label>Sign-in name <input name="email" autoComplete="username" required /></label>
          <label>Password <input name="password" type="password" autoComplete="current-password" required /></label>
          <button>Sign in</button>
          {error && <p role="alert">{error}</p>}
        </form>
      );
    }
  2. Show a value

    One hook gives a tag's value, its unit, its quality and whether it is replayed from the past, so the page can say when not to trust a number.

    React (TSX) · LevelCard.tsx
    import { useTag } from "@scadex.io/sdk/react";
    
    export function LevelCard() {
      const level = useTag<number>("Plant.Tank1.Level");
      if (level.loading) return <p>Waiting for the gateway</p>;
    
      return (
        <section aria-label="Tank 1 level">
          <h2>{level.formattedValue ?? `${level.value} ${level.unit ?? ""}`}</h2>
          {!level.good && <p role="status">Do not trust this value: {level.qualityDetail ?? level.quality}</p>}
          {level.replayed && <p>This is the past, replayed. It is not the plant now.</p>}
        </section>
      );
    }
  3. Write a setpoint

    The same hook writes. It says while the write is pending, and it refuses with a reason when a role may not write or a limit is hit.

    React (TSX) · Setpoint.tsx
    import { useState } from "react";
    import { useTag } from "@scadex.io/sdk/react";
    
    export function Setpoint() {
      const setpoint = useTag<number>("Plant.Tank1.LevelSetpoint");
      const [refused, setRefused] = useState<string | null>(null);
    
      async function change(value: number) {
        setRefused(null);
        try {
          await setpoint.write(value);          // resolves when the gateway has accepted the write
        } catch (error) {
          setRefused(String(error));            // a role that may not write, a limit, or no answer
        }
      }
    
      return (
        <label>
          Level setpoint {setpoint.pending && <small>saving</small>}
          <input
            type="number"
            key={setpoint.value}
            defaultValue={setpoint.value}
            onBlur={event => void change(Number(event.target.value))}
          />
          {refused && <span role="alert">{refused}</span>}
        </label>
      );
    }
  4. Show many values

    Subscribe to a list of paths and draw them as a table, with the state of the connection and whether the page is replaying.

    React (TSX) · Overview.tsx
    import { useClient, useReplaySelector, useTagValues } from "@scadex.io/sdk/react";
    
    const PATHS = ["Plant.Tank1.Level", "Plant.Tank1.Temperature", "Plant.Pump1.Running"];
    
    export function Overview() {
      const values = useTagValues(PATHS);                       // one subscription each, the latest frame per path
      const { connectionState } = useClient();                 // connecting, connected, disconnected or error
      const replaying = useReplaySelector(state => state !== null);
    
      return (
        <table>
          <caption>
            Tank 1 {connectionState !== "connected" && `(${connectionState})`} {replaying && "(replay)"}
          </caption>
          <tbody>
            {PATHS.map(path => {
              const frame = values[path];
              return (
                <tr key={path}>
                  <th scope="row">{path}</th>
                  <td>{frame ? frame.formattedValue ?? String(frame.value) : "waiting"}</td>
                  <td>{frame && frame.quality !== "Good" ? frame.quality : ""}</td>
                </tr>
              );
            })}
          </tbody>
        </table>
      );
    }
  5. Show alarms

    The active alarms, how many there are, and Acknowledge, which the gateway records against the signed-in person. Then put the pieces on one page.

    React (TSX) · Alarms.tsx
    import { useAlarms } from "@scadex.io/sdk/react";
    
    export function Alarms() {
      const { alarms, loaded, activeCount, acknowledge } = useAlarms();
      if (!loaded) return <p>Reading the alarms</p>;
      if (alarms.length === 0) return <p>No alarms are active.</p>;
    
      return (
        <>
          <h2>{activeCount} active</h2>
          <ul>
            {alarms.map(alarm => (
              <li key={alarm.id}>
                <strong>{alarm.name}</strong> on {alarm.tagPath}, value {alarm.value}
                {alarm.acknowledgedAt
                  ? <span> acknowledged by {alarm.acknowledgedByName}</span>
                  : <button onClick={() => void acknowledge(alarm)}>Acknowledge</button>}
              </li>
            ))}
          </ul>
        </>
      );
    }
    React (TSX) · Plant.tsx
    import { Alarms } from "./Alarms";
    import { LevelCard } from "./LevelCard";
    import { Overview } from "./Overview";
    import { Setpoint } from "./Setpoint";
    
    export function Plant() {
      return (
        <main>
          <LevelCard />
          <Setpoint />
          <Overview />
          <Alarms />
        </main>
      );
    }

Not seeing yours?

Tell us what you run and what you want to connect, and we will tell you how it would work.