Skip to content

Commit bc1868e

Browse files
authored
Merge pull request #179 from json-scada/master
Fixes for MQTT and AdminUI
2 parents ca1c06d + eb5a9e1 commit bc1868e

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/AdminUI/src/components/TagsTab.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@
852852
853853
const closeEditTag = () => {
854854
dialogEditTag.value = false
855+
fetchTags()
855856
}
856857
857858
const closeDeleteTag = () => {
@@ -972,12 +973,12 @@
972973
}
973974
974975
const addNewProtocolDestination = async () => {
975-
editedTag.protocolDestinations.push(newProtocolDestination.value)
976+
editedTag.value.protocolDestinations.push(newProtocolDestination.value)
976977
dialogAddProtocolDestination.value = false
977978
}
978979
979980
const addNewParcel = async () => {
980-
editedTag.parcels.push(newParcel.value)
981+
editedTag.value.parcels.push(newParcel.value)
981982
dialogAddParcel.value = false
982983
}
983984

src/mqtt-sparkplug/app-defs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
ENV_PREFIX: 'JS_MQTTSPB_',
2323
AUTOTAG_PREFIX: 'MQTT',
2424
MSG: '{json:scada} - MQTT-Sparkplug-B Client Driver',
25-
VERSION: '0.2.0',
25+
VERSION: '0.2.1',
2626
MAX_QUEUEDMETRICS: 10000,
2727
SPARKPLUG_PUBLISH_INTERVAL: 777,
2828
SPARKPLUG_COMPRESS_DBIRTH: false,
@@ -34,4 +34,5 @@ module.exports = {
3434
MQTT_CONNECTION_TIMEOUT: 30,
3535
MQTT_CONNECTION_KEEPALIVE: 15,
3636
SECONDS_BETWEEN_NODE_REQUESTS: 300,
37+
SECONDS_BETWEEN_REBIRTHS: 30,
3738
}

src/mqtt-sparkplug/index.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const SparkplugPublishQueue = new Queue() // queue of values to publish as Spark
4343
let SparkplugDeviceBirthed = false
4444
let AutoCreateTags = true
4545
const MongoStatus = { HintMongoIsConnected: false }
46+
let LastNodeRebirth = 0
4647

