Skip to content

Commit 0ce0c25

Browse files
Version 1.1.0 (#3)
## New feature - Added optional setting to enable the MQTT client to Disconnect with Will Message. If enabled, a Will Message will be sent before intentionally disconnecting. --------- Co-authored-by: Roy Gollub <roy.gollub@sick.de>
1 parent ef43837 commit 0ce0c25

8 files changed

Lines changed: 341 additions & 180 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## Release 1.1.0
5+
6+
### Improvements
7+
- Added option to send Will Message also when disconnecting normally.
8+
49
## Release 1.0.0
510

611
### Improvements

CSK_Module_MQTTClient/pages/pages/CSK_Module_MQTTClient/CSK_Module_MQTTClient.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,37 @@
248248
</layout-row>
249249
</layout-column>
250250
</layout-row>
251+
<layout-row id="Placeholder12"
252+
class="myCustom10pxHeight_CSK_Module_MQTTClient">
253+
</layout-row>
254+
<layout-row id="RowLayout31">
255+
<layout-column id="ColumnLayout58" style="align-items: stretch">
256+
<davinci-value-display id="VD_SendWillMessageByClosing"
257+
value="Disconnect with WillMessage:">
258+
</davinci-value-display>
259+
</layout-column>
260+
<layout-column id="ColumnLayout59" style="align-items: stretch">
261+
<layout-row id="RowLayout45" style="justify-content: flex-end">
262+
<davinci-toggle-switch id="TS_WillMessageOnDisconnect">
263+
<crown-edpws-binding property="checked"
264+
name="CSK_MQTTClient/OnNewStatusDisconnectWithWillMessage"
265+
update-on-resume>
266+
</crown-edpws-binding>
267+
<crown-set event="change"
268+
crown-function="CSK_MQTTClient/setDisconnectWithWillMessage"
269+
protocol="crownMSGPACK" crown-path="status">
270+
</crown-set>
271+
<crown-edpws-binding property="disabled"
272+
name="CSK_MQTTClient/OnNewStatusWillMessageActive"
273+
update-on-resume converter="function(value) {return !value;}">
274+
</crown-edpws-binding>
275+
</davinci-toggle-switch>
276+
</layout-row>
277+
</layout-column>
278+
</layout-row>
279+
<layout-row id="Placeholder13"
280+
class="myCustom10pxHeight_CSK_Module_MQTTClient">
281+
</layout-row>
251282
<davinci-value-display id="VD_WillMessageConfig">
252283
<crown-on property="value"
253284
crown-event="CSK_MQTTClient/OnNewStatusWillMessageConfig">

CSK_Module_MQTTClient/project.mf.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ This can be used e.g. to listen to "OtherModule.OnNewResult"-events and to forwa
2727
To do so make use of "addPublishEvent" (via script) or the "presetPublish"-functions (incl. "presetPublishEvent") and "addPublishEventViaUI". +
2828
{empty} +
2929
**5) WillMessage** +
30-
Configure a WillMessage via "setWillMessageConfig" (via script) or "setWillMessageViaUI (via UI) to use the preset values of the "presetPublish"-functions and activate it via "setWillMessageActivation". +</desc>
30+
Configure a WillMessage via "setWillMessageConfig" (via script) or "setWillMessageViaUI (via UI) to use the preset values of the "presetPublish"-functions and activate it via "setWillMessageActivation". +
31+
Additionally you can set via 'setDisconnectWithWillMessage' if the WillMessage should be sent when disconnecting from MQTT broker normally. +</desc>
3132
<enum name="QOS" trait="released">
3233
<desc>Quality of MQTT topic service level.</desc>
3334
<item desc="Quality of Service level 0." name="QOS0">QOS0</item>
@@ -216,6 +217,10 @@ Configure a WillMessage via "setWillMessageConfig" (via script) or "setWillMessa
216217
<desc>Notify path to CA bundle.</desc>
217218
<param desc="Path" multiplicity="1" name="path" type="string"/>
218219
</event>
220+
<event name="OnNewStatusDisconnectWithWillMessage">
221+
<desc>Notify status if WillMessage should be send before disconnecting.</desc>
222+
<param desc="Status" multiplicity="1" name="status" type="bool"/>
223+
</event>
219224
<function name="setParameterName">
220225
<desc>Function to set the name of the parameters if saved/loaded via the CSK_PersistentData module.</desc>
221226
<param desc="Name of the parameter" multiplicity="1" name="name" type="string"/>
@@ -414,10 +419,14 @@ Configure a WillMessage via "setWillMessageConfig" (via script) or "setWillMessa
414419
<desc>Function to set path to CA bundle if it is activated.</desc>
415420
<param desc="Path" multiplicity="1" name="path" type="string"/>
416421
</function>
422+
<function name="setDisconnectWithWillMessage">
423+
<desc>Function to set if WillMessage should be sent when disconnecting from MQTT broker normally.</desc>
424+
<param desc="Status" multiplicity="1" name="status" type="bool"/>
425+
</function>
417426
</serves>
418427
</crown>
419428
<meta key="author">SICK AG</meta>
420-
<meta key="version">1.0.0</meta>
429+
<meta key="version">1.1.0</meta>
421430
<meta key="priority">low</meta>
422431
<meta key="copy-protected">false</meta>
423432
<meta key="read-protected">false</meta>

