BRIDGE_SUBSCRIPTION: Obtaining Real-Time Data

Updated: 2026-04-30

Let's look at a concrete example to understand how information flows between GPSS-Plus, middleware.js, and the OPC-UA server.

We are going to modify the behavior of a GENERATE block so that entities are created when a physical (simulated) sensor detects a door opening —instead of doing it by time or probability parameters.

Creating the Communication Bridge

The first step is to define the BRIDGER, which will be the link to the outside world:

Initial options,{user:"user", pass:"1234"}

BRIDGER {NAME:bridge1,X:333,Y:444
    ,SERVER:"wss://bridger.gpss-plus.com:3000"
    ,CLIENT:"opc.tcp://opcua.gpss-plus.com:4840"
    ,OPTIONS:V$options
    ,ON_ERROR:bridge1_on_error
    }

The main parameters are:

  • NAME: Internal identifier for the BRIDGER (e.g., bridge1).
  • SERVER: The secure WebSocket address where middleware.js is listening.
  • CLIENT: The address of the OPC-UA server (usually on the same network as the middleware).
  • OPTIONS: Additional parameters (such as username and password) required for the connection.
  • ON_ERROR: A trigger that will execute if a communication error occurs.

Subscribing to a Sensor

Once the bridge is defined, we must start the connection within the model's PRE_RUN and subscribe to the variable representing the door's state:

    BRIDGE_SUBSCRIPTION { NAME: bridge1
      , VARIABLE: "Sensor_Door_IsOpen"
    , TRIGGER: on_open 
    }

This instruction keeps a channel open with the sensor to receive automatic notifications every time its value changes.

The parameters are minimal:

  • NAME: The name of the BRIDGER that will manage the communication.
  • VARIABLE: The exact name of the variable published by the sensor.
  • TRIGGER: The procedure that will process each received update.

Subscriptions allow receiving data in real-time without the need to perform periodic polling (reads).

The Associated Procedure

Each time a new value is received, the specified trigger is executed.
The parameter P$(PARAM_A.VALUE) will contain the current value of the sensor (0 or 1 in this case). PARAM_B contains the calling entity's number and PARAM_C the timestamp.

procedure on_open
   move {name:Text1,TEXT:"DOOR P$(PARAM_A.VALUE)"}
     if (P$(PARAM_A.VALUE.EXIST) && P$(PARAM_A.VALUE)==1)
        NEW GEN1
     endif
   TERMINATE_VE
endprocedure

In this example, every time the sensor detects that the door opens (value = 1), the system creates a new GEN1 entity, simulating a person entering the system.

Example

SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
SYSTEM {TYPE:OPTIONS, REAL_TIME:1}

Facility {NAME:facility1,X:446,Y:514}

Graphic {Type:TEXT,Name:Text1,X:376,Y:358}
Graphic {Type:TEXT,Name:TextError,X:376,Y:330,Text:"On error...."}

Initial options,{user:"user", pass:"1234"}

BRIDGER {NAME:bridge1,X:375,Y:398
	,SERVER:"wss://bridger.gpss-plus.com:3000"
	,CLIENT:"opc.tcp://opcua.gpss-plus.com:4840"
    ,OPTIONS:V$options
    ,on_error:bridge1_on_error
    }


POSITION {NAME:POS1,X:264,Y:511}

POSITION {NAME:POS2,X:658,Y:509}


START 100

;*****************************************************

PROCEDURE PRE_RUN
    BRIDGE_SUBSCRIPTION { NAME: bridge1
	, VARIABLE: "Sensor_Door_IsOpen"
    , TRIGGER: on_open 
    }

	TERMINATE_VE
ENDPROCEDURE

;*****************************************************
GENERATE 0,0,0,0 {NAME:GEN1,X:141,Y:351}
    ADVANCE 5,0 {TO:POS1}
    ADVANCE 5,0 {TO:facility1}
    SEIZE facility1
    advance 10,10
    RELEASE facility1
    ADVANCE 10,0 {TO:POS2}
ENDGENERATE 1
;----------------------------------------------------------------------------
procedure on_open
        move {name:Text1,TEXT:"DOOR P$(PARAM_A.VALUE)"}
        if (P$(PARAM_A.VALUE.EXIST) && P$(PARAM_A.VALUE)==1)
    	NEW GEN1
    	endif
	TERMINATE_VE
endprocedure
;----------------------------------------------------------------------------
procedure bridge1_on_error
        move {name:TextError,TEXT:"P$PARAM_A"}
	TERMINATE_VE
endprocedure