let Arduino node only send changes of values as stated in docs.

This commit is contained in:
Dave Conway-Jones 2018-04-29 13:41:38 +01:00
parent e57e2545d6
commit 5019f68c9c
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 14 additions and 4 deletions

View File

@ -56,24 +56,34 @@ module.exports = function(RED) {
if (typeof this.serverConfig === "object") {
this.board = this.serverConfig.board;
var node = this;
node.oldval = "";
node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"});
var doit = function() {
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
if (node.state === "ANALOG") {
node.board.pinMode(node.pin, 0x02);
node.board.analogRead(node.pin, function(v) {
node.send({payload:v, topic:"A"+node.pin});
if (v !== node.oldval) {
node.oldval = v;
node.send({payload:v, topic:"A"+node.pin});
}
});
}
if (node.state === "INPUT") {
node.board.pinMode(node.pin, 0x00);
node.board.digitalRead(node.pin, function(v) {
node.send({payload:v, topic:node.pin});
if (v !== node.oldval) {
node.oldval = v;
node.send({payload:v, topic:node.pin});
}
});
}
if (node.state == "STRING") {
node.board.on('string', function(v) {
node.send({payload:v, topic:"string"});
if (v !== node.oldval) {
node.oldval = v;
node.send({payload:v, topic:"string"});
}
});
}
// node.board.on('close', function() {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-arduino",
"version" : "0.0.14",
"version" : "0.0.15",
"description" : "A Node-RED node to talk to an Arduino running firmata",
"dependencies" : {
"firmata" : "~0.17.0"