Help on Plugin Creation - GC IP2SL to Wyrestorm HDBaseT Matrix

Migrating from iRule and I’m able to get these commands to work via iTest by sending it as “Mixed” when the button unchecked for “Remove spaces from Mixed Command”. But I can’t seem to get any variation of them to work in Home Remote.

For example, in iTest, sending “cir 32\x0D” (without the quotes) changes the Source for Output 4 to Source 1.

I import the plugin below to Home Remote and created a couple test buttons to try the commands and run the simulator. They “work” in the sense that they trigger the right command lines in the plugin code but nothing happens on the Wyrestorm.

Any idea what could be going wrong? Is the space in the command a problem? When the box in iTest to remove extra spaces was checked it would not work there either.

plugin.Name = “WyrestormMatrix”;
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1;
plugin.DefaultSettings = {
“Host” : “192.168.11.94”,
“Port” : “4999”,
};

var VERSION = “v1”;
var debug = true;
var LOG_MAX = 5000;
var LOG_TRIM = 500;

var socket = new TCPClient();

var mediaCommandMappings = {
“OUT 1 IN 1” : “cir 00\x0D”,
“OUT 1 IN 2” : “cir 01\x0D”,
“OUT 1 IN 3” : “cir 02\x0D”,
“OUT 1 IN 4” : “cir 03\x0D”,
“OUT 1 IN 5” : “cir 04\x0D”,
“OUT 1 IN 6” : “cir 05\x0D”,
“OUT 1 IN 7” : “cir 06\x0D”,
“OUT 1 IN 8” : “cir 07\x0D”,
“OUT 2 IN 1” : “cir 10\x0D”,
“OUT 2 IN 2” : “cir 11\x0D”,
“OUT 2 IN 3” : “cir 12\x0D”,
“OUT 2 IN 4” : “cir 13\x0D”,
“OUT 2 IN 5” : “cir 14\x0D”,
“OUT 2 IN 6” : “cir 15\x0D”,
“OUT 2 IN 7” : “cir 16\x0D”,
“OUT 2 IN 8” : “cir 17\x0D”,
“OUT 3 IN 1” : “cir 20\x0D”,
“OUT 3 IN 2” : “cir 21\x0D”,
“OUT 3 IN 3” : “cir 22\x0D”,
“OUT 3 IN 4” : “cir 23\x0D”,
“OUT 3 IN 5” : “cir 24\x0D”,
“OUT 3 IN 6” : “cir 25\x0D”,
“OUT 3 IN 7” : “cir 26\x0D”,
“OUT 3 IN 8” : “cir 27\x0D”,
“OUT 4 IN 1” : “cir 30\x0D”,
“OUT 4 IN 2” : “cir 31\x0D”,
“OUT 4 IN 3” : “cir 32\x0D”,
“OUT 4 IN 4” : “cir 33\x0D”,
“OUT 4 IN 5” : “cir 34\x0D”,
“OUT 4 IN 6” : “cir 35\x0D”,
“OUT 4 IN 7” : “cir 36\x0D”,
“OUT 4 IN 8” : “cir 37\x0D”,
“OUT 5 IN 1” : “cir 40\x0D”,
“OUT 5 IN 2” : “cir 41\x0D”,
“OUT 5 IN 3” : “cir 42\x0D”,
“OUT 5 IN 4” : “cir 43\x0D”,
“OUT 5 IN 5” : “cir 44\x0D”,
“OUT 5 IN 6” : “cir 45\x0D”,
“OUT 5 IN 7” : “cir 46\x0D”,
“OUT 5 IN 8” : “cir 47\x0D”,
“OUT 6 IN 1” : “cir 50\x0D”,
“OUT 6 IN 2” : “cir 51\x0D”,
“OUT 6 IN 3” : “cir 52\x0D”,
“OUT 6 IN 4” : “cir 53\x0D”,
“OUT 6 IN 5” : “cir 54\x0D”,
“OUT 6 IN 6” : “cir 55\x0D”,
“OUT 6 IN 7” : “cir 56\x0D”,
“OUT 6 IN 8” : “cir 57\x0D”,
“OUT 7 IN 1” : “cir 60\x0D”,
“OUT 7 IN 2” : “cir 61\x0D”,
“OUT 7 IN 3” : “cir 62\x0D”,
“OUT 7 IN 4” : “cir 63\x0D”,
“OUT 7 IN 5” : “cir 64\x0D”,
“OUT 7 IN 6” : “cir 65\x0D”,
“OUT 7 IN 7” : “cir 66\x0D”,
“OUT 7 IN 8” : “cir 67\x0D”,
“OUT 8 IN 1” : “cir 70\x0D”,
“OUT 8 IN 2” : “cir 71\x0D”,
“OUT 8 IN 3” : “cir 72\x0D”,
“OUT 8 IN 4” : “cir 73\x0D”,
“OUT 8 IN 5” : “cir 74\x0D”,
“OUT 8 IN 6” : “cir 75\x0D”,
“OUT 8 IN 7” : “cir 76\x0D”,
“OUT 8 IN 8” : “cir 77\x0D”,
};

