Commit b1d650e
Alex J Lennon
Fix MQTT disconnection issue by adding KeepAlive configuration
- Add KeepAlivePeriodSeconds to MqttConfig (default: 60 seconds)
- Configure MQTT client with KeepAlive period in initial connection
- Configure MQTT client with KeepAlive period in reconnection logic
- Update appsettings.json with KeepAlivePeriodSeconds setting
Issue:
- MQTT broker was disconnecting the client after ~3 seconds of inactivity
- Client was not sending keepalive packets (PINGREQ) to maintain connection
- This caused repeated connect/disconnect cycles
Solution:
- Added WithKeepAlivePeriod() to MQTT client options
- Client now sends PINGREQ packets every 60 seconds (configurable)
- Prevents broker from disconnecting idle clients
- Standard MQTT keepalive behavior
The keepalive period can be configured via:
- appsettings.json: MQTT.KeepAlivePeriodSeconds
- Environment variable: MQTT__KeepAlivePeriodSeconds
Default: 60 seconds (standard MQTT keepalive interval)1 parent b9ea645 commit b1d650e
3 files changed
+13
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
145 | 149 | | |
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
149 | | - | |
| 153 | + | |
| 154 | + | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| |||
351 | 356 | | |
352 | 357 | | |
353 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
354 | 362 | | |
355 | 363 | | |
356 | 364 | | |
357 | 365 | | |
358 | | - | |
| 366 | + | |
| 367 | + | |
359 | 368 | | |
360 | 369 | | |
361 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
0 commit comments