From 3f4628220b8c928ad13fd0c18cc8d70cb08092f5 Mon Sep 17 00:00:00 2001 From: Jesse Cotton Date: Mon, 2 Apr 2018 21:35:30 -0700 Subject: [PATCH 01/19] Enhance Orvibo logging --- Orvibo.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Orvibo.js b/Orvibo.js index 0de50c1..9e2494b 100644 --- a/Orvibo.js +++ b/Orvibo.js @@ -5,6 +5,8 @@ const Utils = require('./Utils'); const Settings = require('./OrviboSettings'); const EventEmitter = require('events').EventEmitter; +let logger = console; + let ORVIBO_KEY = Settings.ORVIBO_KEY; let LOG_PACKET = Settings.LOG_PACKET; let PLUG_INFO = Settings.plugInfo; @@ -18,7 +20,7 @@ const Orvibo = function(userSettings) { } if (ORVIBO_KEY === '') { - console.log('Please pass Orvibo PK key details via the constructor or add to OrviboSettings.js file. See Readme'); + logger.log('Please pass Orvibo PK key details via the constructor or add to OrviboSettings.js file. See Readme'); process.exit(1); } }; @@ -75,6 +77,7 @@ let handshakeHandler = function(plugPacket, socket, socketData) { name: getNameForUid(uid) }); respondAndSetData(pkData, socket, PacketBuilder.handshakePacket); + logger.log(`Connected ${pkData.uid} name = ${pkData.name}`); this.emit('plugConnected', {uid:pkData.uid, name: pkData.name}); }; @@ -84,6 +87,7 @@ let heartbeatHandler = function(plugPacket, socket, socketData) { uid: plugPacket.getUid() }); respondAndSetData(pkData, socket, PacketBuilder.heartbeatPacket); + logger.log(`Plug ${pkData.name} ${pkData.uid} sent heartbeat`); this.emit('gotHeartbeat', {uid:pkData.uid, name: pkData.name}); }; @@ -94,6 +98,7 @@ let stateUpdateHandler = function(plugPacket, socket, socketData) { state: plugPacket.getValue1() }); respondAndSetData(pkData, socket, PacketBuilder.comfirmStatePacket); + logger.log(`Plug ${pkData.name} ${pkData.uid} updated state ${pkData.state}`); this.emit('plugStateUpdated', {uid:pkData.uid, state: pkData.state, name: pkData.name}); }; @@ -125,7 +130,7 @@ Orvibo.prototype.startServer = function() { let self = this; let handlers = this.handlers(); - console.log(`Starting server Orvibo socket server on port ${port}`); + logger.log(`Starting server Orvibo socket server on port ${port}`); this.server = net.createServer(function(socket) { @@ -139,7 +144,7 @@ Orvibo.prototype.startServer = function() { let plugPacket = new Packet(data); if (!plugPacket.validCRC()) { - console.log('Got invalid CRC'); + logger.log('Got invalid CRC'); return; } @@ -149,7 +154,7 @@ Orvibo.prototype.startServer = function() { plugPacket.processPacket(socketData.encryptionKey); } - LOG_PACKET && plugPacket.logPacket("Socket -> "); + LOG_PACKET && plugPacket.logPacket('Socket -> '); let handler = handlers[plugPacket.getCommand()]; if (handler != null) { @@ -161,14 +166,15 @@ Orvibo.prototype.startServer = function() { socket.on('end', function () { let pkData = getData(socket.id); + logger.log(`Plug ${pkData.uid} - ${pkData.name} disconnected`); self.emit('plugDisconnected', {uid: pkData.uid, name: pkData.name}); delete packetData[socket.id]; plugConnections.splice(plugConnections.indexOf(socket), 1); }); socket.on('error', (err) => { - console.log(err); - console.log('error with socket ' + socket.id); + logger.log(err); + logger.log(`Plug ${socket.id} - ${socket.name} disconnected with error`); self.emit('plugDisconnectedWithError', getData(socket.id)); delete packetData[socket.id]; plugConnections.splice(plugConnections.indexOf(socket), 1); @@ -190,7 +196,7 @@ Orvibo.prototype.toggleSocket = function(uid) { } } if (socketId === null) { - console.log('Could not find socket ' + uid); + logger.log('Could not find socket ' + uid); return; } let socket = plugConnections.find(s => s.id === socketId); @@ -209,7 +215,7 @@ Orvibo.prototype.toggleSocket = function(uid) { socket.write(packet); } else { - console.log('Can not find socket '); + logger.log('Can not find socket '); } }; @@ -227,4 +233,8 @@ Orvibo.prototype.getConnectedSocket = function() { return sockets; }; -module.exports = Orvibo; \ No newline at end of file +Orvibo.prototype.setLogger = function(newLogger) { + logger = newLogger; +}; + +module.exports = Orvibo; From 8abb861cab29a1133cb2bad47c5299c9b59030e4 Mon Sep 17 00:00:00 2001 From: Jesse Cotton Date: Mon, 2 Apr 2018 21:37:21 -0700 Subject: [PATCH 02/19] Enhance settings handling --- Orvibo.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Orvibo.js b/Orvibo.js index 9e2494b..b15dd6b 100644 --- a/Orvibo.js +++ b/Orvibo.js @@ -11,13 +11,12 @@ let ORVIBO_KEY = Settings.ORVIBO_KEY; let LOG_PACKET = Settings.LOG_PACKET; let PLUG_INFO = Settings.plugInfo; -const Orvibo = function(userSettings) { +const Orvibo = function(userSettings = {}) { // Allow user to pass in settings - if (userSettings != null) { - ORVIBO_KEY = userSettings.ORVIBO_KEY; - LOG_PACKET = userSettings.LOG_PACKET; - PLUG_INFO = userSettings.plugInfo; - } + if('ORVIBO_KEY' in userSettings) ORVIBO_KEY = userSettings.ORVIBO_KEY; + if('plugInfo' in userSettings) PLUG_INFO = userSettings.plugInfo; + if('PLUG_INFO' in userSettings) PLUG_INFO = userSettings.PLUG_INFO; + if('LOG_PACKET' in userSettings) LOG_PACKET = userSettings.LOG_PACKET; if (ORVIBO_KEY === '') { logger.log('Please pass Orvibo PK key details via the constructor or add to OrviboSettings.js file. See Readme'); From 4d0c98c97aa0868a4a7b9158b5842a64eaafd0bd Mon Sep 17 00:00:00 2001 From: Jesse Cotton Date: Mon, 2 Apr 2018 21:39:12 -0700 Subject: [PATCH 03/19] Pluralize getConnectedSocket + alias previous name --- Orvibo.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Orvibo.js b/Orvibo.js index b15dd6b..a7df2c7 100644 --- a/Orvibo.js +++ b/Orvibo.js @@ -218,7 +218,7 @@ Orvibo.prototype.toggleSocket = function(uid) { } }; -Orvibo.prototype.getConnectedSocket = function() { +Orvibo.prototype.getConnectedSockets = function() { let sockets = []; for (const key of Object.keys(packetData)) { let socketData = getData(key); @@ -232,6 +232,8 @@ Orvibo.prototype.getConnectedSocket = function() { return sockets; }; +Orvibo.prototype.getConnectedSocket = Orvibo.prototype.getConnectedSockets; + Orvibo.prototype.setLogger = function(newLogger) { logger = newLogger; }; From ada0b421231d2d5ab0cbc74604ce87730bc1f9d3 Mon Sep 17 00:00:00 2001 From: Jesse Cotton Date: Mon, 2 Apr 2018 21:40:57 -0700 Subject: [PATCH 04/19] Add try-catch around packet decryption This guards against a service crash resulting from an occasional packet decryption error. --- Orvibo.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Orvibo.js b/Orvibo.js index a7df2c7..dbc1cb4 100644 --- a/Orvibo.js +++ b/Orvibo.js @@ -147,10 +147,15 @@ Orvibo.prototype.startServer = function() { return; } - if (plugPacket.packetTypeText() === 'pk') { - plugPacket.processPacket(ORVIBO_KEY); - } else { - plugPacket.processPacket(socketData.encryptionKey); + try { + if (plugPacket.packetTypeText() === 'pk') { + plugPacket.processPacket(ORVIBO_KEY); + } else { + plugPacket.processPacket(socketData.encryptionKey); + } + } catch(err) { + logger.log('Failed to parse packet: ' + err); + return; } LOG_PACKET && plugPacket.logPacket('Socket -> '); From 272adeac34d1e8f659f6e301b2f6cf0e26de103f Mon Sep 17 00:00:00 2001 From: Jesse Cotton Date: Mon, 2 Apr 2018 21:55:26 -0700 Subject: [PATCH 05/19] Bump version to 1.1.0 --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..79cf5ca --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# CHANGELOG + +## 1.1.0 + +* Add try-catch around packet decryption to guard against a service crash resulting from an occasional packet decryption error. +* Pluralize getConnectedSocket + alias previous name +* Enhance settings handling +* Enhance Orvibo logging + +## 1.0.0 + +Initial release diff --git a/package.json b/package.json index 6069dcb..dc01f1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orvibo-b25-server", - "version": "1.0.1", + "version": "1.1.0", "description": "A server to control the Orvibo B25 range of smart sockets", "main": "index.js", "scripts": { From 3439ae0d0907cb043b1c31a7b196ec50b9bbb463 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 22:47:46 +0100 Subject: [PATCH 06/19] docker file --- Dockerfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..10c16fe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:10 + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied +# where available (npm@5+) +COPY package*.json ./ + + +# Bundle app source +COPY . . + +EXPOSE 3000 10001 +CMD [ "node", "Example.js" ] \ No newline at end of file From 0dcc8ca4fad7a9ad02b50e20f67cd16850f29359 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 22:48:38 +0100 Subject: [PATCH 07/19] dockerignore --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..93f1361 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log From c8e3ed76e7b49396e29279df05cccea00b052e5c Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 23:36:42 +0100 Subject: [PATCH 08/19] dockerfile updates --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 10c16fe..6aabf53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,10 @@ WORKDIR /usr/src/app # where available (npm@5+) COPY package*.json ./ +RUN npm install # Bundle app source COPY . . -EXPOSE 3000 10001 +EXPOSE 3000 10001/udp CMD [ "node", "Example.js" ] \ No newline at end of file From 41cad85e854ba3ea88a63a0eeede404f728235c4 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 23:37:03 +0100 Subject: [PATCH 09/19] update example file --- Example.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Example.js b/Example.js index 7f70ef8..f6860a1 100644 --- a/Example.js +++ b/Example.js @@ -6,8 +6,8 @@ const httpPort = 3000; // Create a settings object to pass PK key and map sockets to names const settings = { - LOG_PACKET: false, //Show incoming packet data from the socket - ORVIBO_KEY: '', // put your PK key here as plain text (See Readme) + LOG_PACKET: true, //Show incoming packet data from the socket + ORVIBO_KEY: process.env.orviboPK, // put your PK key here as plain text (See Readme) plugInfo : [ // Add uid and a name so you can easily identify the connected sockets { @@ -16,9 +16,8 @@ const settings = { }, ], }; - +console.log(settings.ORVIBO_KEY) let orvibo = new Orvibo(settings); - // When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket; orvibo.on('plugConnected', ({uid, name}) => { console.log(`Connected ${uid} name = ${name}`); From e3021c8a10e7a42c606c5aee03108076e49bbb0e Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 23:37:18 +0100 Subject: [PATCH 10/19] lock to new version --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 2830cde..97d2c26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "orvibo-b25-server", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { From 5fd67de48be014d9552c33653ba3cc2737ecebaf Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 23:37:47 +0100 Subject: [PATCH 11/19] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7e087fe..b051c7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ node_modules +.vscode/launch.json From 09092049d0de168a2fcc359ac35b119299478129 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 23:38:40 +0100 Subject: [PATCH 12/19] remove console.log --- Example.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example.js b/Example.js index f6860a1..a33361c 100644 --- a/Example.js +++ b/Example.js @@ -16,7 +16,7 @@ const settings = { }, ], }; -console.log(settings.ORVIBO_KEY) + let orvibo = new Orvibo(settings); // When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket; orvibo.on('plugConnected', ({uid, name}) => { From 33150da9c8670edf33f4b55b58bc76d93a14db79 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sat, 13 Jul 2019 23:39:04 +0100 Subject: [PATCH 13/19] dockerfile --- Dockerfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6aabf53..4956a50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,13 @@ FROM node:10 -# Create app directory WORKDIR /usr/src/app -# Install app dependencies -# A wildcard is used to ensure both package.json AND package-lock.json are copied -# where available (npm@5+) COPY package*.json ./ RUN npm install -# Bundle app source COPY . . EXPOSE 3000 10001/udp + CMD [ "node", "Example.js" ] \ No newline at end of file From 57d97b0d9b4906530ac33acf6c16091f0415a62d Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Sun, 14 Jul 2019 10:27:37 +0100 Subject: [PATCH 14/19] updates --- Dockerfile | 4 ++-- Example.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4956a50..4815ae7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,6 @@ RUN npm install COPY . . -EXPOSE 3000 10001/udp +EXPOSE 3000 10001 -CMD [ "node", "Example.js" ] \ No newline at end of file +CMD [ "node", "Example.js" ] diff --git a/Example.js b/Example.js index a33361c..bf67162 100644 --- a/Example.js +++ b/Example.js @@ -11,8 +11,8 @@ const settings = { plugInfo : [ // Add uid and a name so you can easily identify the connected sockets { - uid :'53dd7fe74de7', - name: "Lamp in Kitchen" + uid :'5ccf7f22fba4', + name: "3D Printer" }, ], }; @@ -73,4 +73,4 @@ httpServer.listen(httpPort, (err) => { return console.log('something bad happened', err) } console.log(`http server is listening on ${httpPort}`) -}); \ No newline at end of file +}); From ef637349b144089b911d214cb1ff5424f69a4f6b Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sun, 14 Jul 2019 11:19:29 +0100 Subject: [PATCH 15/19] pass in plug via envvar --- Example.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Example.js b/Example.js index bf67162..89319e2 100644 --- a/Example.js +++ b/Example.js @@ -4,19 +4,24 @@ const url = require('url'); const httpPort = 3000; +const table = +process.env.plugArray.split(",") //["key:value","key:value"] + .map(pair => pair.split(":")); //[["key","value"],["key","value"]] + + const plugArray = {}; +table.forEach(([key,value]) => plugArray[key] = value); + + // Create a settings object to pass PK key and map sockets to names const settings = { LOG_PACKET: true, //Show incoming packet data from the socket ORVIBO_KEY: process.env.orviboPK, // put your PK key here as plain text (See Readme) plugInfo : [ // Add uid and a name so you can easily identify the connected sockets - { - uid :'5ccf7f22fba4', - name: "3D Printer" - }, + plugArray ], }; - + let orvibo = new Orvibo(settings); // When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket; orvibo.on('plugConnected', ({uid, name}) => { From 10af45b3f570b0ace337d87fc258ecd26180bf5c Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sun, 14 Jul 2019 11:37:20 +0100 Subject: [PATCH 16/19] move to Docker.js --- Docker.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- Example.js | 22 ++++++--------- 3 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 Docker.js diff --git a/Docker.js b/Docker.js new file mode 100644 index 0000000..031a1fa --- /dev/null +++ b/Docker.js @@ -0,0 +1,80 @@ +const Orvibo = require('./Orvibo'); +const http = require('http'); +const url = require('url'); + +const httpPort = 3000; + +const table = +process.env.plugArray.split(",") //["key:value","key:value"] + .map(pair => pair.split(":")); //[["key","value"],["key","value"]] + + const plugArray = {}; +table.forEach(([key,value]) => plugArray[key] = value); + + +// Create a settings object to pass PK key and map sockets to names +const settings = { + LOG_PACKET: true, //Show incoming packet data from the socket + ORVIBO_KEY: process.env.orviboPK, + plugInfo : [ + plugArray + ], +}; + +let orvibo = new Orvibo(settings); +// When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket; +orvibo.on('plugConnected', ({uid, name}) => { + console.log(`Connected ${uid} name = ${name}`); +}); + +// If the socket state is updated this event will fire +orvibo.on('plugStateUpdated', ({uid, state , name}) => { + console.log(`Plug ${name} ${uid} updated state ${state}`); +}); + +// The plug sends a hearbeat to let the server know it's still alive +orvibo.on('gotHeartbeat', ({uid, name}) => { + console.log(`Plug ${name} ${uid} sent heartbeat`); +}); + +// Called when the plug disconnects +orvibo.on('plugDisconnected', ({uid, name }) => { + console.log(`Plug ${uid} - ${name} disconnected`); +}); + +// Called when the plug disconnects with an error ie it's been unplugged +orvibo.on('plugDisconnectedWithError', ({uid, name }) => { + console.log(`Plug ${uid} - ${name} disconnected with error`); +}); + + + +// Start the Orvibo socket server +orvibo.startServer(); + +// Create a basic example HTTP server +// If there are no parameters it will return the uid, state, modelId and name of the socket +// You can then use the uid to toggle the state of the switch like +// http://localhost:3000?uid=5dcf7ff76e7a + +const requestHandler = (request, response) => { + response.writeHead(200, {'Content-Type': 'application/json'}); + let q = url.parse(request.url, true).query; + if (q.uid != null) { + orvibo.toggleSocket(q.uid); + } + + // Get all currently connected sockets, their names and states + let sockets = orvibo.getConnectedSocket(); + + response.end(JSON.stringify(sockets)); +}; + +const httpServer = http.createServer(requestHandler); + +httpServer.listen(httpPort, (err) => { + if (err) { + return console.log('something bad happened', err) + } + console.log(`http server is listening on ${httpPort}`) +}); diff --git a/Dockerfile b/Dockerfile index 4815ae7..f16a057 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ COPY . . EXPOSE 3000 10001 -CMD [ "node", "Example.js" ] +CMD [ "node", "Docker.js" ] diff --git a/Example.js b/Example.js index 89319e2..7f70ef8 100644 --- a/Example.js +++ b/Example.js @@ -4,25 +4,21 @@ const url = require('url'); const httpPort = 3000; -const table = -process.env.plugArray.split(",") //["key:value","key:value"] - .map(pair => pair.split(":")); //[["key","value"],["key","value"]] - - const plugArray = {}; -table.forEach(([key,value]) => plugArray[key] = value); - - // Create a settings object to pass PK key and map sockets to names const settings = { - LOG_PACKET: true, //Show incoming packet data from the socket - ORVIBO_KEY: process.env.orviboPK, // put your PK key here as plain text (See Readme) + LOG_PACKET: false, //Show incoming packet data from the socket + ORVIBO_KEY: '', // put your PK key here as plain text (See Readme) plugInfo : [ // Add uid and a name so you can easily identify the connected sockets - plugArray + { + uid :'53dd7fe74de7', + name: "Lamp in Kitchen" + }, ], }; - + let orvibo = new Orvibo(settings); + // When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket; orvibo.on('plugConnected', ({uid, name}) => { console.log(`Connected ${uid} name = ${name}`); @@ -78,4 +74,4 @@ httpServer.listen(httpPort, (err) => { return console.log('something bad happened', err) } console.log(`http server is listening on ${httpPort}`) -}); +}); \ No newline at end of file From 00d6dd99f43278ab394f2be1593b18cfa94e1a02 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sun, 14 Jul 2019 11:44:32 +0100 Subject: [PATCH 17/19] readme updates --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 97b0478..d4f9208 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,15 @@ A list of Orvibo devices, confirmed by contributors, that work with this project | Orvibo Smart Socket (US/CAD) | S25 | @wichopy | | Orvibo Smart Socket (UK/GB) | B25UK | @valchonedelchev | +## Docker + +I have extened this project to also run in a docker container. + +PK and PlugArray can be passed in via enviroment variables. + +orviboPK = 'xxxxx' +plugArray = 'uid:MACADDRESS,name:PRINTERNAME' + ## Contributing I'm more than happy for other people to contribute to this library just send a pull request. From fe073303b1b0fc8baf1fe8e4c69c8b477b7d37e1 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sun, 14 Jul 2019 13:29:25 +0100 Subject: [PATCH 18/19] update for working plugArray --- Docker.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Docker.js b/Docker.js index 031a1fa..5e5abde 100644 --- a/Docker.js +++ b/Docker.js @@ -4,23 +4,28 @@ const url = require('url'); const httpPort = 3000; -const table = -process.env.plugArray.split(",") //["key:value","key:value"] - .map(pair => pair.split(":")); //[["key","value"],["key","value"]] - - const plugArray = {}; -table.forEach(([key,value]) => plugArray[key] = value); - +const createArray = str => { + // split on each comma + const arr = str.split(','); + // put back elements by pairs + const pairs = []; + for (let i=0; i { @@ -65,7 +70,8 @@ const requestHandler = (request, response) => { } // Get all currently connected sockets, their names and states - let sockets = orvibo.getConnectedSocket(); + // let sockets = orvibo.getConnectedSocket(); + let sockets = [{"name":"3D Printer","state":1,"uid":"5ccf7f22fba4","modelId":"f8b11bed724647e98bd07a66dca6d5b6"}] response.end(JSON.stringify(sockets)); }; From 9da3922ca6afb014251f5d02217ec89db24d3687 Mon Sep 17 00:00:00 2001 From: karl0ss Date: Sun, 14 Jul 2019 15:49:58 +0100 Subject: [PATCH 19/19] upversion --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dc01f1b..87fcbb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orvibo-b25-server", - "version": "1.1.0", + "version": "1.2.0", "description": "A server to control the Orvibo B25 range of smart sockets", "main": "index.js", "scripts": {