Home

Awesome

binrpc

npm version dependencies Status Coverage Status Build Status XO code style License

HomeMatic xmlrpc_bin:// protocol server and client

For use with CCU1/2 (rfd, hs485d, Rega), Homegear and CUxD

Implements the same interface as homematic-xmlrpc, these 2 libs should be a 1:1 drop-in-replacement for each other.

Changelog

Breaking Change in v3.0.0: To be consistent with homematic-xmlrpc the RPC client isn't an event emitter anymore. All errors have to be handled through the methodCall callback.

Change in v2.1.0 To be consistent with homematic-xmlrpc you don't have to wait for the client connect event before using methodCall.

Breaking change in v2.0.0: system.multicall isn't resolved in single calls anymore. This should be done by the application itself and was removed to be consistent with homematic-xmlrpc.

Examples

Switch on the Channel LEQ0134153:1

var rpc = require('binrpc');

var rpcClient = rpc.createClient({host: '192.168.1.100', port: '2001'});

rpcClient.methodCall('setValue', ['LEQ0134153:1', 'STATE', true], function (err, res) {
    console.log('response', err, JSON.stringify(res));
});

For a full example on how to subscribe to CCU events see example.js

Further reading

API Documentation

Modules

<dl> <dt><a href="#module_binrpc">binrpc</a></dt> <dd></dd> <dt><a href="#module_client">client</a></dt> <dd></dd> <dt><a href="#module_protocol">protocol</a></dt> <dd></dd> <dt><a href="#module_server">server</a></dt> <dd></dd> </dl>

Classes

<dl> <dt><a href="#Client">Client</a></dt> <dd></dd> <dt><a href="#Protocol">Protocol</a></dt> <dd></dd> <dt><a href="#Server">Server</a></dt> <dd></dd> </dl>

<a name="module_binrpc"></a>

binrpc

<a name="module_binrpc.createClient"></a>

binrpc.createClient(options) ⇒ <code>Client</code>

RPC client factory

Kind: static method of <code>binrpc</code>

ParamTypeDefaultDescription
options<code>object</code>
options.host<code>string</code>the hostname or ip address to connect to
options.port<code>number</code>the port to connect to
[options.reconnectTimeout]<code>number</code><code>2500</code>wait milliseconds until trying to reconnect after the socket was closed
[options.responseTimeout]<code>number</code><code>5000</code>wait milliseconds for method call response
[options.queueMaxLength]<code>number</code><code>15</code>maximum number of methodCalls that are allowed in the queue

<a name="module_binrpc.createServer"></a>

binrpc.createServer(options, onListening) ⇒ <code>Server</code>

RPC server factory

Kind: static method of <code>binrpc</code>

ParamTypeDescription
options<code>object</code>
options.host<code>string</code>ip address on which the server should listen
options.port<code>number</code>port on which the server should listen
onListening<code>function</code>function to be invoked in the server's listening callback

<a name="module_client"></a>

client

<a name="module_client+queue"></a>

client.queue : <code>Array</code>

The request queue. Array elements must be objects with the properties buffer and callback

Kind: instance property of <code>client</code>
<a name="module_client+queueMaxLength"></a>

client.queueMaxLength : <code>number</code>

Maximum queue length. If queue length is greater than this a methodCall will return error 'You are sending too fast'

Kind: instance property of <code>client</code>
<a name="module_client+queueRetryTimeout"></a>

client.queueRetryTimeout : <code>number</code>

Time in milliseconds. How long to wait for retry if a request is pending

Kind: instance property of <code>client</code>
<a name="module_client+pending"></a>

client.pending : <code>boolean</code>

Indicates if there is a request waiting for its response

Kind: instance property of <code>client</code>
<a name="module_client+responseTimeout"></a>

client.responseTimeout : <code>number</code>

Time in milliseconds. How long to wait for a method call response

Kind: instance property of <code>client</code>
<a name="module_client+connect"></a>

client.connect()

connect

