Bridge

Bridge

new Bridge()

Source:


The base bridge class used to create a bridge.
The adapter directory should contain your adapters index.jse, commands directory, and responses directory. See Adapter for details.
Example:

const bridge = require('k4-base-bridge');
const path = require('path');
const K4 = require('k4');

const k4 = new K4({
    url: 'auto'
});

const opts = {
    k4: k4,
    id: 'networkId',
    transport: {
        name: 'udp',
        protocol: 'udp6',
        receiver: {
            port: 10000,
            protocol: 'udp6'
        }
    },
    adapter: {
        file: path.resolve('./adapter/index.jse'),
        sequencer: {
            max: 255,
            min: 0,
            start: 'random'
        }
    }
};

bridge.start(opts);

Members

adapter :Adapter

Source:

The adapter instance

Type:

classes :classesObj

Source:

Contains the base bridge classes

Type:

devices :Object

Source:

Contains the devices that the module found in K4Model

Type:
  • Object

k4 :Object

Source:

The K4Model instance

Type:
  • Object

Methods

(private) buildDevice(node)

Source:

Constructs device from K4Model device node

Parameters:
Name Type Description
node Object

K4Model device node

(private) createTransport() → {Promise}

Source:

Creates the specified transport

Returns:
Type
Promise

(private) execute(data, callback)

Source:

Handles execute commands from device node

Parameters:
Name Type Description
data Object

Data from execute command

callback function

The K4Model callback

(private) getDevice(id) → {Device}

Source:

Get a device by id

Parameters:
Name Type Description
id String

The device id

Returns:
Type
Device

(private) loadClasses()

Source:

Loads the base bridges classes

(private) ready() → {Promise}

Source:

Ready handler for K4Model

Returns:
Type
Promise

(private) reloadDevices() → {Promise}

Source:

Recreates devices list when K4Model ready event fires

Returns:
Type
Promise

(private) restoreDeviceModelVarsFromCache() → {Promise}

Source:

Restores last-known K4Model variable values for devices

Returns:
Type
Promise

(private) send(address, command) → {Promise}

Source:

Forwards command instances to the transport

Parameters:
Name Type Description
address String | Object

Address for the transport

command Command

The command to send

Returns:
Type
Promise

(async) start(opts) → {Promise}

Source:

Starts the bridge

Parameters:
Name Type Description
opts Object
Properties
Name Type Description
k4 Object

Instance of the K4Model

id String

The name of the device property that contains the id (ex: networkId, nodeId, etc)

transport Object

Transport configuration. See udp or see serial

adapter Object

Adapter configuration. See Adapter

Returns:
Type
Promise