Skip to content

Commit

Permalink
v0.1.3 - Fix minor change on zero metric values for spB listener node
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-fg committed Dec 17, 2023
1 parent a0fb6f8 commit c589f6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions mqtt-sparkplug-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ module.exports = function(RED) {
// Send Commands
this.on("input",function(msg,send,done) {

// this.debug(`Msg value: ${msg.payload}, Type:, ${typeof msg.payload}`);
// this.debug(`Msg value: ${msg.payload}, Type:, ${typeof msg.payload}`);

// Check if the payload is correct type
if ( msg.hasOwnProperty("payload") && (typeof msg.payload === 'number' || typeof msg.payload === 'string' || typeof msg.payload === 'boolean' )){
Expand All @@ -1334,7 +1334,7 @@ module.exports = function(RED) {
var _m = { "type" : this.metricsCmd[_cmd]["dataType"], "value": msg.payload, "name": _cmd};
_metrics.push(_m);

// this.log(JSON.stringify(_metrics, null, 2));
// this.debug(JSON.stringify(_metrics, null, 2));

// Send CMD if broker is connected, otherwise data will be lost.
if (this.brokerConn.connected) {
Expand Down Expand Up @@ -1402,6 +1402,7 @@ module.exports = function(RED) {
var topic = topic_;

// node.debug(`Data received on topic: ${topic}`);
// node.debug(`${JSON.stringify(payload)}`);

// Check msg type and if we need to parse it.
let msgType = topic.split('/')[2].substring(1); // Get message type without first character
Expand All @@ -1423,13 +1424,13 @@ module.exports = function(RED) {
if( node.metricsData.hasOwnProperty(m.name)){

// Check if the value is valid
if(m.value)
if(m.value != null)
_validMessages[m.name] = { "payload": m.value, "topic": m.name, "type": m.type};
}
}
})

// node.log(JSON.stringify(_validMessages, null, 2));
// node.debug(JSON.stringify(_validMessages));

// Generate the output messages
if(_validMessages){
Expand All @@ -1444,7 +1445,7 @@ module.exports = function(RED) {
_messages.push(null); // No message
}

// node.log(JSON.stringify(_messages, null, 2));
// node.debug(JSON.stringify(_messages));

node.send(_messages); // Send the parse metrics messages to the different outputs.
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-mqtt-sparkplug-wrapper",
"version": "0.1.2",
"version": "0.1.3",
"repository": {
"type": "git",
"url": "https://github.com/javier-fg/node-red-mqtt-sparkplug-wrapper"
Expand Down

0 comments on commit c589f6f

Please sign in to comment.