### 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 (
}}
/>
);
};
```
--------------------------------
### 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 (
);
};
```
--------------------------------
### 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 (
);
};
```
--------------------------------
### 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 (
{data?.map((item: any) => (
{item.oid}: {item.value}
))}
);
};
```
--------------------------------
### 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 (
);
};
```
--------------------------------
### 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