Skip to main content

Tools for creating custom drivers

An iRidi driver implements a protocol (rules) for exchanging data with equipment over a transport - a specific data transmission method (TCP, UDP, HTTP, Serial).

HowItWorksTCP.png

If your system does not yet have a ready-made protocol implementation, you can create one yourself. You need a driver that implements only the transport part of data exchange, while you implement the protocol (forming requests and processing responses) using JavaScript.

iRidi Pro supports creating several transport drivers. The following sections describe their features and purposes:

Selecting an AV & Custom Systems driver​

Add an AV & Custom Systems driver for your task:

  • TCP, UDP, Serial (RS232) . To connect to a remote resource using TCP, UDP or RS232:
    • The "AV & Custom Systems" driver in i3 pro or iRidi Server
    • In the driver settings, set "Protocol" to the transport type: TCP, UDP or Serial (RS232)
  • HTTP . To connect to a remote resource using HTTP or HTTPs:
    • The "AV & Custom Systems (HTTP)" driver in i3 pro or iRidi Server
  • TCP server . To accept connections from remote resources using TCP:
    • A JavaScript implementation of a TCP server; the driver is not added to the device tree
  • Shared transport . To let multiple logical devices use a single TCP/UDP connection, with separate data in scripts and separate access to commands and feedbacks
    • The "AV & Custom TCP/UDP Network" driver in i3 pro or iRidi Server
    • The "AV & Custom HTTP Network" driver in i3 pro or iRidi Server

AVCS1.png

Connection settings​

After adding the driver, specify its connection settings:

AV & Custom Systems, TCP​

AV & Custom Systems driver, Protocol: TCP . Connection settings:

  • Host is the IP address or domain name
  • Port is the TCP connection port
  • Mode is the connection mode:
    • Always Connected: continuously connected
    • Connect when Sending - connected only while sending a command. Feedback does not work in this mode, but commands can be sent without keeping the connection open
  • SSL enables/disables SSL encryption
  • Auth type is the authentication type:
    • Basic: uses unencrypted base64 encoding,
    • Digest: credential encryption;
  • Script Mode determines how commands are passed to scripts:
    • Direct & Script: send the command to the equipment immediately and also pass it to the script
    • Script Only - send the command only to the script (when a button is pressed, the command linked to it is processed in iRidi scripts but is not sent to the equipment as it normally would be)
  • Disable Queue disables the command queue in iRidi. The queue accumulates commands that could not be sent for some reason, then sends them when the connection is restored
  • Send Command Attempts is the number of attempts to send a queued command that could not be sent initially. 0 - do not retry sending
  • Wait for Connect (ms) is the connection timeout (after which another connection attempt is made)
  • Wait for Data (ms) is the timeout for a response from the equipment (after which the command is repeated and the connection is checked). Set 0 if the driver should not disconnect from equipment when there is no data exchange

AV & Custom Systems, UDP​

AV & Custom Systems driver, Protocol: UDP . Connection settings:

  • Host is the IP address or domain name
  • Port is the UDP connection port
  • Auth type is the authentication type:
    • Basic: uses unencrypted base64 encoding,
    • Digest: credential encryption;
  • Script Mode determines how commands are passed to scripts:
    • Direct & Script: send the command to the equipment immediately and also pass it to the script
    • Script Only - send the command only to the script (when a button is pressed, the command linked to it is processed in iRidi scripts but is not sent to the equipment as it normally would be)
  • Local Port is the UDP port opened on the iRidi side: data from equipment arrives here. It can differ from the port opened on the equipment side
  • Multicast enables multicast connection mode
    • Group is the multicast group, for example 224.0.0.1

AV & Custom Systems, Serial (RS232)​

AV & Custom Systems driver, Protocol: Serial (RS232). Connection settings:

  • Host is the COM port number to which the controlled device is connected. For example: \.\COM1
  • Baud Rate is the data transfer rate
  • Data Bits is the number of data bits in a frame
  • Parity is the parity setting
  • Stop Bits is the stop bit in a frame
  • The web interface displays stop bits as follows:
10
1,51
22
  • Auth type is the authentication type:
    • Basic: uses unencrypted base64 encoding,
    • Digest: credential encryption;
  • Script Mode determines how commands are passed to scripts:
    • Direct & Script: send the command to the equipment immediately and also pass it to the script
    • Script Only - send the command only to the script (when a button is pressed, the command linked to it is processed in iRidi scripts but is not sent to the equipment as it normally would be)

AV & Custom Systems (HTTP), HTTP​

AV & Custom Systems (HTTP) driver. Connection settings:

  • Host is the IP address or domain name
  • Port is the TCP connection port (usually 80)
  • Login, Password are the username and password for authentication, depending on the specified Auth type
  • SSL enables/disables SSL encryption
  • User Agent is the identification string of the iRidi client application
  • Auth type is the authentication type:
    • Basic: uses unencrypted base64 encoding,
    • Digest: credential encryption;
  • Script Mode determines how commands are passed to scripts:
    • Direct & Script: send the command to the equipment immediately and also pass it to the script
    • Script Only - send the command only to the script (when a button is pressed, the command linked to it is processed in iRidi scripts but is not sent to the equipment as it normally would be)
  • Disable Queue disables the command queue in iRidi. The queue accumulates commands that could not be sent for some reason, then sends them when the connection is restored
  • Send Command Attempts is the number of attempts to send a queued command that could not be sent initially. 0 - do not retry sending
  • Wait for Connection (ms) is the connection timeout (after which another connection attempt is made)
  • Wait for Data (ms) is the timeout for a response from the equipment (after which the command is repeated and the connection is checked). Set 0 if the driver should not disconnect from equipment when there is no data exchange

