Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OpcuaSensorThingsController

Creates and manages Sensor and Thing objects for monitored OPC UA items.

Acts as a sensor source for OPC UA items (e.g. analog data items), i.e. advertises sensor objects, makes them discoverable, and publishes observations for its sensors associated with OPC UA items.

Mappings from OPC UA data sources to sensor object ids are configured on a controller option named opcuaSensorOptions which must implement the opcuaSensorOptions interface.

The sensor used for mapping OPC UA data sources can be defined either programmatically by calling registerSensor method or by specifying them in the controller's sensors option (see documentation of base class SensorSourceController). In both cases, specify a sensor's io interface to be of type OpcuaSensorIo and specify the observationPublicationType property either as

  • "none": an observation is published on a Channel event synchronously with each received OPC UA data value (default),
  • "advertise": an observation is published on an Advertise event at regular intervals specified by samplingInterval, or
  • "channel": an observation is published on a Channel event at regular intervals specified by samplingInterval.

Thing objects for the registered sensors can be registered either programmatically by calling registerThing method or by specifying them in the controller's things option as an array of Thing objects. Registered Thing objects are advertised (unless ignoreThingAdvertise option is set) and made discoverable (unless skipThingDiscoverEvents option is set) either by their Thing object type or by their Thing object type and their external ID.

By default, monitored OPC UA data values are passed unchanged as observation results. You can implement a specific data value coercion by defining a coerceValue function in the associated OpcuaDataSource.

remarks

This controller only runs in a Node.js runtime, not in a browser.

Hierarchy

  • SensorSourceController
    • OpcuaSensorThingsController

Implements

  • IController

Index

Constructors

constructor

  • new OpcuaSensorThingsController(_container: Container, _options: ControllerOptions, _controllerName: string): OpcuaSensorThingsController
  • internal

    For internal use in framework only.

    Never instantiate Controller objects in your application; they are created automatically by dependency injection.

    Parameters

    • _container: Container
    • _options: ControllerOptions
    • _controllerName: string

    Returns OpcuaSensorThingsController

Accessors

communicationManager

  • get communicationManager(): CommunicationManager

container

  • get container(): Container
  • Gets the container object of this controller.

    Returns Container

options

  • get options(): Readonly<ControllerOptions>
  • Gets the controller's options as specified in the configuration options.

    Returns Readonly<ControllerOptions>

registeredName

  • get registeredName(): string
  • Gets the registered name of this controller.

    The registered name is either defined by the corresponding key in the Components.controllers object in the container configuration, or by invoking Container.registerController method with this name.

    Returns string

registeredSensorContainers

  • get registeredSensorContainers(): SensorContainer[]

registeredSensors

  • get registeredSensors(): Sensor[]

runtime

  • get runtime(): Runtime
  • Gets the container's Runtime object.

    Returns Runtime

Methods

Protected createObservation

  • createObservation(container: SensorContainer, value: any, resultQuality?: string[], validTime?: TimeInterval, parameters?: {}): Observation
  • Overwrite this method to define how Observation object should be created.

    Do not call this method in your application code, it is called by this controller internally.

    Parameters

    • container: SensorContainer

      Sensor container creating this observation

    • value: any

      value of the observation

    • Optional resultQuality: string[]

      the quality of the result

    • Optional validTime: TimeInterval

      the validity time of the observation (optional)

    • Optional parameters: {}

      extra parameters for the observation (optional)

      • [key: string]: any

    Returns Observation

Protected extendLogObject

  • extendLogObject(log: Log): void
  • Whenever one of the controller's log methods (e.g. logDebug, logInfo, logWarning, logError, logFatal) is called by application code, the controller creates a Log object with appropriate property values and passes it to this method before advertising it.

    You can override this method to additionally set certain properties (such as LogHost.hostname or Log.logLabels). Ensure that super.extendLogObject is called in your override. The base method does nothing.

    Parameters

    • log: Log

      log object to be extended before being advertised

    Returns void

