Skip to content

Commit 9f6437c

Browse files
authored
Update MQTT demo timeout and record length (FreeRTOS#1030)
* Update MQTT plain text demo timeout and record length * Update Helper functions * Update timeout comment * Update Readme with more details
1 parent 6682dbb commit 9f6437c

File tree

10 files changed

+149
-24
lines changed

10 files changed

+149
-24
lines changed

FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@
118118

119119
/**
120120
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
121+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
121122
*/
122-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
123+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
123124

124125
/**
125126
* @brief Keep alive time reported to the broker while establishing an MQTT connection.
@@ -145,14 +146,16 @@
145146
/**
146147
* @brief The length of the outgoing publish records array used by the coreMQTT
147148
* library to track QoS > 0 packet ACKS for outgoing publishes.
149+
* This length depends on the Number of publishes & can be updated accordingly.
148150
*/
149-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
151+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
150152

151153
/**
152154
* @brief The length of the incoming publish records array used by the coreMQTT
153155
* library to track QoS > 0 packet ACKS for incoming publishes.
156+
* This length depends on the Number of publishes & can be updated accordingly.
154157
*/
155-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
158+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
156159

157160
/**
158161
* @brief Maximum number of outgoing publishes maintained in the application

FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_pkcs11_demo_helpers.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@
111111

112112
/**
113113
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
114+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
114115
*/
115-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
116+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
116117

117118
/**
118119
* @brief Keep alive time reported to the broker while establishing an MQTT connection.
@@ -138,14 +139,16 @@
138139
/**
139140
* @brief The length of the outgoing publish records array used by the coreMQTT
140141
* library to track QoS > 0 packet ACKS for outgoing publishes.
142+
* This length depends on the Number of publishes & can be updated accordingly.
141143
*/
142-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
144+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
143145

144146
/**
145147
* @brief The length of the incoming publish records array used by the coreMQTT
146148
* library to track QoS > 0 packet ACKS for incoming publishes.
149+
* This length depends on the Number of publishes & can be updated accordingly.
147150
*/
148-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
151+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
149152

150153
/**
151154
* @brief Maximum number of outgoing publishes maintained in the application

FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/Common/MutualAuthMQTTExample.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@
184184

185185
/**
186186
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
187+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
187188
*/
188-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 5000U )
189+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
189190

190191
/**
191192
* @brief Keep alive time reported to the broker while establishing
@@ -220,14 +221,18 @@
220221
/**
221222
* @brief The length of the outgoing publish records array used by the coreMQTT
222223
* library to track QoS > 0 packet ACKS for outgoing publishes.
224+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
225+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
223226
*/
224-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
227+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
225228

226229
/**
227230
* @brief The length of the incoming publish records array used by the coreMQTT
228231
* library to track QoS > 0 packet ACKS for incoming publishes.
232+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
233+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
229234
*/
230-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
235+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
231236

232237
/**
233238
* Provide default values for undefined configuration settings.

FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Basic_TLS/DemoTasks/BasicTLSMQTTExample.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@
158158

159159
/**
160160
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
161+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
161162
*/
162-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
163+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
163164

164165
/**
165166
* @brief The keep-alive timeout period reported to the broker while establishing
@@ -189,14 +190,18 @@
189190
/**
190191
* @brief The length of the outgoing publish records array used by the coreMQTT
191192
* library to track QoS > 0 packet ACKS for outgoing publishes.
193+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
194+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
192195
*/
193-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
196+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
194197

195198
/**
196199
* @brief The length of the incoming publish records array used by the coreMQTT
197200
* library to track QoS > 0 packet ACKS for incoming publishes.
201+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
202+
* Update in ulMaxPublishCount needs updating mqttexampleINCOMING_PUBLISH_RECORD_LEN.
198203
*/
199-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
204+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
200205

201206
/**
202207
* @brief Milliseconds per second.

FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ extern void vLoggingPrintf( const char * pcFormatString,
211211

212212
/**
213213
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
214+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
214215
*/
215-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
216+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
216217

217218
/**
218219
* @brief Keep alive time reported to the broker while establishing
@@ -242,14 +243,18 @@ extern void vLoggingPrintf( const char * pcFormatString,
242243
/**
243244
* @brief The length of the outgoing publish records array used by the coreMQTT
244245
* library to track QoS > 0 packet ACKS for outgoing publishes.
246+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
247+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
245248
*/
246-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
249+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
247250

