I re-wrote my local copy of blynk-client - Node.js

I figure it might help others that connect to multiple servers / ports

#!/usr/bin/env node

var Blynk = require("../");

if (process.argv[2]) {
 if ((process.argv[2]=="-h") || (process.argv[2]=="--h")) {
 printusage();
 process.exit(1);
 }
 if ((process.argv[2]=="-help") || (process.argv[2]=="--help")) {
 printusage();
 process.exit(1);
 }
}
if ((process.argv[2]) && (process.argv[2].length != 32)) {
console.log("");
  console.log("Looks like you're TOKEN is Off by a few characters - Recopy");
  console.log("");
 printusage();
 process.exit(1);

}

function printusage () {
var examf = "Example ";
var examb = "blynk-client abcdefghijklmnopqrstuvxyz12345678 ";
var exams = "192.168.1.99 ";
var examp1 = "8080 ";
var examp2 = "9443 ";
var exam1 = ":  Blynk Cloud";
var exam2 = ":  LocalServer / Port";
var exam3 = ":  LocalServer / Port / Use SSL";
var exam4 = ":  Blynk Cloud / Port / Use SSL";
var examT = "Usage : blynk-client <auth> (optional) <server> <port> <ssl>";
  console.log("");
  console.log(examT);
  console.log("");
  console.log(examf, exam1);
  console.log("   ", examb);
  console.log("");
  console.log(examf, exam2);
  console.log("   ", examb, exams, examp1);
  console.log("");
  console.log(examf, exam3);
  console.log("   ", examb, exams, examp2, "ssl");
  console.log("");
  console.log(examf, exam4);
  console.log("   ", examb, "blynk-cloud.com", "8441", "ssl");
  console.log("");
  process.exit(1);
}

if ((process.argv[2]) && (process.argv[3]) && (process.argv[4]) && (process.argv[5] == 'ssl')) {
console.log("");
console.log("Auth   =",process.argv[2]);
console.log("Server =",process.argv[3]);
console.log("Port   =",process.argv[4]);
console.log("SSL    = ON");
var blynk = new Blynk.Blynk(process.argv[2], options = {
   connector : new Blynk.SslClient( options = { addr: process.argv[3], port: process.argv[4]} )
});
}

if ((process.argv[2]) && (process.argv[3]) && (process.argv[4]) && (!process.argv[5])) {
console.log("");
console.log("Auth   =",process.argv[2]);
console.log("Server =",process.argv[3]);
console.log("Port   =",process.argv[4]);
console.log("SSL    = OFF");
var blynk = new Blynk.Blynk(process.argv[2], options = {
  connector : new Blynk.TcpClient( options = { addr: process.argv[3], port: process.argv[4]} )
});
}

if ((process.argv[2]) && (process.argv[3]) && (!process.argv[4])) {
console.log("");
console.log("Auth   =",process.argv[2]);
console.log("Server =",process.argv[3]);
console.log("Port   = Unspecified - Using 8080");
console.log("SSL    = OFF");
var blynk = new Blynk.Blynk(process.argv[2], options = {
  connector : new Blynk.TcpClient( options = { addr: process.argv[3], port: "8080"} )
});
}



// if ((process.argv[2]) && (!process.argv[3])) {
// console.log("");
// console.log("Auth   =",process.argv[2]);
// console.log("Server = blynk-cloud.com");
// console.log("Port   = CHANGE - Using 8441");
// console.log("SSL    = ON");
// var blynk = new Blynk.Blynk(process.argv[2], options = {
//     connector : new Blynk.SslClient( options = { addr:"blynk-cloud.com", port: "8441"} )
// });
// }

if ((process.argv[2]) && (!process.argv[3])) {
console.log("");
console.log("Auth   =",process.argv[2]);
console.log("Server = blynk-cloud.com");
console.log("Port   = CHANGE - Using 8080");
console.log("SSL    = ON");
var blynk = new Blynk.Blynk(process.argv[2], options = {
    connector : new Blynk.TcpClient( options = { addr:"blynk-cloud.com", port: "8080"} )
});
}


if (!process.argv[2]) {
printusage();
process.exit(1);  
}

blynk.on('connect', function() {
  console.log("Blynk ready.");
});
1 Like