Skip to content

Instantly share code, notes, and snippets.

@celly
Last active February 25, 2016 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celly/f79ca8cd0e5e7ca36e86 to your computer and use it in GitHub Desktop.
Save celly/f79ca8cd0e5e7ca36e86 to your computer and use it in GitHub Desktop.
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