Last active
February 25, 2016 19:22
-
-
Save celly/f79ca8cd0e5e7ca36e86 to your computer and use it in GitHub Desktop.
SainSmart iMatic with RJ45 Interface Node JS Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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