Kind: instance method of <code>client</code>
<a name="module_client+queuePush"></a>

client.queuePush(buf, cb)

Push request to the queue

Kind: instance method of <code>client</code>

ParamType
buf<code>buffer</code>
cb<code>function</code>

<a name="module_client+queueShift"></a>

client.queueShift()

Shift request from the queue and write it to the socket.

Kind: instance method of <code>client</code>
<a name="module_client+methodCall"></a>

client.methodCall(method, params, callback)

methodCall

Kind: instance method of <code>client</code>

ParamTypeDescription
method<code>string</code>
params<code>Array</code>
callback<code>function</code>optional - if omitted an empty string will be send as response

<a name="module_protocol"></a>

protocol

<a name="module_protocol.encodeRequest"></a>

protocol.encodeRequest(method, data) ⇒ <code>Buffer</code>

encode requests

Kind: static method of <code>protocol</code>

ParamTypeDescription
method<code>string</code>throws error if not type string or if string is empty
data<code>*</code>optional - defaults to an empty array

<a name="module_protocol.encodeResponse"></a>

protocol.encodeResponse(data) ⇒ <code>Buffer</code>

encode response

Kind: static method of <code>protocol</code>

ParamTypeDescription
data<code>*</code>optional - defaults to empty string

<a name="module_protocol.encodeData"></a>

protocol.encodeData(obj) ⇒ <code>Buffer</code>

encode data

Kind: static method of <code>protocol</code>

ParamTypeDescription
obj<code>*</code>throws TypeError if obj is undefined or null

<a name="module_protocol.encodeStruct"></a>

protocol.encodeStruct(obj) ⇒ <code>Buffer</code>

encode struct

Kind: static method of <code>protocol</code>

ParamTypeDescription
obj<code>object</code>throws error if not of type object

<a name="module_protocol.encodeStructKey"></a>

protocol.encodeStructKey(str) ⇒ <code>Buffer</code>

encode struct key

Kind: static method of <code>protocol</code>

ParamTypeDescription
str<code>string</code>throws error if not of type string

<a name="module_protocol.encodeArray"></a>

protocol.encodeArray(arr) ⇒ <code>Buffer</code>

encode array

Kind: static method of <code>protocol</code>

ParamTypeDescription
arr<code>array</code>throws error if not instance of Array

<a name="module_protocol.encodeString"></a>

protocol.encodeString(str) ⇒ <code>Buffer</code>

encode string

Kind: static method of <code>protocol</code>

ParamTypeDescription
str<code>string</code>throws error if not of type string

<a name="module_protocol.encodeBool"></a>

protocol.encodeBool(b) ⇒ <code>Buffer</code>

encode bool

Kind: static method of <code>protocol</code>

ParamTypeDescription
b<code>*</code>any type

<a name="module_protocol.encodeInteger"></a>

protocol.encodeInteger(i) ⇒ <code>Buffer</code>

encode integer

Kind: static method of <code>protocol</code>

ParamTypeDescription
i<code>number</code>throws error if not a number or if out of range (min=-2147483648 max=2147483647)

<a name="module_protocol.encodeDouble"></a>

protocol.encodeDouble(d) ⇒ <code>Buffer</code>

encode double

Kind: static method of <code>protocol</code>

ParamTypeDescription
d<code>number</code>throws error if not a number

<a name="module_protocol.decodeDouble"></a>

protocol.decodeDouble(elem) ⇒ <code>object</code>

decode double

Kind: static method of <code>protocol</code>
Returns: <code>object</code> - properties content and rest

ParamTypeDescription
elem<code>Buffer</code>throws error if not an instance of Buffer or if length <8

<a name="module_protocol.decodeString"></a>

protocol.decodeString(elem) ⇒ <code>object</code>

decode string

Kind: static method of <code>protocol</code>
Returns: <code>object</code> - properties content and rest

ParamTypeDescription
elem<code>Buffer</code>throws error if not an instance of Buffer or if length <4

<a name="module_protocol.decodeBool"></a>