4748
;(async () => {
4849
const jsConfig = LoadConfig() // load and parse config file
@@ -1144,16 +1145,22 @@ async function sparkplugProcess(
11441145

11451146
spClient.handle.on('error', function (error) {
11461147
Log.log(logMod + "Event: Can't connect" + error)
1148+
if (spClient?.handle) spClient.handle.stop()
1149+
spClient.handle = null
11471150
})
11481151

11491152
spClient.handle.on('close', function () {
11501153
SparkplugDeviceBirthed = false
11511154
Log.log(logMod + 'Event: Connection Closed')
1155+
if (spClient?.handle) spClient.handle.stop()
1156+
spClient.handle = null
11521157
})
11531158

11541159
spClient.handle.on('offline', function () {
11551160
SparkplugDeviceBirthed = false
11561161
Log.log(logMod + 'Event: Connection Offline...')
1162+
if (spClient?.handle) spClient.handle.stop()
1163+
spClient.handle = null
11571164
})
11581165

11591166
// Create 'birth' handler
@@ -1406,17 +1413,16 @@ async function sparkplugProcess(
14061413
if (elem) {
14071414
// test if published topic matches subscribed element
14081415
if (topic == elem) {
1409-
let JsonValue = TryPayloadAsRJson(payload)
1416+
const JsonValue = TryPayloadAsRJson(payload)
14101417
EnqueueJsonValue(JsonValue, topic)
1411-
// match = true
14121418
}
14131419

14141420
if (
14151421
autoTag &&
14161422
elem.endsWith('#') &&
14171423
topic.startsWith(elem.substring(0, elem.length - 1))
14181424
) {
1419-
let JsonValue = TryPayloadAsRJson(payload)
1425+
const JsonValue = TryPayloadAsRJson(payload)
14201426
EnqueueJsonValue(JsonValue, topic)
14211427
}
14221428

@@ -1425,7 +1431,7 @@ async function sparkplugProcess(
14251431

14261432
// when used '*~' at the end of JSONPathPlus explode property names
14271433
if (elem.endsWith('*~')) {
1428-
let jpt = JsonPathTopic(elem)
1434+
const jpt = JsonPathTopic(elem)
14291435
if (jpt.jsonPath !== '' && topicMatchSub(topic)(jpt.topic)) {
14301436
const jpPropNames = JSONPath({
14311437
path: jpt.jsonPath,
@@ -1434,7 +1440,9 @@ async function sparkplugProcess(
14341440
})
14351441
jpPropNames.forEach((propName) => {
14361442
let newTopic = elem.replace('*~', propName)
1437-
let jptNew = JsonPathTopic(newTopic)
1443+
const jptNew = JsonPathTopic(newTopic)
1444+
newTopic = newTopic.replace('$.', '')
1445+
14381446
// extract value from payload using JSON PATH
14391447
const jpRes = JSONPath({
14401448
path: jptNew.jsonPath,
@@ -1444,9 +1452,10 @@ async function sparkplugProcess(
14441452
EnqueueJsonValue(jpRes, newTopic)
14451453
})
14461454
}
1455+
return
14471456
}
14481457

1449-
let jpt = JsonPathTopic(elem)
1458+
const jpt = JsonPathTopic(elem)
14501459
if (jpt.jsonPath !== '' && topicMatchSub(topic)(jpt.topic)) {
14511460
// extract value from payload using JSON PATH
14521461
const jpRes = JSONPath({
@@ -1477,7 +1486,20 @@ async function sparkplugProcess(
14771486
jscadaConnection.groupId.trim() === ''
14781487
)
14791488
return
1489+
14801490
if (metric?.value === true) {
1491+
if (
1492+
LastNodeRebirth + AppDefs.SECONDS_BETWEEN_REBIRTHS * 1000 >
1493+
new Date().getTime()
1494+
) {
1495+
Log.log(
1496+
logModS +
1497+
`Node Rebirth command received, ignoring until after ${AppDefs.SECONDS_BETWEEN_REBIRTHS} seconds`
1498+
)
1499+
return
1500+
}
1501+
LastNodeRebirth = new Date().getTime()
1502+
14811503
Log.log(logModS + 'Node Rebirth command received')
14821504
// Publish Node BIRTH certificate
14831505
let nbc = getNodeBirthPayload(configObj)
@@ -1622,7 +1644,8 @@ async function sparkplugProcess(
16221644
nodeLocator in DevicesList &&
16231645
'lastReqDateTime' in DevicesList[nodeLocator] &&
16241646
new Date().getTime() <
1625-
DevicesList[nodeLocator].lastReqDateTime + AppDefs.SECONDS_BETWEEN_NODE_REQUESTS * 1000
1647+
DevicesList[nodeLocator].lastReqDateTime +
1648+
AppDefs.SECONDS_BETWEEN_NODE_REQUESTS * 1000
16261649
) {
16271650
Log.log(
16281651
logModS +
@@ -1681,7 +1704,8 @@ async function sparkplugProcess(
16811704
nodeLocator in DevicesList &&
16821705
'lastReqDateTime' in DevicesList[nodeLocator] &&
16831706
new Date().getTime() <
1684-
DevicesList[nodeLocator].lastReqDateTime + AppDefs.SECONDS_BETWEEN_NODE_REQUESTS * 1000
1707+
DevicesList[nodeLocator].lastReqDateTime +
1708+
AppDefs.SECONDS_BETWEEN_NODE_REQUESTS * 1000
16851709
) {
16861710
Log.log(
16871711
logModS +

0 commit comments

Comments
 (0)