findSensor

  • findSensor(predicate: (sensor: Sensor) => boolean): Sensor
  • Returns the first registered sensor where the given predicate is true, undefined otherwise.

    Parameters

    • predicate: (sensor: Sensor) => boolean

      findSensor calls predicate once in arbitrary order for each registered sensor, until it finds one where predicate returns true. If such a sensor is found, that sensor is returned immediately. Otherwise, undefined is returned

        • (sensor: Sensor): boolean
        • Parameters

          • sensor: Sensor

          Returns boolean

    Returns Sensor

    the first sensor matching the predicate; otherwise undefined

Protected getChannelId

  • getChannelId(container: SensorContainer): string
  • Returns the channelId associated with a sensor container.

    By default, it is the objectId of the Sensor. Subclasses can override this method to provide their own logic.

    Parameters

    • container: SensorContainer

    Returns string

getSensor

  • getSensor(sensorId: Uuid): Sensor
  • Returns the Sensor associated with the given Sensor objectId.

    If no such sensor exists then undefined is returned.

    Parameters

    • sensorId: Uuid

    Returns Sensor

getSensorContainer

  • getSensorContainer(sensorId: Uuid): SensorContainer
  • Returns the sensor container associated with the given Sensor objectId.

    If no such container exists then undefined is returned.

    Parameters

    • sensorId: Uuid

    Returns SensorContainer

getSensorIo

  • getSensorIo(sensorId: Uuid): SensorIo
  • Returns the sensor IO interface associated with the given Sensor objectId. If no such sensor IO exists then undefined is returned.

    Parameters

    • sensorId: Uuid

    Returns SensorIo

getSensorValueObservable

  • getSensorValueObservable(sensorId: Uuid): Observable<any>
  • Returns an observable that emits values read from the sensor.

    Only the values read with publishChanneledObservation or publishAdvertisedObservation will emit new values. Reading the sensor value manually with SensorIo.read will not emit any new value.

    The observable is created lazily and cached. Once the Sensor associated with the observable is unregistered, all subscriptions to the observable are also unsubscribed.

    If the Sensor is not registered, this method will throw an error.

    Parameters

    • sensorId: Uuid

    Returns Observable<any>

isRegistered

  • isRegistered(sensorId: Uuid): boolean
  • Determines whether a Sensor with the given objectId is registered with this controller.

    Parameters

    • sensorId: Uuid

    Returns boolean

