Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

evrythng-mqtt

evrythng101.1.0

Evrythng.js MQTT plugin for MQTT real-time communication with EVRYTHNG API

evrythng, everything, thng, evt, iot, internet of things, wot, web of things, thng-hub, hub, mqtt, thng-scan, scanthng

readme

EVRYTHNG-MQTT.JS (plugin for EVT.js)

evrythng-mqtt.js is an extension plugin to be used with evrythng.js or evrythng-extended.js JS libraries.

It adds MQTT support to any resource, allowing to publish, subscribe and unsubscribe to the resource's topics easily.

evrythng-mqtt.js is only available for Node.js as a NPM package. For browsers, consider using evrythng-ws.js.

Installation

Node.js

npm install evrythng-mqtt --save

Usage

var EVT = require('evrythng-extended'),
  mqtt = require('evrythng-mqtt');

EVT.use(mqtt);
...

Examples

General

Use specific settings (below are defaults)

mqtt.setup({
  apiUrl: 'mqtts://mqtt.evrythng.com:8883/mqtt',
  reconnectPeriod: 1000,
  keepAlive: 50,
  clientIdPrefix: 'evtjs'
});

Authenticate as an Operator and read a Thng object:

var operator = new EVT.Operator(OPERATOR_API_KEY);
var thngResource = operator.thng('{thngId}');

Subscribe to property updates of a particular Thng:

thngResource.property().subscribe(function(update){
  console.log(update);
});

Publish property updates:

thngResource.property('key').publish(value);

Create an action:

thngResource.action('scans').publish();

Update a Thng:

thngResource.publish({
  name: 'My new cool name'
});

Unsubscribe to a subscribed topic:

thngResource.property().unsubscribe();

Documentation

Check all the available subscriptions on the EVRYTHNG Pubsub documentation.

Source Maps

Source Maps are available, which means that when using the minified version, if you open Developer Tools (Chrome, Safari, Firefox), .map files will be downloaded to help you debug code using the original uncompressed version of the library.

evrythng.js

evrythng.js is the core version of evrythng.js intended to be used in public applications and/or devices.

evrythng-extended.js

evrythng-extended.js is an extended version of evrythng.js which includes Operator access to the API.

License

Apache 2.0 License, check LICENSE.txt

Copyright (c) EVRYTHNG Ltd.

changelog

v1.1.0 (10-01-2017)

Features

  • Options: Allow to pass connectOptions to the subscribe and publish methods

Bug fixes

  • Unsubscribe: Correct handling of empty subscriptions map. to override resource authentication/url.

v1.0.8 (29-09-2016)

Bug fixes

  • Subscribe: Fix multiple subscriptions not being handled correctly.

v1.0.7 (18-08-2016)

Bug fixes

  • Unsubscribe: Fix subscription not being removed correctly on unsubscribe.

v1.0.6 (14-12-2015)

Bug fixes

  • Connect: Reject and terminate connection when unable to reach host.

v1.0.5 (02-12-2015)

Bug fixes

  • Resubscribe on reconnect: Restore subscriptions after reconnect.
  • One connection per scope: When making multiple subscriptions in parallel, only one connection per scope should be created.

v1.0.4 (31-07-2015)

Bug Fixes

  • Publish: silence rejection from hijacked HTTP request.

v1.0.3 (25-06-2015)

Features

  • documentation: updated documentation with consistent format from other libs.

v1.0.2 (24-06-2015)

Bug Fixes

  • package.json: request dependency removed, as this is part of evrythng.js.

v1.0.1 (24-06-2015)

Bug Fixes

  • package.json: Added mqtt to dependencies.

v1.0.0 (22-06-2015)

Features

  • MQTT methods: allow to subscribe, unsubscribe and publish to any EVT resource.