0.0.5 • Published 6 years ago

automesh-client-node v0.0.5

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
6 years ago

automesh-client

Clients for sending authenticated requests to the Automesh REST API and interacting with the streaming API.

Install

npm i --save automesh-client

Usage

AutomeshClient

TBD.

AutomeshStreamingClient

Authentication

Use a developer API key to authenticate with the streaming server.

// Load dependencies.
const AutomeshStreamingClient = require('automesh-client').AutomeshStreamingClient;

// Instantiate the streaming client.
const streamingClient = new AutomeshStreamingClient();

// Listen for connection event.
streamingClient.on('connect', () =>
{
	// Log it.
	console.info(`Connected.`);
});

// Listen for disconnection event.
streamingClient.on('disconnect', (reason) =>
{
	// Log it.
	console.info(`Disconnected:`, reason);
});

// Authenticate using developer API key.
let authResponse = await streamingClient.authenticate({apiKey: "your-key", apiSecret: "your-secret"});

Input

Stream data point values to the server.

// Get the current time (UTC) in ISO 8601 format.
const now = "2018-01-02T03:04:05Z";

// ...or use moment to get the current time (UTC).
const moment = require('moment');
now = moment().utc().format();

// Generate some data point values.
const dataPointValues = [
	{
		dataPointID: "your-data-point-id-1",
		t: now,
		v: 1.11
	},
	{
		dataPointID: "your-data-point-id-2",
		t: now,
		v: 2.22
	},
];

// Send data point values into the data mesh.
let response = await streamingClient.appendValues(dataPointValues);

// Log the response.
console.info(`Response:`, response);

Output

Subscribe to streaming output channels for real-time data point values, or triggered events.

// Listen for channel messages.
streamingClient.on('channelMessage', (message) =>
{
	// Log it.
	console.info(`Received channel message:`, message);
});

// Leave any channels we are currently subscribed to.
await streamingClient.leaveAllChannels();

// Join channels for data points whose values we want to receive in real-time.
await streamingClient.joinChannels(['data-point-id-1', 'data-point-id-2']);

// Join channels for triggers whose events we want to receive in real-time.
await streamingClient.joinChannels(['trigger-id-1']);

// Leave specific channels we no longer care about.
await streamingClient.leaveChannels(['data-point-id-1']);

Build

npm i
npm run build

Test

npm test