CSK_Module_MQTTClient/scripts/Communication/MQTTClient/MQTTClient_Controller.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Script.serveEvent('CSK_MQTTClient.OnNewStatusSubscriptionList', 'MQTTClient_OnNe
6262
Script.serveEvent('CSK_MQTTClient.OnNewStatusPublishEventList', 'MQTTClient_OnNewStatusPublishEventList')
6363
Script.serveEvent('CSK_MQTTClient.OnNewStatusWillMessageActive', 'MQTTClient_OnNewStatusWillMessageActive')
6464
Script.serveEvent('CSK_MQTTClient.OnNewStatusWillMessageConfig', 'MQTTClient_OnNewStatusWillMessageConfig')
65+
Script.serveEvent('CSK_MQTTClient.OnNewStatusDisconnectWithWillMessage', 'MQTTClient_OnNewStatusDisconnectWithWillMessage')
6566

6667
Script.serveEvent("CSK_MQTTClient.OnNewStatusLoadParameterOnReboot", "MQTTClient_OnNewStatusLoadParameterOnReboot")
6768
Script.serveEvent("CSK_MQTTClient.OnPersistentDataModuleAvailable", "MQTTClient_OnPersistentDataModuleAvailable")
@@ -178,6 +179,7 @@ local function handleOnExpiredTmrMQTTClient()
178179
Script.notifyEvent("MQTTClient_OnNewStatusPublishRetain", mqttClient_Model.tempPublishRetain)
179180

180181
Script.notifyEvent("MQTTClient_OnNewStatusWillMessageActive", mqttClient_Model.parameters.useWillMessage)
182+
Script.notifyEvent("MQTTClient_OnNewStatusDisconnectWithWillMessage", mqttClient_Model.parameters.disconnectWithWillMessage)
181183
Script.notifyEvent("MQTTClient_OnNewStatusWillMessageConfig", "Topic = '" .. mqttClient_Model.parameters.willMessageTopic ..
182184
"', Data = '" .. mqttClient_Model.parameters.willMessageData ..
183185
"', QoS = '" .. mqttClient_Model.parameters.willMessageQOS ..
@@ -255,6 +257,9 @@ local function connectMQTT(status)
255257
mqttClient_Model.addMessageLog("Connection failed")
256258
end
257259
else
260+
if mqttClient_Model.parameters.disconnectWithWillMessage == true and mqttClient_Model.parameters.useWillMessage == true then
261+
mqttClient_Model.publish(mqttClient_Model.parameters.willMessageTopic, mqttClient_Model.parameters.willMessageData, mqttClient_Model.parameters.willMessageQOS, mqttClient_Model.parameters.willMessageRetain)
262+
end
258263
MQTTClient.disconnect(mqttClient_Model.mqttClient)
259264
mqttClient_Model.reconnectionTimer:stop()
260265
end
@@ -615,9 +620,16 @@ Script.serveFunction('CSK_MQTTClient.selectPublishEvent', selectPublishEvent)
615620
local function setWillMessageActivation(status)
616621
_G.logger:info(nameOfModule .. ": Set WillMessage activation to " .. tostring(status))
617622
mqttClient_Model.parameters.useWillMessage = status
623+
Script.notifyEvent("MQTTClient_OnNewStatusWillMessageActive", status)
618624
end
619625
Script.serveFunction('CSK_MQTTClient.setWillMessageActivation', setWillMessageActivation)
620626

627+
local function setDisconnectWithWillMessage(status)
628+
_G.logger:info(nameOfModule .. ": Set DisconnectWithWillMessage to " .. tostring(status))
629+
mqttClient_Model.parameters.disconnectWithWillMessage = status
630+
end
631+
Script.serveFunction('CSK_MQTTClient.setDisconnectWithWillMessage', setDisconnectWithWillMessage)
632+
621633
local function setWillMessageConfig(topic, data, qos, retain)
622634
_G.logger:info(nameOfModule .. ": Set WillMessage config with data '" .. data .. "' to topic '" .. topic .. "' with QoS '" .. qos .. "' and '" .. retain .. "'")
623635
mqttClient_Model.parameters.willMessageTopic = topic

CSK_Module_MQTTClient/scripts/Communication/MQTTClient/MQTTClient_Model.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ mqttClient_Model.parameters.caBundleActive = false -- Enables/disables to use ce
9595
mqttClient_Model.parameters.caBundlePath = 'public/CA.pem' -- Path to a certificate bundle in PEM format.
9696

9797
mqttClient_Model.parameters.useWillMessage = false -- Enables/disables to use a will message
98+
mqttClient_Model.parameters.disconnectWithWillMessage = false -- Enables/disables sending a will message before intentionally disconnecting
9899
mqttClient_Model.parameters.willMessageTopic = '' -- Topic under which to publish the will message
99100
mqttClient_Model.parameters.willMessageData = '' -- The message payload to publish
100101
mqttClient_Model.parameters.willMessageQOS = 'QOS0' -- Quality of Service level

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CSK_Module_MQTTClient
22

33
Module to provide MQTT client functionality.
4-
![](https://github.com/SICKAppSpaceCodingStarterKit/CSK_Module_MQTTClient/blob/main/docu/media/UI_Screenshot.png)
4+
![](./docu/media/UI_Screenshot.png)
55

66
## How to Run
77

@@ -20,13 +20,15 @@ Tested on:
2020
|--|--|--|
2121
|SIM1012|V2.4.1|v1.0.0|
2222
|SIM1012|V2.2.0|v0.4.1|
23-
|SICK AppEngine|V1.5.0|v1.0.0|
23+
|SIM2500|V1.6.0|v1.1.0|
24+
|Inspector 85x|V3.6.0|v1.1.0|
25+
|SICK AppEngine|V1.5.0|v1.0.0, v1.1.0|
2426
|SICK AppEngine|V1.3.2|v0.4.1|
2527
|TDC-E|L4M 2023.1|v0.4.1|
2628

2729
This module is part of the SICK AppSpace Coding Starter Kit developing approach.
28-
It is programmed in an object oriented way. Some of these modules use kind of "classes" in Lua to make it possible to reuse code / classes in other projects.
29-
In general it is not neccessary to code this way, but the architecture of this app can serve as a sample to be used especially for bigger projects and to make it easier to share code.
30+
It is programmed in an object-oriented way. Some of these modules use kind of "classes" in Lua to make it possible to reuse code / classes in other projects.
31+
In general, it is not neccessary to code this way, but the architecture of this app can serve as a sample to be used especially for bigger projects and to make it easier to share code.
3032
Please check the [documentation](https://github.com/SICKAppSpaceCodingStarterKit/.github/blob/main/docu/SICKAppSpaceCodingStarterKit_Documentation.md) of CSK for further information.
3133

3234
## Topics

0 commit comments

Comments
 (0)