Subscribing Events
Subscribing to events allows your application to receive live updates about changes in data. These events may include measurement updates, file transfers, or other general updates.
It is important to note there are three distinct event types available for subscription:
- Measurement Event
- File Event
- Events (e.g. Edge Rules)
Measurement Events:
To handle incoming measurement data, use the subscribeMeasurements
method:
/**
* Subscribes to measurement events and processes the incoming data.
*
* @param {MeasurementMessage} message - Contains the data source configuration and the list of data points.
*/
VL.subscribeMeasurements = (message) => {
// Implement logic to process the message
console.log(
`Data Source Name: ${message.dataSource.name},
Data Point Name: ${message.data.name}`
);
};
Property | Field | Type | Description |
---|---|---|---|
MeasurementMessage | dataSource | IDataSourceConfig | Configuration of the data source. |
data | IDataPointConfig[] | Array of data point configurations. | |
IDataSourceConfig | id | string | Unique identifier of the data source. |
dataPointsConfigs | ReadonlyArray\<IDataPointConfig> | Array of data point configurations. | |
name | string | Name of the data source. | |
protocol | DataSourceProtocols | Protocol used by the data source. | |
connection_string | string | Connection string for the data source. | |
rack | number | Rack number for the data source. | |
slot | number | Slot number for the data source. | |
asset_id | string (optional) | Asset identifier (optional). | |
field_device_type | string (optional) | Type of the field device (optional). | |
IDataPointConfig | id | string | Unique identifier of the data point. |
name | string | Name of the data point. | |
unit | string | Unit of measurement for the data point. | |
address | string | Address of the data point. | |
read_frequency | string | Frequency at which data is read. | |
variable_type | string (optional) | Type of the variable (optional). | |
function_type | string (optional) | Function type of the data point (optional). | |
edge_only | boolean (optional) | Flag to indicate if it's edge-only (optional). | |
disabled | boolean | Flag to indicate if the data point is disabled. |
File Events:
To handle incoming file data, use the subscribeFile method:
/**
* This function subscribes to file events.
*
* @param {string} dataString - The file data as a string.
*/
VL.subscribeFile = (dataString) => {
// Do something with the data
};
General Events:
To handle incoming EdgeBusEvents, use the onEvent method:
/**
* This function subscribes to general events.
*
* @param {IEdgeBusEvent} events - The event message that this function will process.
*/
VL.onEvent = (events) => {
// Do something with the data
};
IDataSourceConfig object:
This object holds configuration details about a data source.
IEdgeBusEvent
IEdgeBusEvent Structure
Property | Field | Type | Description |
---|---|---|---|
measurement | id | string | The identifier for the measurement. |
value | string | The value of the measurement. | |
edgeEvent | id | string | The identifier for the edge event. |
ts | Date | The timestamp of the edge event. |