Skip to content

Commit 51e4f43

Browse files
committed
added method to obtain whether a session was present
1 parent dbd7f1b commit 51e4f43

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ Check if the client is currently connected:
245245
bool connected();
246246
```
247247

248+
Check whether a session was present at the time of the last connect:
249+
250+
```c++
251+
bool sessionPresent();
252+
```
253+
248254
Configure dropping of overflowing messages (exceeding read buffer):
249255

250256
```c++

src/MQTTClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ bool MQTTClient::connect(const char clientID[], const char username[], const cha
371371
return false;
372372
}
373373

374+
// copy session present flag
375+
this->_sessionPresent = options.session_present;
376+
374377
// set flag
375378
this->_connected = true;
376379

src/MQTTClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class MQTTClient {
7272
uint16_t keepAlive = 10;
7373
bool cleanSession = true;
7474
uint32_t timeout = 1000;
75+
bool _sessionPresent = false;
7576

7677
Client *netClient = nullptr;
7778
const char *hostname = nullptr;
@@ -177,6 +178,7 @@ class MQTTClient {
177178

178179
bool loop();
179180
bool connected();
181+
bool sessionPresent() { return this->_sessionPresent; }
180182

181183
lwmqtt_err_t lastError() { return this->_lastError; }
182184
lwmqtt_return_code_t returnCode() { return this->_returnCode; }

0 commit comments

Comments
 (0)