Command formatting examples​

Strings, characters, numbers and their sequences for TCP, UDP, Serial​

To send a data sequence to equipment over TCP, UDP or a COM port, create a command (Command) in the "AV & Custom Systems" driver with the appropriate transport, and enter the data in the Data field of the created command.

Calling the command with any Value sends the entered data to the equipment.

While iRidi is running, you cannot change the contents of a command created this way (it is a constant). Variable values must be formed in scripts (see the .Set and .Send methods).

Rules for formatting data:

  • Enclose a string (STRING ) in 'single quotation marks'. Enclose multiple strings in quotation marks and separate them with commas. See below for line endings (CR or LF)
  • Separate hexadecimal (HEX ) characters with commas, and prefix each character with $ or 0x (other prefixes are not supported)
  • Separate decimal (DEC ) numbers with commas
  • At the end of the data, add one or both end-of-line characters as specified by your API:
    • ,13 - carriage return (CR). In iRidi, the same character can also be written as ,$0D or ,0x0D
    • ,10 - line feed (LF). In iRidi, the same character can also be written as ,$0A or ,0x0A
    • Some devices accept only CR, some CR+LF, and some do not need a line ending at all, but it is usually required. Follow your API and do not neglect this addition!

Examples: * A sequence of hexadecimal characters + end of line:
0x16,0x8A,0xFF,0x81,13 or
0x16,0x8A,0xFF,0x81,0x0D * A sequence of decimal numbers + end of line:
01,255,255,15,13 * A string + end of line:
'PWR 01',13 * Mixed data + end of line:
0,255,'PWR 01',0x00,0xFF,13

AVCS2.png

How to tell whether data is formatted correctly:

  • In the Data window, the lower part shows the command converted to HEX (as the driver will send it). If the lower part contains no characters, or the character counts in the upper and lower parts clearly differ, the data formatting is incorrect. Check commas, quotation marks and HEX character formatting.
  • If the first part of the data is formatted correctly but the last part is not, the last part is discarded. Check that the character counts in the upper and lower parts of the window match

HTTP GET, POST, PUT requests​

To send an HTTP request to equipment, create a command (Command) in the "AV & Custom Systems (HTTP)" driver and enter the data in the URI field of the created command. POST and PUT requests let you send additional data in Data .

Calling the command with any Value sends the constructed request to the equipment.

While iRidi is running, you cannot change the contents of a request created this way (it is a constant). Variable values must be formed in scripts (the .SendEx method).

Rules for formatting GET requests :

The request consists of the URI request body - the data after the IP address or domain name in the HTTP request. Copy the data into URI, starting with / (slash), without quotation marks: * example 1: http://iridi.com/support

    • /support - the request body to enter in URI
    • iridi.com - the destination address, specified in Host in the driver settings

the default port (80), specified in the driver settings * example 2: httр://192.168.0.100:81/do?cmd=ir_code=B748BF00

    • /do?cmd=ir_code=B748BF00 - the request body to enter in URI
    • 192.168.0.100 - the destination address, specified in Host in the driver settings
    • 81 - the port, specified in the driver settings

You can use the script method .SendEx to construct requests, data and headers, and to process the responses to those requests

AVCS3.png

Rules for formatting POST and PUT requests :
The request consists of the URI request body - the data after the IP address or domain name in the HTTP request - and additional data specified in Data. Enter URI without quotation marks, and Data as an array of strings in quotation marks (see the string formatting rules for TCP, UDP, Serial).

Example:

POST /YamahaRemoteControl/ctrl HTTP/1.1

Accept: */*
Referer: http://192.168.10.102/
Content-Type: text/xml; charset=UTF-8
Host: 192.168.10.100
Content-Length: 105
Cache-Control: no-cache

<YAMAHA_AV cmd="PUT"><System><Power>Standby</Power></System></YAMAHA_AV>
  • /YamahaRemoteControl/ctrl - (without HTTP 1.1) the request body to enter in URI
  • 'Standby' - the additional data to enclose entirely in quotation marks and enter in Data

The remaining data consists of headers that the driver generates automatically * You can use the script method .SendEx to construct requests, data and headers, and to process the responses to those requests

AVCS4.png

Incoming data processing examples​

Incoming data is always processed in scripts.

With any transport, you can subscribe to IR.EVENT_RECEIVE_TEXT or IR.EVENT_RECEIVE_DATA and process the data received from the driver by the listeners.

For HTTP , the most suitable method for processing data is .SendEx - it lets you construct and send a request, wait for the response, and immediately process the response to that specific request. This avoids having to determine which request a response relates to, as when using the driver's event system.

Example of a TCP server with incoming data processing.

Example using SendEx:

function Login() {
IR.GetDevice("Server REST").SendEx({
Type: "POST",
Url: "/html/login",
Data: ["Password=2007&name=auth&Login=admin"],
Headers: {"Content-Type": "application/x-www-form-urlencoded"},

cbReceiveKey: function(key,value)
{
if (key == "set-cookie")
{
cookie = value.match(/=.+;/);
if (cookie) {
IR.Log("ir-session-id" + cookie);
Volume80();
}
}
}
});
}

function Volume80() {
IR.GetDevice("Server REST").SendEx({
Type: "GET",
Url: "/json/ok/server/channel/set?name=Sender%20Hotel.FM%20Volume?value=80",
Headers: {"Cookie":"ir-session-id" + cookie},

cbReceiveText: function(text, code, headers) {
IR.Log("cbReceiveText code: " + code); IR.Log("cbReceiveText text: " + text);
}
});
}

IR.AddListener(IR.EVENT_START, 0, function() {
Login();
});

TCP server example​

Example: TCP server for i3 pro