node-red-contrib-blynk-ws
Advanced tools
Comparing version 0.2.0 to 0.3.0
170
blynk-ws.js
@@ -408,3 +408,7 @@ /** | ||
BlynkClientNode.prototype.registerInputNode = function (handler) { | ||
this.log("Register input node" + " - type: " + handler.nodeType + " pin: " + handler.pin); | ||
var pinlog = ''; | ||
if(handler.pin != undefined) { | ||
pinlog = " pin: " + handler.pin; | ||
} | ||
this.log("Register input node" + " - type: " + handler.nodeType + pinlog); | ||
this._inputNodes.push(handler); | ||
@@ -414,3 +418,7 @@ }; | ||
BlynkClientNode.prototype.removeInputNode = function (handler) { | ||
this.log("Remove input node" + " - type: " + handler.nodeType + " pin: " + handler.pin); | ||
var pinlog = ''; | ||
if(handler.pin != undefined) { | ||
pinlog = " pin: " + handler.pin; | ||
} | ||
this.log("Remove input node" + " - type: " + handler.nodeType + pinlog); | ||
this._inputNodes.forEach(function (node, i, inputNodes) { | ||
@@ -721,2 +729,9 @@ if (node === handler) { | ||
this.pin = n.pin; | ||
this.pinmode = n.pinmode; | ||
if(this.pinmode == 1) | ||
this.connected_label = "connected to dynamic pin"; | ||
else | ||
this.connected_label = "connected to pin V" + this.pin; | ||
@@ -739,3 +754,3 @@ this.serverConfig = RED.nodes.getNode(this.server); | ||
shape: "dot", | ||
text: "connected to pin V" + node.pin | ||
text: node.connected_label | ||
}); | ||
@@ -762,3 +777,15 @@ }); | ||
var subject = msg.topic ? msg.topic : payload; | ||
node.serverConfig.virtualWrite(node.pin, payload); | ||
var pin = node.pin; | ||
if(node.pinmode == 1) { | ||
if (!msg.hasOwnProperty("pin")) { | ||
node.warn("Write node - Setting \"pin mode\" to \"dynamic\" but no msg.pin found."); | ||
return; | ||
} | ||
if(msg.pin<0 || msg.pin>127) { | ||
node.warn("Write node - The msg.pin must be between 0 and 127."); | ||
return; | ||
} | ||
pin = msg.pin; | ||
} | ||
node.serverConfig.virtualWrite(pin, payload); | ||
} | ||
@@ -825,3 +852,9 @@ }); | ||
this.prop = n.prop; | ||
this.pinmode = n.pinmode; | ||
if(this.pinmode == 1) | ||
this.connected_label = "connected to dynamic pin"; | ||
else | ||
this.connected_label = "connected to pin V" + this.pin; | ||
this.serverConfig = RED.nodes.getNode(this.server); | ||
@@ -843,3 +876,3 @@ if (!this.serverConfig) { | ||
shape: "dot", | ||
text: "connected to pin V" + node.pin | ||
text: node.connected_label | ||
}); | ||
@@ -867,2 +900,15 @@ }); | ||
var prop = node.prop; | ||
var pin = node.pin; | ||
if(node.pinmode == 1) { | ||
if (!msg.hasOwnProperty("pin")) { | ||
node.warn("Set Property node - Setting \"pin mode\" to \"dynamic\" but no msg.pin found."); | ||
return; | ||
} | ||
if(msg.pin<0 || msg.pin>127) { | ||
node.warn("Set Property node - The msg.pin must be between 0 and 127."); | ||
return; | ||
} | ||
pin = msg.pin; | ||
} | ||
if (msg.hasOwnProperty("prop") && node.serverConfig && node.serverConfig.logged) { | ||
@@ -872,3 +918,7 @@ prop = Buffer.isBuffer(msg.prop) ? msg.prop : RED.util.ensureString(msg.prop); | ||
if(prop!=='bycode'){ //single propery | ||
node.serverConfig.setProperty(node.pin, prop, payload); | ||
if(prop == ''){ | ||
node.warn("Set Property node - Please select a property."); | ||
return; | ||
} | ||
node.serverConfig.setProperty(pin, prop, payload); | ||
} | ||
@@ -879,15 +929,15 @@ else { //multiple property | ||
var label = Buffer.isBuffer(msg.label) ? msg.label : RED.util.ensureString(msg.label); | ||
node.serverConfig.setProperty(node.pin, 'label', label); | ||
node.serverConfig.setProperty(pin, 'label', label); | ||
} | ||
if (msg.hasOwnProperty("color") && node.serverConfig && node.serverConfig.logged) { | ||
var color = Buffer.isBuffer(msg.color) ? msg.color : RED.util.ensureString(msg.color); | ||
node.serverConfig.setProperty(node.pin, 'color', color); | ||
node.serverConfig.setProperty(pin, 'color', color); | ||
} | ||
if (msg.hasOwnProperty("min") && node.serverConfig && node.serverConfig.logged) { | ||
var min = Buffer.isBuffer(msg.min) ? msg.min : RED.util.ensureString(msg.min); | ||
node.serverConfig.setProperty(node.pin, 'min', min); | ||
node.serverConfig.setProperty(pin, 'min', min); | ||
} | ||
if (msg.hasOwnProperty("max") && node.serverConfig && node.serverConfig.logged) { | ||
var max = Buffer.isBuffer(msg.max) ? msg.max : RED.util.ensureString(msg.max); | ||
node.serverConfig.setProperty(node.pin, 'max', max); | ||
node.serverConfig.setProperty(pin, 'max', max); | ||
} | ||
@@ -898,7 +948,7 @@ //buttons | ||
var onlabel = Buffer.isBuffer(msg.onlabel) ? msg.onlabel : RED.util.ensureString(msg.onlabel); | ||
node.serverConfig.setProperty(node.pin, 'onLabel', onlabel); | ||
node.serverConfig.setProperty(pin, 'onLabel', onlabel); | ||
} | ||
if (msg.hasOwnProperty("offlabel")){ | ||
var offlabel = Buffer.isBuffer(msg.offlabel) ? msg.offlabel : RED.util.ensureString(msg.offlabel); | ||
node.serverConfig.setProperty(node.pin, 'offLabel', offlabel); | ||
node.serverConfig.setProperty(pin, 'offLabel', offlabel); | ||
} | ||
@@ -908,3 +958,3 @@ } | ||
else if (msg.hasOwnProperty("labels") && node.serverConfig && node.serverConfig.logged) { | ||
node.serverConfig.setProperty(node.pin, 'labels', msg.labels); | ||
node.serverConfig.setProperty(pin, 'labels', msg.labels); | ||
} | ||
@@ -915,6 +965,5 @@ //music player | ||
if (msg.isonplay) isonplay = true; | ||
node.serverConfig.setProperty(node.pin, 'isonplay', isonplay); | ||
node.serverConfig.setProperty(pin, 'isonplay', isonplay); | ||
} | ||
} | ||
@@ -1015,2 +1064,9 @@ } | ||
} | ||
if(!msg.hasOwnProperty("text") && !msg.hasOwnProperty("text1") && !msg.hasOwnProperty("clear") && msg.hasOwnProperty("payload")){ | ||
var payload = Buffer.isBuffer(msg.payload) ? msg.payload : RED.util.ensureString(msg.payload); | ||
if(payload != '' && payload.length > 1 ){ | ||
node.warn("## Blynk LCD node does not use the msg.payload property! ## You must use the property msg.text or msg.text1 to write to the first or second line."); | ||
} | ||
} | ||
} | ||
@@ -1023,4 +1079,13 @@ }); | ||
RED.nodes.createNode(this, n); | ||
this.server = n.client; | ||
this.queue = n.queue; | ||
this.rate = 1000 * (n.rate > 0 ? n.rate : 1); | ||
this.buffer = []; | ||
this.intervalID = -1; | ||
var node = this; | ||
this.server = n.client; | ||
//node.log(this); | ||
@@ -1032,2 +1097,4 @@ this.serverConfig = RED.nodes.getNode(this.server); | ||
// TODO: nls | ||
this.log("Register notify node" + " - on client: " + this.serverConfig.name); | ||
this.serverConfig.on('opened', function(n) { | ||
@@ -1041,6 +1108,10 @@ node.status({ | ||
this.serverConfig.on('connected', function(n) { | ||
var queuestr = ""; | ||
if (node.queue) { | ||
queuestr = " - queue: 0"; | ||
} | ||
node.status({ | ||
fill: "green", | ||
shape: "dot", | ||
text: "connected" + n | ||
text: "connected" + queuestr | ||
}); | ||
@@ -1064,3 +1135,56 @@ }); | ||
this.on("input", function(msg) { | ||
if (msg.hasOwnProperty("payload") && node.serverConfig && node.serverConfig.logged) { | ||
node.reportDepth = function() { | ||
if (!node.busy) { | ||
node.busy = setTimeout(function() { | ||
if (node.buffer.length > 0) { | ||
node.status({ | ||
fill: "green", | ||
shape: "dot", | ||
text: "connected - queue: " + node.buffer.length, | ||
}); | ||
} else { | ||
node.status({ | ||
fill: "green", | ||
shape: "dot", | ||
text: "connected - queue: 0", | ||
}); | ||
} | ||
node.busy = null; | ||
},500); | ||
} | ||
}; | ||
if (node.queue) { | ||
node.log("queue"); | ||
if ( node.intervalID !== -1) { | ||
node.buffer.push(msg); | ||
node.reportDepth(); | ||
} | ||
else { | ||
//node.send(msg); | ||
if (msg.hasOwnProperty("payload") && node.serverConfig && node.serverConfig.logged) { | ||
var payload = Buffer.isBuffer(msg.payload) ? msg.payload : RED.util.ensureString(msg.payload); | ||
node.serverConfig.sendNotify(payload); | ||
} | ||
node.reportDepth(); | ||
node.intervalID = setInterval(function() { | ||
if (node.buffer.length === 0) { | ||
clearInterval(node.intervalID); | ||
node.intervalID = -1; | ||
} | ||
if (node.buffer.length > 0) { | ||
//node.send(node.buffer.shift()); | ||
var tempmsg = node.buffer.shift() | ||
if (tempmsg.hasOwnProperty("payload") && node.serverConfig && node.serverConfig.logged) { | ||
var payload = Buffer.isBuffer(tempmsg.payload) ? tempmsg.payload : RED.util.ensureString(tempmsg.payload); | ||
node.serverConfig.sendNotify(payload); | ||
} | ||
} | ||
node.reportDepth(); | ||
},node.rate); | ||
} | ||
} | ||
else if (msg.hasOwnProperty("payload") && node.serverConfig && node.serverConfig.logged) { | ||
var payload = Buffer.isBuffer(msg.payload) ? msg.payload : RED.util.ensureString(msg.payload); | ||
@@ -1070,2 +1194,8 @@ node.serverConfig.sendNotify(payload); | ||
}); | ||
this.on("close", function() { | ||
clearInterval(node.intervalID); | ||
clearTimeout(node.busy); | ||
node.buffer = []; | ||
node.status({}); | ||
}); | ||
} | ||
@@ -1163,2 +1293,2 @@ RED.nodes.registerType("blynk-ws-out-notify", BlynkOutNotifyNode); | ||
}; | ||
}; |
@@ -9,2 +9,12 @@ # Changelog | ||
## [0.3.0] - 2017-12-12 | ||
### Added | ||
- Node - *Notify* - Implemented queue messages | ||
- Node - *Write* - Pin mode (Fixed / Dynamic) pass pin number in msg.pin variable | ||
- Node - *Set Property* - Pin mode (Fixed / Dynamic) pass pin number in msg.pin variable | ||
### Changed | ||
- Node - *LCD* - Warning on incorrect use of msg.payload property | ||
- Fixed some log messages | ||
## [0.2.0] - 2017-09-18 | ||
@@ -25,3 +35,3 @@ ### Added | ||
- Display the number of pins on the status of the nodes, | ||
- Node - * Notification * to send push notifications on the smartphone | ||
- Node - * Notify * to send push notifications on the smartphone | ||
- Node - * Set Property * to set the property of any widget | ||
@@ -38,4 +48,5 @@ - Node - * App Event * for the connection and disconnect event of the app | ||
[Unreleased]: https://github.com/gablau/node-red-contrib-blynk-ws/compare/v0.2.0...HEAD | ||
[0.2.0]: https://github.com/gablau/node-red-contrib-blynk-ws/compare/v0.1.0...v0.2.0 | ||
[Unreleased]: https://github.com/gablau/node-red-contrib-blynk-ws/compare/0.3.0...HEAD | ||
[0.3.0]: https://github.com/gablau/node-red-contrib-blynk-ws/compare/0.2.0...0.3.0 | ||
[0.2.0]: https://github.com/gablau/node-red-contrib-blynk-ws/compare/0.1.0...0.2.0 | ||
{ | ||
"name": "node-red-contrib-blynk-ws", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Node Red integration with Blynk App and Server through websockets", | ||
@@ -5,0 +5,0 @@ "main": "blynk-ws.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85286
1141