Quellcode durchsuchen

add client files

bhitch vor 2 Jahren
Ursprung
Commit
b5cf4d029d
2 geänderte Dateien mit 62 neuen und 0 gelöschten Zeilen
  1. 61 0
      ICGLabelClient.js
  2. 1 0
      whoami

+ 61 - 0
ICGLabelClient.js

@@ -0,0 +1,61 @@
+const WebSocket = require('ws');
+var exec = require('child_process').exec;
+const fs = require("fs");
+var whoami;
+try{
+        var tempObj  = fs.readFileSync('whoami');
+          tempRead = JSON.parse(tempObj);
+          whoami = tempRead.Name;
+          console.log("I am '" + whoami + "'");
+} catch (e) {
+	console.log("I could not open whoami, I'm going to exit");
+    process.exit();
+}
+
+
+var ws;
+
+var wsConnect = function(){
+  ws =  new WebSocket('ws://10.10.10.2:8080/');
+  ws.on('open', function open() {
+      console.log("connected");
+  })
+
+  ws.on('message', function incoming(data, flags) {
+        console.log("Received : " + data);
+        try{
+                myObj = JSON.parse(data);
+                console.log(myObj);
+                console.log(myObj.labelSource);
+                if(whoami == myObj.who){
+                        console.log("I am " + whoami + ", this message was for me");
+                        if(myObj.label){
+                                fs.writeFileSync('internetShipLabel.zpl', myObj.label);
+                                printLabel('internetShipLabel.zpl');
+                        }
+                }else{
+                        console.log("this Message was not for me");
+                }
+
+        } catch(e){console.log(e);}
+  })
+
+  ws.on('error', function(error){
+        console.log('Connection Error: ' + error.toString());
+        //process.exit();
+  });
+
+  ws.on('close', function() {
+        console.log('socket close');
+        setTimeout(wsConnect, 30*1000);
+  });
+}
+
+function printLabel(filename){
+    console.log('trying to print');
+        exec('cat ' + filename + ' > /dev/usb/lp0', function(error, stdout, stderr) {
+        });
+}
+
+
+wsConnect(); 

+ 1 - 0
whoami

@@ -0,0 +1 @@
+{"Name":"QA"}