0.0.2 • Published 5 years ago

@avimesa/examples-group-api-amqp v0.0.2

Weekly downloads
10
License
SEE LICENSE IN LI...
Repository
github
Last release
5 years ago

Avimesa Group API Examples, Node.js and AMQP

Group API examples using Node.js abd AMQP (0-9-1)

Introduction

This project contains simple example of how to interface with the Avimesa Device Cloud's Group API using Node.js and AMQP. Common tasks are captured in a simple example application to illustrate how one could go about interfacing withe system.

Table of Contents

1. Overview

Top

2. Prerequisites

  • Node.js
  • A valid Avimesa Device Cloud Group ID and Authentication Key

Top

3. Usage

Checkout and initialize the project:

git clone https://github.com/Avimesa/examples-nodejs-group-api-amqp.git
cd examples-nodejs-group-api-amqp
npm init

Update the credentials in the .env file in the root of the project:

# RMQ Server Hostname
RMQ_HOSTNAME=rmqserv001.avimesa.com

# RMQ Server Port
RMQ_PORT=5672

# RMQ Group ID / Vhost
RMQ_GROUP_ID= *<TODO>*

# RMQ Authentication Key
RMQ_AUTH_KEY= *<TODO>*

# Set this to 0 to allow certless TLS
NODE_TLS_REJECT_UNAUTHORIZED=0

Run the example from its directory, for example to run the queue-subscriber example, do ths following from the root of the project:

node queue-subscriber/index.js

Top

4. Examples

actuate-device

Summary:

Device actuation occurs by sending a command to the Device. Because the device may be offline, a queue for the Device is available to cache the message. The Device's queue is automatically configured by the Avimesa Device Cloud upon addition of the Device to the Group.

To actuate a device, we send a JSON command to the actuation.dx exchange, and use a routing key that is the Device's ID (lower case, string based UUID, no hyphens).

This is all done for you by the actuate API, where you just pass in a Device ID and a JSON message.

Top

add-device

Summary:

This example shows how to add a Device to the Device Cloud. The Device ID must be a 32 character string using a-f or 0-9 (i.e. base16 values for a UUID...). It also must be unique in the Avimesa Device Cloud instance, so one could use a UUID generator to make the Device ID.

In response to a successful Device addition, you get a 32 character string (base16, UUID) authentication key.

The combination of the Device ID and Authentication key can then be used by an Avimesa Device.

Top

list-devices

Summary:

An Avimesa Group contains Devices. This example shows how to query for a list of devices.

Top

list-files

Summary:

Each Device in the Avimesa Device Cloud has its own file system. This will contain things like the device script, device config, DFU files, and any temporary files used by te script engine.

This example shows listing a devices files.

Top

message-count

Summary:

Sometimes you want to see if there are any messages in a queue. This example shows you how to do that.

Top

queue-purge

Summary:

It's possible that you will want to empty a queue, for example a device's actuation queue to clear any pending commands.

This example shows how to purge a queue.

Top

queue-subscriber

Summary:

This example consumes data from a queue. When using the consume API, it's assumed that the user of this API is in charge of moving data to permanent storage. Upon first connection, all pending messages are available. This allows an application to go offline and not worry about data loss.

Top

queue-temp-subscriber

Summary:

Sometimes you want to 'listen' to a queue for live data passing through it, but not necessarily be responsible for handling the datastore.

This example shows how to create a temporary queue that will get data from the source of your choice by setting up a routing key.

Top

upload-files

Summary:

This example shows how one can upload a Device Driver Script and Device Configuration.

Top

4. Dependencies

@avimesa/group-api-amqp
amqplib
dotenv