var inputSourceMappings = {
“Input1” : “ky src.1”,
“Input2” : “ky src.2”,
“Input3” : “ky src.3”,
“Input4” : “ky src.4”,
“Input5” : “ky src.5”,
};

// helper function to clear the socket receive buffer
function flushReceiveBuffer() {
if(socket.available) {
socket.receive();
}
}

function onConnect() {
console.log(“onConnect called…”);

var host = plugin.Settings["Host"];
var port = plugin.Settings["Port"];

console.log("  Host: " + host);
console.log("  Port: " + port);

var device = plugin.Devices[plugin.Name];

if(device) {
    console.log("  setting supported media commands...");
    device.SupportedMediaCommands = Object.keys(mediaCommandMappings);
    console.log("  set...");

    console.log("  setting supported input sources...");
    device.SupportedInputSources = Object.keys(inputSourceMappings);
    console.log("  set...");
}

console.log("  connecting...");
socket.connect(host, port);
console.log("  connected");   

}

function onChangeRequest(device, attribute, value) {
console.log(“onChangeRequest called…”);
}

function onDisconnect() {
console.log(“onDisconnect called…”);
socket.close();
console.log(" disconnected");
}

function onPoll() {
var device = plugin.Devices[plugin.Name];
}

function onSynchronizeDevices() {
console.log(“onSynchronizeDevices called…”);

var device = new Device();

device.Id = plugin.Name;
device.DisplayName = "Wyrestorm Matrix";
device.Icon = "TV";
device.Capabilities = [ "MediaControl", "MediaInputSource", "Switch" ];
device.Attributes = [ "Log" ];

plugin.Devices[plugin.Name] = device;

console.log("  done syncing");

}

function debugLog(s) {
// Logs a string to both the console and the device Log attribute
// because the console is not available in the app. It can also
// trim the device Log to keep it from growing too large if
// LOG_MAX is not 0.
if(debug) {
var device = plugin.Devices[plugin.Name];

    // is this the first time through?
    if(device && !device.Log) {
        // log is empty, so start it off with version info
        var verstr = plugin.Name + ": version " + VERSION;
        console.log(verstr);
        device.Log = verstr + "\n";
    }

    var logstr = plugin.Name + ": " + s;

    // send it to the console
    console.log(logstr);

    // send it to the device log
    if(device && device.Log) {
        device.Log += logstr + "\n";
       
        // trim the log if necessary
        if(LOG_MAX && (device.Log.length > LOG_MAX)) {
            device.Log = device.Log.slice(-(LOG_MAX + LOG_TRIM));
        }
    }
}

}

You haven’t programmed onChangeRequest yet. That’s what actually sends your commands. All your code is doing is writing to the log.

function onChangeRequest(device, attribute, value) {
console.log(“onChangeRequest called…”);
}

Your code should probably be doing something like this:

function onChangeRequest(device, attribute, value) {
    if (attribute != "MediaCommand")
        throw "Invalid attribute";

    var command = commands[value];
    if (!command)
        throw "Invalid command";

    socket.send(command);
}

I copied that code from this example:

1 Like

Bill,

Thanks. I was actually just about to post in here and say disregard, I figured it out.

You hit the nail on the head with the first part, I didn’t have the socket.send(command) so it wasn’t actually even trying to send the command. Duh.

I also didn’t have the syntax of the commands correct either. This file works now for anyone that might be interested in it. I plan to clean it up later and add some other elements but functionally this works.

Thanks!
WyrestormMatrix.plugin (7.1 KB)

1 Like