logDebug

  • logDebug(message: string, ...tags: string[]): void
  • Advertise a Log object for debugging purposes.

    Parameters

    • message: string

      a debug message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logError

  • logError(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for an error.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logErrorWithStacktrace

  • logErrorWithStacktrace(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for an error with stacktrace information.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logFatal

  • logFatal(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for a fatal error.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logInfo

  • logInfo(message: string, ...tags: string[]): void
  • Advertise an informational Log object.

    Parameters

    • message: string

      an informational message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logWarning

  • logWarning(message: string, ...tags: string[]): void
  • Advertise a Log object for a warning.

    Parameters

    • message: string

      a warning message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

onCommunicationManagerStarting

  • onCommunicationManagerStarting(): void

onCommunicationManagerStopping

  • onCommunicationManagerStopping(): void

onDispose

  • onDispose(): void

onInit

  • onInit(): void

Protected onObservationDidPublish

  • onObservationDidPublish(container: SensorContainer, observation: Observation): void
  • Lifecycle method called immediately after an observation is published for a specific Sensor. Default implementation does nothing.

    Parameters

    • container: SensorContainer
    • observation: Observation

    Returns void

Protected onObservationWillPublish

  • onObservationWillPublish(container: SensorContainer, observation: Observation): void
  • Lifecycle method called just before an observation is published for a specific Sensor.

    Default implementation does nothing.

    Parameters

    • container: SensorContainer
    • observation: Observation

    Returns void

publishAdvertisedObservation

  • publishAdvertisedObservation(sensorId: Uuid, resultQuality?: string[], validTime?: TimeInterval, parameters?: {}, featureOfInterestId?: Uuid): void
  • Publishes an observation for a registered Sensor.

    If no such registered Sensor exists then an error is thrown. The publication is performed in the form of an advertise event.

    The observation value is read directly from the IO handler of the Sensor. The observation time is recorded as this method is called. Subclasses can change the final value of the observation object by overriding the createObservation method.

    Parameters

    • sensorId: Uuid

      ObjectId of the Sensor to publish the observation.

    • Optional resultQuality: string[]

      The quality of the result. (optional)

    • Optional validTime: TimeInterval

      The validity time of the observation. (optional)

    • Optional parameters: {}

      Extra parameters for the observation. (optional)

      • [key: string]: any
    • Optional featureOfInterestId: Uuid

      UUID of associated feature of interest. (optional)

    Returns void

publishChanneledObservation

  • publishChanneledObservation(sensorId: Uuid, resultQuality?: string[], validTime?: TimeInterval, parameters?: {}, featureOfInterestId?: Uuid): void
  • Publishes an observation for a registered Sensor.

    If no such registered Sensor exists then an error is thrown. The publication is performed in the form of a channel event. By default the channelId is the sensorId. However, subclasses can change it by overriding getChannelId method.

    The observation value is read directly from the IO handler of the Sensor. The observation time is recorded as this method is called. Subclasses can change the final value of the observation object by overriding the createObservation method.

    Parameters

    • sensorId: Uuid

      ObjectId of the Sensor to publish the observation.

    • Optional resultQuality: string[]

      The quality of the result. (optional)

    • Optional validTime: TimeInterval

      The validity time of the observation. (optional)

    • Optional parameters: {}

      Extra parameters for the observation. (optional)

      • [key: string]: any
    • Optional featureOfInterestId: Uuid

      UUID of associated feature of interest. (optional)

    Returns void

registerSensor

  • registerSensor(sensor: Sensor, io: SensorIo, observationPublicationType?: ObservationPublicationType, samplingInterval?: number): void
  • Register a Sensor to this controller.

    You can call this function at runtime or register sensors automatically at the beginning by passing them in the controller options under 'sensors' objects (see documentation of base class SensorSourceController). In both cases, specify a sensor's io interface to be of type OpcuaSensorIo and specify the observationPublicationType property either as

    • "none": an observation is published on a Channel event synchronously with each received OPC UA data value (default),
    • "advertise": an observation is published on an Advertise event at regular intervals specified by samplingInterval, or
    • "channel": an observation is published on a Channel event at regular intervals specified by samplingInterval.

    Parameters

    • sensor: Sensor

      a Sensor object

    • io: SensorIo

      the sensor's io interface

    • Default value observationPublicationType: ObservationPublicationType = "none"

      how to publish sensor observations, one of "none", "advertise", "channel" (optional)

    • Optional samplingInterval: number

      regular publication interval in milliseconds (optional)

    Returns void

registerThing

  • registerThing(thing: Thing): void
  • Registers a Thing to this controller.

    You can call this function at runtime or register things automatically at the beginning by passing them in the controller options under 'things' as an array of Thing objects.

    If a Thing with the given objectId already exists, this method is simply ignored.

    Whenever a thing is registered, it is advertised to notify other listeners (unless ignoreThingAdvertise option is set). The controller class also starts to listen on Discover events for Things (unless skipThingDiscoverEvents option is set). Registered things are discoverable either by their Thing object type or by their Thing object type and their external ID.

    Parameters

    • thing: Thing

      Thing to register to the controller.

    Returns void

Protected traceOpcuaError

  • traceOpcuaError(error: any): void
  • Overwrite this method to define how internal OPC UA errors within this controller should be traced.

    By default, OPC UA errors are logged on the console.

    Do not call this method in your application code, it is called by this controller internally.

    Parameters

    • error: any

      an OPC UA error

    Returns void

unregisterSensor

  • unregisterSensor(sensorId: Uuid): Error
  • Unregisters a previously registered Sensor.

    If no such Sensor is registered, then an error is thrown.

    This also sends a disadvertise event to notify the listeners (unless ignoreSensorDeadvertise option is set). The query and discover events for this Sensor are ignored from this point on.

    If a value observable for the Sensor exists, then all subscriptions to that observable are unsubscribed.

    Parameters

    • sensorId: Uuid

    Returns Error

Generated using TypeDoc