Giter Club home page Giter Club logo

node-itach's Introduction

node-itach

Simple Node.js module to send commands to GlobalCache iTach devices. Should handle reconnection (if connection lost), resending (on busyIR), etc.. but not abstract away the iTach API (https://www.globalcache.com/files/docs/API-iTach.pdf).

Note: Only testing with IP2IR device but it should work with any of the itach devices.

Installation

npm install itach --save

Example

var itach = require("itach");

itach.on("connect", async () => {
  console.log("Connected to itach");
  try {
    const result = await itach.send("sendir:..")
  } catch (error) {
    // Some error happened
  }
});

itach.connect({ host: "itach", reconnect: true });

API

All commands are enqueued and are only sent when a connection to an itach device is present. The queue is paused if connection is lost and then resumed when connection is restored.

If iTach is already busy sending IR from another connection it will retry every options.retryInterval until options.sendTimeout is reached.

setOptions(options)

Changes options

Arguments

  • options - (Mandatory) An options Object
    • options.host - (Default: null) Hostname/IP to connect to
    • options.port - (Default: 4998) Port to connect to
    • options.reconnect - (Default: false) Try to reconnect if connection is lost
    • options.reconnectInterval - (Default: 3000) Time (in milliseconds) between reconnection attempts
    • options.connectionTimeout - (Default: 3000) Timeout (in milliseconds) when connection attempt is assumed to be failed. error event will be emitted.
    • options.retryInterval- (Default: 99) Time (in milliseconds) between resending attempts (when busyIR is received)
    • options.sendTimeout - (Default: 500) Time (in milliseconds) after which a sent command will be assumed lost

Examples

itach.setOptions({ host: "itachIP2IR", reconnect: true });

connect(options)

Connects to itach device and optionally changes options before connecting.

Arguments

  • options - An options Object (see setOptions method)

Examples

itach.connect();
itach.connect({ host: "itachIP2IR", reconnect: true });

close(options)

Closes the connection to the itach device. Note: If reconnect is enabled the connection will not stay closed. If you want that you have to pass in { reconnect: false }. Also note: You can change any options.

Example

itach.close();
itach.close({ reconnect: false });

send(data)

Sends a itach api command to be executed.

Arguments

  • data - (Mandatory) String containing a itach command (carriage return not required)

Returns

A promise that will resolve to the result of the sent command.

Example

try {
  const result = await itach.send('sendir,1:1,1,38400,1,1,347,173,22,22,22,65,22,22,22,22,22,65,22,22,22,22,22,22,22,22,22,22,22,65,22,22,22,65,22,65,22,22,22,22,22,22,22,22,22,65,22,22,22,22,22,22,22,22,22,22,22,65,22,65,22,22,22,65,22,65,22,65,22,65,22,65,22,1657')
  console.log(result) // completeir...
} catch (error) {
  // handle error
}

Events

  • connect - Connection to itach has been established and commands will now be sent
  • close - Connection to itach has been closed
  • error - Some error with the socket connection

Example

itach.on("connect", function() {
  // Connection established
});

itach.on("close", function() {
  // Connection closed
});

itach.on("error", function (error) {
  // Error occurred
});

TODO

LINKS

node-itach's People

Contributors

tillbaks avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.