0.0.9 • Published 6 years ago

mqtt-methods v0.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

mqtt-rpc Build Status

This module provides an rpc interface for an mqtt connection, in essence this is a request and response strategy which uses an MQTT topic structure as transport.

NPM NPM

Installation

npm install mqtt-rpc

server

Exposes an array of functions which retrieves and returns data.

var mqtt = require('mqtt')
  , mqttrpc = require('mqtt-rpc')
  , debug = require('debug')('remote-time:server');

var settings = {
  reconnectPeriod: 5000 // chill on the reconnects
}

// client connection
var mqttclient = mqtt.connect('mqtt://localhost', settings);

// build a mqtt new RPC server
var server = mqttrpc.server(mqttclient);

// optionally configure the codec, which defaults to JSON, also supports msgpack
server.format('json');

// provide a new method
server.provide('$RPC/time', 'localtime', function (args, cb) {
  debug('localtime');
  cb(null, new Date());
});

client

Consumes the api exposed by the previous example.

var mqtt = require('mqtt')
  , mqttrpc = require('mqtt-rpc')
  , debug = require('debug')('remote-time:client');

var settings = {
  reconnectPeriod: 5000 // chill on the reconnects
}

// client connection
var mqttclient = mqtt.connect('mqtt://localhost', settings);

// build a new RPC client
var client = mqttrpc.client(mqttclient);

// optionally configure the codec, which defaults to JSON, also supports msgpack
client.format('json');

// call the remote method
client.callRemote('$RPC/time', 'localtime', {}, function(err, data){
  debug('callRemote', err, data);
});

License

Copyright (c) 2013 Mark Wolfe Licensed under the MIT license.

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago