0.8.13 • Published 5 years ago

mqtt-topping v0.8.13

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

mqtt-topping

A small wrapper around the MQTT.js client and an API to query retained topics via HTTP.

MQTT Client Features

  • Subscribe and unsubscribe handler callbacks to individual (wildcard) topics
  • JSON.stringify all published payloads
  • JSON.parse all incoming payloads
  • Ignore non-JSON payloads
  • Decide whether to retain a message or not depending on the topic name (retained unless topic is prefixed with on or do)
  • Publishes and subscriptions are send with quality-of-service 2

Usage

var topping = require("mqtt-topping").default;

var client = topping.connect("tcp://broker.example.com", "http://broker.example.com");

client.subscribe("my/topic", function(payload, topic, packet) {
  console.log("Received Payload " + payload +
              " for Topic " + topic +
              " (retained = " + packet.retain + ")");
});

HTTP Query Features

Query

Example

client.query({ topic: "example", depth: 0, parseJson: true, flatten: false }).then((result) => {
  // process result
});

The query API allows single and batch queries including wildcard topics via HTTP. It specifically supports JSON payloads and parses them if possible. Multiple results of a batch, wildcard or flattened query are structured as Array of results. A single result has the format:

{
  topic: String,
  payload: PAYLOAD,
  children?: CHILDREN
}
// PAYLOAD = The JSON parsed payload
// CHILDREN = An array of subtopic results

Options

Boolean parseJson

If false result.payload contains the raw payload as String. Default is true.

Number depth

Specifies the recursive depth of the query. A depth > 0 returns subtopic results in result.children. Default is 0.

Boolean flatten

Flattens all results into a flat array of results. Default is false.

QueryJson

Example

client.queryJson({ topic: "example" }).then((result) => {
  // process result
});

The queryJson API allows single and batch queries via HTTP. Multiple results of a batch query are structured as Array of results. A single result is an object containing subtopics as properties. The subtopics may be objects with subtopics or the json parsed payload.

0.8.13

5 years ago

0.8.12

6 years ago

0.8.11

6 years ago

0.8.10

6 years ago

0.8.9

6 years ago

0.8.8

6 years ago

0.8.7

6 years ago

0.8.6

6 years ago

0.8.5

6 years ago

0.8.4

6 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.0

7 years ago

0.7.3

7 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.7

9 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.6

10 years ago

0.4.5

10 years ago

0.4.4

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago