Create a gist now

Instantly share code, notes, and snippets.

@celly /imatic.js
Last active Feb 25, 2016

SainSmart iMatic with RJ45 Interface Node JS Snippet
#
# NodeJs code for controlling
# SainSmart iMatic with RJ45 Interface
#
var net = require("net");
var client = new net.Socket();
client.connect(30000, '192.168.1.4', function() {
console.log('connected to iMatic!');
});
var PREFIX = '\xFD\x02\x20';
var POSTFIX = "\x5D";
function iMaticOn(relayId) {
var relay = String.fromCharCode(relayId);
var on = String.fromCharCode(1);
var cmd = PREFIX+relay+on+POSTFIX;
client.write(cmd, 'ascii');
}
function iMaticOff(relayId) {
var relay = String.fromCharCode(relayId);
var off = String.fromCharCode(0);
var cmd = PREFIX+relay+off+POSTFIX;
client.write(cmd, 'ascii');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment