Skip to content

Commit 5c92b2a

Browse files
committed
MQTT (plain): extracts JSON payload for autotag when # is used at the end of subscribed topic.
1 parent 9fd64b5 commit 5c92b2a

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/mqtt-sparkplug/index.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const LoadConfig = require('./load-config')
3434
const Redundancy = require('./redundancy')
3535
const AutoTag = require('./auto-tag')
3636
const { castSparkplugValue: castSparkplugValue } = require('./cast')
37+
const autoTag = require('./auto-tag')
3738

3839
const SparkplugNS = 'spBv1.0'
3940
const DevicesList = [] // contains either EoN nodes or devices
@@ -1406,6 +1407,15 @@ async function sparkplugProcess(
14061407
// match = true
14071408
}
14081409

1410+
if (
1411+
autoTag &&
1412+
elem.endsWith('#') &&
1413+
topic.startsWith(elem.substring(0, elem.length - 1))
1414+
) {
1415+
let JsonValue = TryPayloadAsRJson(payload)
1416+
EnqueueJsonValue(JsonValue, topic)
1417+
}
1418+
14091419
// keep testing for match when JSONPathPlus syntax is used
14101420
if (elem.indexOf('$.') === -1) return
14111421

@@ -1445,18 +1455,6 @@ async function sparkplugProcess(
14451455
}
14461456
}
14471457
})
1448-
1449-
// if (match) return
1450-
1451-
// // try to detect payload as JSON or RJSON
1452-
1453-
// if (payload.length > 20000) {
1454-
// Log.log(logMod + 'Payload too big!')
1455-
// return
1456-
// }
1457-
1458-
// let JsonValue = TryPayloadAsRJson(payload)
1459-
// EnqueueJsonValue(JsonValue, topic)
14601458
}
14611459
)
14621460

@@ -2299,13 +2297,13 @@ function EnqueueJsonValue(JsonValue, protocolSourceObjectAddress) {
22992297
}
23002298

23012299
if (isNaN(value)) value = 0
2302-
if (JsonValue === null) JsonValue = {}
2300+
if (JsonValue === null) JsonValue = ""
23032301

23042302
ValuesQueue.enqueue({
23052303
protocolSourceObjectAddress: protocolSourceObjectAddress,
23062304
value: value,
23072305
valueString: valueString,
2308-
valueJson: JsonValue,
2306+
valueJson: JSON.stringify(JsonValue),
23092307
invalid: false,
23102308
transient: false,
23112309
causeOfTransmissionAtSource: '3',

0 commit comments

Comments
 (0)