protocol.decodeBool(elem) ⇒ <code>object</code>

decode double

Kind: static method of <code>protocol</code>
Returns: <code>object</code> - properties content and rest

ParamTypeDescription
elem<code>Buffer</code>throws error if not an instance of Buffer or if length <8

<a name="module_protocol.decodeInteger"></a>

protocol.decodeInteger(elem) ⇒ <code>object</code>

decode integer

Kind: static method of <code>protocol</code>
Returns: <code>object</code> - properties content and rest

ParamTypeDescription
elem<code>Buffer</code>throws error if not an instance of Buffer or if length <4

<a name="module_protocol.decodeArray"></a>

protocol.decodeArray(elem) ⇒ <code>object</code>

decode array

Kind: static method of <code>protocol</code>
Returns: <code>object</code> - properties content and rest

ParamTypeDescription
elem<code>Buffer</code>throws error if not an instance of Buffer or if length <4

<a name="module_protocol.decodeStruct"></a>

protocol.decodeStruct(elem) ⇒ <code>object</code>

decode struct

Kind: static method of <code>protocol</code>
Returns: <code>object</code> - properties content and rest

ParamTypeDescription
elem<code>Buffer</code>throws error if not an instance of Buffer or if length <4

<a name="module_protocol.decodeData"></a>

protocol.decodeData(data) ⇒ <code>*</code>

decodes binary data

Kind: static method of <code>protocol</code>

ParamType
data<code>Buffer</code>

<a name="module_protocol.decodeResponse"></a>

protocol.decodeResponse(data) ⇒ <code>*</code>

decode response

Kind: static method of <code>protocol</code>

ParamTypeDescription
data<code>Buffer</code>throws TypeError if data is no instance of Buffer

<a name="module_protocol.decodeStrangeRequest"></a>

protocol.decodeStrangeRequest(data) ⇒ <code>Array</code>

decode "strange" request

Kind: static method of <code>protocol</code>

ParamTypeDescription
data<code>Buffer</code>throws TypeError if data is no instance of Buffer

<a name="module_protocol.decodeRequest"></a>

protocol.decodeRequest(data) ⇒ <code>*</code>

decode request

Kind: static method of <code>protocol</code>

ParamTypeDescription
data<code>Buffer</code>throws TypeError if not instance of Buffer

<a name="module_server"></a>

server

<a name="Client"></a>

Client

Kind: global class
<a name="new_Client_new"></a>

new Client(options)

ParamTypeDefaultDescription
options<code>object</code>
options.host<code>string</code>the hostname or ip address to connect to
options.port<code>number</code>the port to connect to
[options.reconnectTimeout]<code>number</code><code>2500</code>wait milliseconds until trying to reconnect after the socket was closed
[options.responseTimeout]<code>number</code><code>5000</code>wait milliseconds for method call response
[options.queueMaxLength]<code>number</code><code>15</code>maximum number of methodCalls that are allowed in the queue

<a name="Protocol"></a>

Protocol

Kind: global class
<a name="Server"></a>

Server

Kind: global class

<a name="new_Server_new"></a>

new Server(options, onListening)

ParamTypeDescription
options<code>object</code>
options.host<code>string</code>ip address on which the server should listen
options.port<code>number</code>port on which the server should listen
onListening<code>function</code>function to be invoked in the server's listening callback

<a name="Server+event_[method]"></a>

"[method]" (error, params, callback)

Fires when RPC method call is received

Kind: event emitted by <code>Server</code>

ParamTypeDescription
error<code>*</code>
params<code>array</code>
callback<code>function</code>callback awaits params err and response

<a name="Server+event_NotFound"></a>

"NotFound" (method, params)

Fires if a RPC method call has no event handler. RPC response is always an empty string.

Kind: event emitted by <code>Server</code>

ParamType
method<code>string</code>
params<code>array</code>

License

The MIT License (MIT)

Copyright (c) 2014-2018 Sebastian 'hobbyquaker' Raff and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.