Skip to main content

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}`
);
};
PropertyFieldTypeDescription
MeasurementMessagedataSourceIDataSourceConfigConfiguration of the data source.
dataIDataPointConfig[]Array of data point configurations.
IDataSourceConfigidstringUnique identifier of the data source.
dataPointsConfigsReadonlyArray\<IDataPointConfig>Array of data point configurations.
namestringName of the data source.
protocolDataSourceProtocolsProtocol used by the data source.
connection_stringstringConnection string for the data source.
racknumberRack number for the data source.
slotnumberSlot number for the data source.
asset_idstring (optional)Asset identifier (optional).
field_device_typestring (optional)Type of the field device (optional).
IDataPointConfigidstringUnique identifier of the data point.
namestringName of the data point.
unitstringUnit of measurement for the data point.
addressstringAddress of the data point.
read_frequencystringFrequency at which data is read.
variable_typestring (optional)Type of the variable (optional).
function_typestring (optional)Function type of the data point (optional).
edge_onlyboolean (optional)Flag to indicate if it's edge-only (optional).
disabledbooleanFlag 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

PropertyFieldTypeDescription
measurementidstringThe identifier for the measurement.
valuestringThe value of the measurement.
edgeEventidstringThe identifier for the edge event.
tsDateThe timestamp of the edge event.