### Initialize and Retrieve EVA ICS WebEngine Instance Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt Demonstrates how to initialize the EVA ICS WebEngine and set it globally for use across the application. It also shows how to retrieve the engine instance later. This must be done before using other components or hooks. ```typescript import { Eva } from "@eva-ics/webengine"; import { set_engine, get_engine } from "@eva-ics/webengine-react"; // Initialize the engine with EVA ICS server configuration const eva = new Eva();eva.api_uri = "http://localhost:7727";eva.set_login_password("admin", "secret"); // Set the engine globally for all components set_engine(eva); // Later, retrieve the engine instance anywhere in your app const engine = get_engine(); if (engine && engine.logged_in) { console.log("Connected to EVA ICS"); } ``` -------------------------------- ### HMIApp Wrapper for Authentication and Dashboard Rendering Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt Provides a complete HMI application wrapper that manages the login/logout flow, session, and OTP authentication. It renders a provided Dashboard component once the user is authenticated. Customization options for the login form are available. ```tsx import { Eva } from "@eva-ics/webengine"; import { HMIApp, set_engine, LoginFailedAction } from "@eva-ics/webengine-react"; const eva = new Eva();eva.api_uri = "http://localhost:7727"; set_engine(eva); // Your main dashboard component const Dashboard = ({ engine, logout }: { engine: Eva; logout: () => void }) => { return (

Welcome to HMI Dashboard

); }; // Complete HMI application with authentication const App = () => { return ( { console.error("Login failed:", err.message); return LoginFailedAction.Default; }, form_header: () =>
My Company
, form_footer: () =>
v1.0.0
}} /> ); }; ``` -------------------------------- ### Display Live Video Streams with EvaLivePlayer Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The EvaLivePlayer component displays live video streams from EVA ICS camera sources. It supports basic stream display, auto-sizing, and provides a reference to the player instance for control. Dependencies include @eva-ics/webengine-react and @eva-ics/webengine-multimedia. It takes an 'oid' for the camera source and can handle errors and stream end events. ```tsx import { EvaLivePlayer, EvaPlayerAutoSize } from "@eva-ics/webengine-react"; import { EvaLivePlayer as EvaLivePlayerC } from "@eva-ics/webengine-multimedia"; import { useState } from "react"; const CameraView = () => { const [player, setPlayer] = useState(null); return (
{/* Basic video stream */} console.error("Stream error:", err.message)} onEOS={() => console.log("Stream ended")} /> {/* Auto-sizing stream */} {/* Called on each frame */}} onChange={(info) => console.log("Stream info:", info)} /> {/* With player control reference */} { console.log("Canvas initialized:", canvas); }} /> {player && ( )}
); }; ``` -------------------------------- ### ProgressBar Component: Display Percentage-Based Progress Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The ProgressBar component visualizes data as a horizontal bar, representing a value as a percentage of a defined range. It supports basic display, warning and critical thresholds, formula-based value conversion, and custom styling via class names and formatting functions. Requires the @eva-ics/webengine-react library. ```tsx import { ProgressBar } from "@eva-ics/webengine-react"; const SystemStatus = () => { return (
{/* Basic progress bar */} {/* With warning thresholds */} {/* Tank level with formula */} {/* Custom styling */} `${value}% complete`} set_class_name_with={(value) => value === 100 ? "completed" : "in-progress" } />
); }; ``` -------------------------------- ### Execute Macros with ControlButtonRun Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The ControlButtonRun component is used to trigger EVA ICS logic macros. It can execute simple macros or those requiring parameters, and can optionally display a busy indicator linked to a system sensor. Callbacks for success and failure are supported. ```tsx import { ControlButtonRun } from "@eva-ics/webengine-react"; const AutomationControls = () => { return (
{/* Simple macro execution */} console.log("All lights turned off")} /> {/* Macro with parameters */} {/* With busy indicator (disables while running) */} alert(`Startup failed: ${err.message}`)} />
); }; ``` -------------------------------- ### Display Historical Data with LineChart and Chart Components Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt These components render historical data from specified Object Identifiers (OIDs) as interactive line or bar charts. They support various configurations including timeframes, update intervals, multiple OIDs, formula transformations, and custom styling options. Dependencies include the '@eva-ics/webengine-react' library. ```tsx import { Chart, LineChart, ChartKind } from "@eva-ics/webengine-react"; import { StateProp } from "@eva-ics/webengine"; const TemperatureChart = () => { return (
{/* Simple line chart */} {/* Multiple OIDs on one chart */} {/* Chart with formula transformation */} {/* Bar chart */} {/* With custom options */} ({ fill: idx === 0, yAxisID: idx === 0 ? "y" : "y1" })} data_callback={(data) => console.log("Chart data updated:", data)} />
); }; ``` -------------------------------- ### Fetch and Auto-Update Historical State Data with useEvaStateHistory (React) Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The `useEvaStateHistory` hook fetches historical state data for a specified object ID (oid) and automatically updates it at a defined interval. It supports configuring the timeframe, update frequency, property to fetch, data filling, and decimal precision. The hook returns an object containing `data` and `error` properties, where `data` includes timestamps and corresponding values. ```tsx import { useEvaStateHistory } from "@eva-ics/webengine-react"; import { StateProp } from "@eva-ics/webengine"; const TemperatureHistory = () => { // Fetch last 24 hours of data, update every 30 seconds const history = useEvaStateHistory({ oid: "sensor:env/temperature", timeframe: "24H", // Last 24 hours update: 30, // Update every 30 seconds prop: StateProp.Value, // Get value property fill: "1H", // Fill gaps with 1-hour intervals digits: 2 // Round to 2 decimal places }, []); if (history.error) { return
Error: {history.error.message}
; } if (!history.data) { return
Loading history...
; } // history.data.t = array of timestamps // history.data[0].value = array of values return (