248251
/**
249252
* @brief The length of the incoming publish records array used by the coreMQTT
250253
* library to track QoS > 0 packet ACKS for incoming publishes.
254+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
255+
* Update in ulMaxPublishCount needs updating mqttexampleINCOMING_PUBLISH_RECORD_LEN.
251256
*/
252-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
257+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
253258

254259
/**
255260
* Provide default values for undefined configuration settings.

FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth_wolfSSL/DemoTasks/MutualAuthMQTTExample.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@
127127

128128
/**
129129
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
130+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
130131
*/
131-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
132+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
132133

133134
/**
134135
* @brief Keep alive time reported to the broker while establishing
@@ -158,14 +159,18 @@
158159
/**
159160
* @brief The length of the outgoing publish records array used by the coreMQTT
160161
* library to track QoS > 0 packet ACKS for outgoing publishes.
162+
* Number of publishes = ulMaxPublishCount * Number of topic subscribed
163+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
161164
*/
162-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
165+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
163166

164167
/**
165168
* @brief The length of the incoming publish records array used by the coreMQTT
166169
* library to track QoS > 0 packet ACKS for incoming publishes.
170+
* Number of publishes = ulMaxPublishCount * Number of topic subscribed
171+
* Update in ulMaxPublishCount needs updating mqttexampleINCOMING_PUBLISH_RECORD_LEN.
167172
*/
168-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
173+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
169174

170175
/**
171176
* @brief Milliseconds per second.

FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/PlaintextMQTTExample.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@
151151

152152
/**
153153
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
154+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
154155
*/
155-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
156+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
156157

157158
/**
158159
* @brief The keep-alive timeout period reported to the broker while establishing
@@ -182,14 +183,18 @@
182183
/**
183184
* @brief The length of the outgoing publish records array used by the coreMQTT
184185
* library to track QoS > 0 packet ACKS for outgoing publishes.
186+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
187+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
185188
*/
186-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
189+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
187190

188191
/**
189192
* @brief The length of the incoming publish records array used by the coreMQTT
190193
* library to track QoS > 0 packet ACKS for incoming publishes.
194+
* Number of publishes = ulMaxPublishCount * mqttexampleTOPIC_COUNT
195+
* Update in ulMaxPublishCount needs updating mqttexampleINCOMING_PUBLISH_RECORD_LEN.
191196
*/
192-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
197+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
193198

