Skip to content

Instantly share code, notes, and snippets.

Last active Feb 25, 2016
What would you like to do?
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, '', 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