Skip to content

Commit bad8d1b

Browse files
committed
MQTT Sparkplug B: avoid publishing to invalid client handle.
1 parent a23b7e0 commit bad8d1b

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/mqtt-sparkplug/index.js

+32-30
Original file line numberDiff line numberDiff line change
@@ -1625,21 +1625,22 @@ async function sparkplugProcess(
16251625
return
16261626
}
16271627
Log.log(logModS + 'Requesting node rebirth...')
1628-
spClient.handle.publishNodeCmd(
1629-
topicInfo.groupId,
1630-
topicInfo.edgeNodeId,
1631-
{
1632-
timestamp: new Date().getTime(),
1633-
metrics: [
1634-
{
1635-
name: 'Node Control/Rebirth',
1636-
timestamp: new Date().getTime(),
1637-
type: 'Boolean',
1638-
value: true,
1639-
},
1640-
],
1641-
}
1642-
)
1628+
if (spClient?.handle)
1629+
spClient.handle.publishNodeCmd(
1630+
topicInfo.groupId,
1631+
topicInfo.edgeNodeId,
1632+
{
1633+
timestamp: new Date().getTime(),
1634+
metrics: [
1635+
{
1636+
name: 'Node Control/Rebirth',
1637+
timestamp: new Date().getTime(),
1638+
type: 'Boolean',
1639+
value: true,
1640+
},
1641+
],
1642+
}
1643+
)
16431644
return
16441645
}
16451646
ProcessNodeBirthOrData(nodeLocator, payload, false, splTopic[2])
@@ -1660,21 +1661,22 @@ async function sparkplugProcess(
16601661
logModS + 'Data from not yet birthed device: ' + deviceLocator
16611662
)
16621663
Log.log(logModS + 'Requesting node rebirth...')
1663-
spClient.handle.publishNodeCmd(
1664-
topicInfo.groupId,
1665-
topicInfo.edgeNodeId,
1666-
{
1667-
timestamp: new Date().getTime(),
1668-
metrics: [
1669-
{
1670-
name: 'Node Control/Rebirth',
1671-
timestamp: new Date().getTime(),
1672-
type: 'Boolean',
1673-
value: true,
1674-
},
1675-
],
1676-
}
1677-
)
1664+
if (spClient?.handle)
1665+
spClient.handle.publishNodeCmd(
1666+
topicInfo.groupId,
1667+
topicInfo.edgeNodeId,
1668+
{
1669+
timestamp: new Date().getTime(),
1670+
metrics: [
1671+
{
1672+
name: 'Node Control/Rebirth',
1673+
timestamp: new Date().getTime(),
1674+
type: 'Boolean',
1675+
value: true,
1676+
},
1677+
],
1678+
}
1679+
)
16781680
return
16791681
}
16801682
ProcessDeviceBirthOrData(

0 commit comments

Comments
 (0)