194199
/**
195200
* @brief Milliseconds per second.

FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,91 @@ a re-usable agent component.
1313
! always use authenticated and encrypted communication. Never send private or
1414
! sensitive data on an unencrypted connection.
1515

16+
17+
In MQTT demos, for each iteration we send 3 QoS2 MQTT Publish messages and receive
18+
3 QoS2 MQTT Publish messages because we are subscribed to the same topics we
19+
publish on. Each QoS2 MQTT publish message results in total 4 MQTT packets
20+
being exchanged between the device and the broker. For example, the following
21+
MQTT packets are exchanged between the device and the broker when the device
22+
sends a QoS2 MQTT Publish message:
23+
24+
Device Broker
25+
| |
26+
| Publish QoS2 |
27+
+------------------------>|
28+
| PUBREC |
29+
|<------------------------+
30+
| PUBREL |
31+
+------------------------>|
32+
| PUBCOMP |
33+
|<------------------------+
34+
| |
35+
36+
The coreMQTT library keeps track of the in-flight publish messages (i.e. the
37+
publish messages for which the above 4 packets sequence is not complete) in 2
38+
application supplied arrays - pOutgoingPublishRecords and pIncomingPublishRecords
39+
in this demo. We need to set the value of mqttexamplePROCESS_LOOP_TIMEOUT_MS to
40+
ensure that we can keep up with the incoming MQTT packets. We did some experiments
41+
to find the optimal value of mqttexamplePROCESS_LOOP_TIMEOUT_MS. The following
42+
table lists the results of our experiments:
43+
44+
+------------------------------------+-------------+----------------------------------------------------+
45+
| mqttexamplePROCESS_LOOP_TIMEOUT_MS | Iteration # | No. of pending messages in pOutgoingPublishRecords |
46+
+------------------------------------+-------------+----------------------------------------------------+
47+
| 500 | 0 | 0 |
48+
+ +-------------+----------------------------------------------------+
49+
| | 1 | 3 |
50+
+ +-------------+----------------------------------------------------+
51+
| | 2 | 3 |
52+
+ +-------------+----------------------------------------------------+
53+
| | 3 | 6 |
54+
+ +-------------+----------------------------------------------------+
55+
| | 4 | 9 |
56+
+------------------------------------+-------------+----------------------------------------------------+
57+
| 1000 | 0 | 0 |
58+
+ +-------------+----------------------------------------------------+
59+
| | 1 | 1 |
60+
+ +-------------+----------------------------------------------------+
61+
| | 2 | 3 |
62+
+ +-------------+----------------------------------------------------+
63+
| | 3 | 4 |
64+
+ +-------------+----------------------------------------------------+
65+
| | 4 | 6 |
66+
+ +-------------+----------------------------------------------------+
67+
| | 5 | 7 |
68+
+ +-------------+----------------------------------------------------+
69+
| | 6 | 7 |
70+
+------------------------------------+-------------+----------------------------------------------------+
71+
| 1500 | 0 | 0 |
72+
+ +-------------+----------------------------------------------------+
73+
| | 1 | 0 |
74+
+ +-------------+----------------------------------------------------+
75+
| | 2 | 1 |
76+
+ +-------------+----------------------------------------------------+
77+
| | 3 | 2 |
78+
+ +-------------+----------------------------------------------------+
79+
| | 4 | 3 |
80+
+ +-------------+----------------------------------------------------+
81+
| | 5 | 3 |
82+
+ +-------------+----------------------------------------------------+
83+
| | 6 | 0 |
84+
+------------------------------------+-------------+----------------------------------------------------+
85+
| 2000 | 0 | 0 |
86+
+ +-------------+----------------------------------------------------+
87+
| | 1 | 0 |
88+
+ +-------------+----------------------------------------------------+
89+
| | 2 | 0 |
90+
+ +-------------+----------------------------------------------------+
91+
| | 3 | 0 |
92+
+ +-------------+----------------------------------------------------+
93+
| | 4 | 0 |
94+
+ +-------------+----------------------------------------------------+
95+
| | 5 | 0 |
96+
+ +-------------+----------------------------------------------------+
97+
| | 6 | 0 |
98+
+------------------------------------+-------------+----------------------------------------------------+
99+
100+
As clear from the above table, with the value of mqttexamplePROCESS_LOOP_TIMEOUT_MS
101+
set to 2000, we are able to keep up with the incoming MQTT packets every iteration.
102+
mqttexamplePROCESS_LOOP_TIMEOUT_MS can be updated according to the requirements.
103+

FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/PKCS11_Mqtt_MutualAuthDemo.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@
130130

131131
/**
132132
* @brief Timeout for MQTT_ProcessLoop in milliseconds.
133+
* Refer to FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/readme.txt for more details.
133134
*/
134-
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 500U )
135+
#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 2000U )
135136

136137
/**
137138
* @brief Keep alive time reported to the broker while establishing
@@ -161,14 +162,18 @@
161162
/**
162163
* @brief The length of the outgoing publish records array used by the coreMQTT
163164
* library to track QoS > 0 packet ACKS for outgoing publishes.
165+
* Number of publishes = ulMaxPublishCount * Number of topic subscribed
166+
* Update in ulMaxPublishCount needs updating mqttexampleOUTGOING_PUBLISH_RECORD_LEN.
164167
*/
165-
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 10U )
168+
#define mqttexampleOUTGOING_PUBLISH_RECORD_LEN ( 15U )
166169

167170
/**
168171
* @brief The length of the incoming publish records array used by the coreMQTT
169172
* library to track QoS > 0 packet ACKS for incoming publishes.
173+
* Number of publishes = ulMaxPublishCount * Number of topic subscribed
174+
* Update in ulMaxPublishCount needs updating mqttexampleINCOMING_PUBLISH_RECORD_LEN.
170175
*/
171-
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 10U )
176+
#define mqttexampleINCOMING_PUBLISH_RECORD_LEN ( 15U )
172177

173178
/**
174179
* @brief Milliseconds per second.

lexicon.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,7 @@ ulmaxfpuinterruptnesting
29282928
ulmaxjitter
29292929
ulmaxloop
29302930
ulmaxloopcount
2931+
ulmaxpublishcount
29312932
ulmemchecktaskrunningcount
29322933
ulmessagevalue
29332934
ulminorreportversion

0 commit comments

Comments
 (0)