2.2.0 • Published 3 years ago

wiser-connector v2.2.0

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

wiser-connector

Samples data from a Wiser Tracker REST API and reports tag location updates and zone transitions.

Targets ES6+.

Table of Contents

Install

npm i -S wiser-connector

Usage

Same Process

// import
const { WiserConnector } = require('wiser-connector');

// create connector
const connector = new WiserConnector({
  hostname: '127.0.0.1',
  tagSampleRate: 500, // tag data will be checked every 0.5 seconds
  zoneSampleRate: 30000, // zone data will be checked every 30 seconds
  tagHeartbeat: 1000, // tag updates are reported at most once per second
  port: 3101
});

// start the connector
connector.start();

// listen for events
connector.on(WiserConnector.events.tagHeartbeat, message => {
  console.log(message);
});

// shutdown the connector
connector.shutdown();

Connector Options

NameTypeDefaultDescription
idStringWiserConnectorThe identifier to use for the connector.
hostnameString127.0.0.1The hostname to use to connect to the Wiser REST API.
portNumber3101The TCP port to use to connect to the Wiser REST API.
tlsEnabledBooleanfalseIf true, the connector will use https to connect to the Wiser REST API.
tagSampleRateNumber1000How often the connector should sample tag data (milliseconds).
zoneSampleRateNumber30000How often the connector should sample zone data (milliseconds).
tagHeartbeatNumber60000How often tag location changes are reported (milliseconds), independent of zone transitions.

NOTE: Zone transitions are ALWAYS reported no matter what the tagHeartbeat is set to.


Tag Report Properties

PropertyTypeDescription
idNumberThe unique id of the tag report.
errorNumberThe estimated error in location calculation.
locationObjectLocation coordinates {x: Number, y: Number, z: Number}.
tagNumberAn integer used to identify the tag. Usually printed on the tag in hex format.
timestampNumberUnix time in milliseconds.
batteryNumberThe current battery voltage of the tag. Anything below 2.8 is considered low.
zonesObject[]A list of zone IDs {id: number} that the tag is reported to be in.

The location property is an object that contains the x, y, and z coordinates for the tag position.

Example:

{x: 10.2, y: 256.9, z: 34.0}

The zones property is an array of objects that describe which zones the tag is currently in.

Example:

[{ id: 0 }, { id: 1 }, { id: 2 }];

Anchor Properties

PropertyTypeDescription
idIntegerAnchor ID
hardwareIdIntegerHardware ID
firmwareVersionStringFirmware version
xNumberX coordinate within the array
yNumberY coordinate within the array
zNumberZ coordinate within the array

Gateway Properties

PropertyTypeDescription
idIntegerGateway ID
ipv4StringNetwork IP address
portIntegerNetwork TCP port
xNumberX coordinate within the array
yNumberY coordinate within the array
zNumberZ coordinate within the array

Adapter Properties

PropertyTypeDescription
idIntegerAdapter ID
usbAnchorIntegerUSB attached anchor ID
downstreamAdapterIntegerDownstream adapter ID

Arena Properties

PropertyTypeDescription
panIdIntegerUnique ID
anchors[Anchor]List of anchors
gateways[Gateway]List of gateways
adapters[Adapter]List of adapters

Methods

start

Start the connector with Connector Options or, if not provided, use the options passed to the constructor.

const WiserConnector = require('wiser-connector');
const options = {
  hostname: '192.168.1.9',
  port: 3101,
  tagHeartbeat: 300000
};

const connector = new WiserConnector(options);
connector.start();

// OR

const connector = new WiserConnector();
connector.start(options);

shutdown

Shut down the connector.

connector.shutdown();

status (async)

Returns a Promise that resolves to an Arena object.

connector
  .status()
  .then(arena => {
    console.log(arena);
  })
  .catch(err => {
    console.log(err.message);
  });

// OR

try {
  const arena = await connector.status();
} catch (err) {
  console.log(err.message);
}

Events

Register for events using the values defined in WiserConnector.events or use the event names directly.

tagHeartbeat

Emitted when a tag updates and the time since the last heartbeat is greater than or equal to the configured tagHeartbeat value. See Tag Report Properties.

TIP: Setting tagHeartbeat to 0 will cause every tag update to be reported.

tagEnteredZone & tagExitedZone

Emitted when a tag enters or exits a zone. See event data object definition below.

PropertyTypeDescription
reportObjectThe tag report for the tag that transitioned zones.
zoneObjectContains the Wiser id and name of the zone where the transition occured.

Example

{
  report: {
    id: 0,
    tag: 31000,
    location: {x: 0, y: 0, z: 0},
    zones: [{id: 0, id: 1}],
    error: 0.0,
    anchors: 5,
    timestamp: 143456789,
    battery: 3.1
  },
  zone: {
    id: 0,
    name: 'Zone A'
  }
}

status

Emitted after a connector's status command is executed in a child process. The data contains the current hardware status information returned from the Wiser REST API /wiser/api/arena endpoint. See Arena Properties

You can also use async/await or then/catch since the status method is asynchronous to get the data without subscribing to the status event.

// .then/.catch
connector
  .status()
  .then(() => {
    // process arena data
  })
  .catch(err => {
    // handle error
  });

// async/await
try {
  const arena = await connector.status();
  // process arena data
} catch (err) {
  // handle error
}