Neolithic Programming Machine

    itach

    2.0.1 • Public • Published

    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

    Install

    npm i itach

    DownloadsWeekly Downloads

    13

    Version

    2.0.1

    License

    MIT License

    Unpacked Size

    11.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • tillbaks