Temperature History (24h)

    {history.data.t.map((timestamp: number, idx: number) => (
  • {new Date(timestamp * 1000).toLocaleString()}: {history.data[0].value[idx]}°C
  • ))}
); }; ``` -------------------------------- ### Toggle Binary Devices with ControlButtonToggle Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The ControlButtonToggle component provides a UI element for switching binary states (e.g., on/off) of EVA ICS units. It accepts an oid for the target unit and can optionally define success and failure callbacks for handling the toggle operation's outcome. ```tsx import { ControlButtonToggle } from "@eva-ics/webengine-react"; const LightControls = () => { return (
{ console.log("Light toggled successfully", result); }} on_fail={(err) => { console.error("Failed to toggle light:", err.message); }} />
); }; ``` -------------------------------- ### Make Periodic API Calls with useEvaAPICall (React) Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The `useEvaAPICall` hook facilitates making periodic API calls to the EVA ICS backend with automatic refresh capabilities. It allows specifying the API method, parameters, and the refresh interval. The hook returns an object containing `data` and `error` for handling responses and potential errors. This is useful for fetching system status or dynamic item data. ```tsx import { useEvaAPICall } from "@eva-ics/webengine-react"; const SystemInfo = () => { // Call "test" API method every 5 seconds const { data, error } = useEvaAPICall({ method: "test", params: {}, update: 5 // Refresh every 5 seconds }, []); if (error) { return
API Error: {error.message}
; } if (!data) { return
Loading system info...
; } return (

EVA ICS System Status

System: {data.system_name}

Version: {data.version}

Uptime: {Math.floor(data.uptime / 3600)} hours

); }; // Custom API call example const ItemList = () => { const { data } = useEvaAPICall({ method: "item.state", params: { i: "#" }, // Get all items update: 10 }, []); return ( ); }; ``` -------------------------------- ### Display Real-time Values with Gauge Component Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The Gauge component visualizes real-time data from a specified OID within a defined range, offering various visual styles like Standard, Modern, Minimal, Sphere, and Light. It allows customization of units, thresholds, and appearance. Dependencies include the '@eva-ics/webengine-react' library. ```tsx import { Gauge, GaugeType, GaugeStrokeLineCap } from "@eva-ics/webengine-react"; const GaugeDashboard = () => { return (
{/* Standard gauge */} {/* Modern style gauge */} {/* Minimal gauge */} {/* Sphere gauge */} {/* Light gauge with custom thresholds */} { if (value >= 40 && value <= 60) return "#00ff00"; return undefined; // Use default threshold colors }} />
); }; ``` -------------------------------- ### useEvaStateBulk Hook for Multiple Item State Subscriptions Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt A React hook that subscribes to the states of multiple EVA ICS items simultaneously. It returns an object mapping each OID to its corresponding state, allowing for efficient bulk data retrieval and display. ```typescript import { useEvaStateBulk } from "@eva-ics/webengine-react"; const MultiSensorDashboard = () => { const oids = [ "sensor:env/temperature", "sensor:env/humidity", "sensor:env/pressure" ]; // Subscribe to all sensors at once const states = useEvaStateBulk({ oid: oids }, [oids]); return (
{oids.map((oid) => { const state = states[oid]; return (

{oid.split("/")[1]}

{state?.value ?? "Loading..."} {state?.status === 1 ? "Online" : "Offline"}
); })}
); }; ``` -------------------------------- ### Manage Dynamic State Subscriptions with useEvaStateUpdates (React) Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The `useEvaStateUpdates` hook enables dynamic subscription management for EVA ICS states, adapting to the component's lifecycle. It allows specifying state update patterns, controlling whether to clear existing subscriptions, restore previous ones on unmount, and append to current subscriptions. The hook returns a `EvaSubscriptionState` enum to indicate the current status of the subscription process. ```tsx import { useEvaStateUpdates, EvaSubscriptionState } from "@eva-ics/webengine-react"; const DynamicSubscriptions = () => { // Subscribe to specific item patterns when component mounts const subscriptionState = useEvaStateUpdates({ state_updates: ["sensor:env/#", "unit:lights/#"], clear_existing: false, // Don't clear other subscriptions keep: true, // Restore previous subscriptions on unmount append: true // Add to existing subscriptions }, []); if (subscriptionState === EvaSubscriptionState.Working) { return
Setting up subscriptions...
; } if (subscriptionState === EvaSubscriptionState.Failed) { return
Failed to subscribe to states
; } return (

Subscription active - receiving real-time updates

{/* Your components using useEvaState will now receive updates */}
); }; ``` -------------------------------- ### useEvaState Hook for Real-time Item State Subscription Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt A React hook that subscribes to real-time state updates for a single EVA ICS item (e.g., sensor, unit). It automatically updates when the item's value changes and provides connection status and error information. ```typescript import { useEvaState } from "@eva-ics/webengine-react"; const SensorDisplay = ({ oid }: { oid: string }) => { // Subscribe to item state - updates automatically when value changes const state = useEvaState({ oid }, [oid]); // state.value - current value // state.status - 1 = ok, -1 = error // state.connected - WebSocket connection status // state.act - action pending count (for units) if (state.status === -1) { return
Sensor error
; } return (
Temperature: {state.value}°C Status: {state.status === 1 ? "OK" : "Unknown"} {!state.connected && Disconnected}
); }; // Usage ``` -------------------------------- ### Canvas Component: Create Interactive HMI Layouts Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The Canvas component enables the creation of sophisticated Human-Machine Interface (HMI) layouts on a background image. It allows positioning of data items (sensors, values) and interactive controls (buttons) with associated actions and callbacks for success and failure events. Requires @eva-ics/webengine-react and its ControlButtonKind enum. ```tsx import { Canvas, ControlButtonKind } from "@eva-ics/webengine-react"; const ProcessDiagram = () => { const items = [ { oid: "sensor:tank1/level", label: "Tank 1", units: "%", digits: 0, position: { x: 50, y: 100 }, css_class: "tank-label" }, { oid: "sensor:tank2/level", label: "Tank 2", units: "%", digits: 0, position: { x: 250, y: 100 } }, { oid: "sensor:pipe/flow", label: "Flow", units: " L/min", digits: 1, position: { x: 150, y: 200 }, threshold: [ { value: 100, class: "high-flow" }, { value: 50, class: "normal-flow" } ] } ]; const buttons = [ { oid: "unit:valve/inlet", label: "Inlet", kind: ControlButtonKind.Toggle, position: { x: 50, y: 250 } }, { oid: "unit:valve/outlet", label: "Outlet", kind: ControlButtonKind.Toggle, position: { x: 250, y: 250 } }, { oid: "unit:pump/main", label: "Pump Speed", kind: ControlButtonKind.Value, input_size: 4, position: { x: 150, y: 300 } }, { oid: "lmacro:process/start_filling", label: "Start Fill", params: { tank: 1 }, position: { x: 50, y: 350 } } ]; return ( console.log("Action completed:", result)} on_fail={(err) => alert(`Action failed: ${err.message}`)} /> ); }; ``` -------------------------------- ### Thermometer Component: Display Temperature and Liquid Levels Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The Thermometer component renders a vertical visualization suitable for temperature or liquid level readings. It supports basic display, warning thresholds, formula-based conversions, and custom formatting for labels and colors. Dependencies include the @eva-ics/webengine-react library. ```tsx import { Thermometer } from "@eva-ics/webengine-react"; const TemperatureMonitor = () => { return (
{/* Basic thermometer */} {/* With warning thresholds */} {/* With formula conversion (Fahrenheit) */} {/* Custom formatting */} `${value.toFixed(0)}% full`} set_color_with={(value) => value < 20 ? "red" : "blue"} />
); }; ``` -------------------------------- ### Render Item Values in a Table with ItemValueTable Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The ItemValueTable component displays a list of items, each with a unique identifier (oid), label, units, and formatting options like decimal precision, thresholds, and formulas. It's useful for presenting sensor data or other item values in a structured tabular format. ```tsx import { ItemValueTable } from "@eva-ics/webengine-react"; const EnvironmentDashboard = () => { const items = [ { oid: "sensor:env/temperature", label: "Temperature", units: "°C", digits: 1, threshold: [ { value: 35, class: "critical" }, { value: 28, class: "warning" } ] }, { oid: "sensor:env/humidity", label: "Humidity", units: "%", digits: 0 }, { oid: "sensor:env/pressure", label: "Pressure", units: " hPa", digits: 1, formula: "x / 100" // Convert Pa to hPa }, { oid: "sensor:env/co2", label: "CO2 Level", units: " ppm", digits: 0, set_color_with: (value) => value > 1000 ? "red" : "green" } ]; return (
); }; ``` -------------------------------- ### Display Item Values with Formatting using ItemValue Component (React) Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The `ItemValue` component from `@eva-ics/webengine-react` displays a single item's value with extensive customization options. It supports unit display, decimal formatting, applying CSS classes based on thresholds or custom logic, and custom formatting functions for both values and colors. This component simplifies the presentation of real-time data with rich visual feedback. ```tsx import { ItemValue } from "@eva-ics/webengine-react"; const SensorReadings = () => { return (
{/* Basic usage */} {/* With formula transformation */} {/* With color thresholds */} {/* With custom formatting */} value === 1 ? "Online" : "Offline"} set_color_with={(value) => value === 1 ? "green" : "red"} /> {/* With custom class name */} value > 1020 ? "high-pressure" : "low-pressure" } />
); }; ``` -------------------------------- ### Group Controls with ControlBlock Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The ControlBlock component serves as a container for organizing multiple control buttons, such as toggles, value inputs, or macro execution buttons. It displays a title for the group and provides callbacks for overall success or failure of actions within the block. ```tsx import { ControlBlock, ControlButtonKind } from "@eva-ics/webengine-react"; const EquipmentControls = () => { const buttons = [ { oid: "unit:pump/main", label: "Main Pump", kind: ControlButtonKind.Toggle }, { oid: "unit:valve/inlet", label: "Inlet Valve", kind: ControlButtonKind.Toggle }, { oid: "unit:motor/speed", label: "Motor Speed", kind: ControlButtonKind.Value, input_size: 4 }, { oid: "lmacro:process/emergency_stop", label: "EMERGENCY STOP", css_class: "emergency", params: { confirm: true } } ]; return ( console.log("Action completed:", result)} on_fail={(err) => console.error("Action failed:", err)} /> ); }; ``` -------------------------------- ### Export State History to CSV with generateStateHistoryCSV Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The generateStateHistoryCSV function, along with the useEvaStateHistory hook, allows for exporting historical state data to CSV format. This is useful for reporting and analysis. Dependencies include @eva-ics/webengine-react and @eva-ics/webengine. It requires historical data and a mapping configuration to define CSV columns and data properties. ```tsx import { useEvaStateHistory, generateStateHistoryCSV } from "@eva-ics/webengine-react"; import { StateProp } from "@eva-ics/webengine"; const DataExport = () => { const history = useEvaStateHistory({ oid: ["sensor:env/temperature", "sensor:env/humidity"], timeframe: "24H", update: 60, fill: "1H" }, []); const handleExport = () => { if (!history.data) return; const csv = generateStateHistoryCSV({ data: history.data, mapping: [ { oid: "sensor:env/temperature", name: "Temperature (°C)", prop: StateProp.Value }, { oid: "sensor:env/humidity", name: "Humidity (%)", prop: StateProp.Value } ], timeColName: "Timestamp", timeFormatter: (t) => new Date(t * 1000).toISOString() }); if (csv) { const blob = new Blob([csv], { type: "text/csv" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "sensor_data.csv"; a.click(); URL.revokeObjectURL(url); } }; return ( ); }; ``` -------------------------------- ### Display EVA ICS Errors with EvaErrorMessage Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The EvaErrorMessage component displays errors returned from EVA ICS API calls or custom error objects in a standardized format. It can be used with the useEvaAPICall hook or independently for manual error display. Dependencies include @eva-ics/webengine-react. It takes an 'error' object as input and can be styled using CSS classes. ```tsx import { EvaErrorMessage, useEvaAPICall } from "@eva-ics/webengine-react"; const DataDisplay = () => { const { data, error } = useEvaAPICall({ method: "item.state", params: { i: "sensor:nonexistent/item" }, update: 10 }, []); return (
{data &&
{JSON.stringify(data, null, 2)}
}
); }; // Manual error display const ManualError = () => { const customError = { code: -32001, message: "Item not found" }; return ( ); // Renders: "Error: Item not found (-32001)" }; ``` -------------------------------- ### Set Specific Values with ControlButtonValue Source: https://context7.com/eva-ics/eva-webengine-react/llms.txt The ControlButtonValue component is an input field designed to set specific numerical or string values on EVA ICS units. It requires an oid and allows configuration of input size and CSS classes, along with optional callbacks for success and failure. ```tsx import { ControlButtonValue } from "@eva-ics/webengine-react"; const ThermostatControl = () => { return (
{ console.log("Setpoint updated:", result); }} on_fail={(err) => { alert(`Failed to set temperature: ${err.message}`); }} />
); }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.