@@ -411,7 +411,12 @@ int MqttClient::unsubscribe(const String& topic)
411
411
return unsubscribe (topic.c_str ());
412
412
}
413
413
414
- void MqttClient::poll ()
414
+ /* *
415
+ * @brief Call poll() regularly to receive MQTT messages and send MQTT keep alives.
416
+ * @return 0 - client is no longer connected.
417
+ * 1 - client is still connected.
418
+ */
419
+ int MqttClient::poll ()
415
420
{
416
421
if (clientAvailable () == 0 && !clientConnected ()) {
417
422
_rxState = MQTT_CLIENT_RX_STATE_READ_TYPE;
@@ -441,8 +446,7 @@ void MqttClient::poll()
441
446
if (_rxLengthMultiplier > (128 * 128 * 128L )) {
442
447
// malformed
443
448
stop ();
444
-
445
- return ;
449
+ return 0 ;
446
450
}
447
451
448
452
if ((b & 0x80 ) == 0 ) { // length done
@@ -469,7 +473,7 @@ void MqttClient::poll()
469
473
470
474
if (malformedResponse) {
471
475
stop ();
472
- return ;
476
+ return 0 ;
473
477
}
474
478
475
479
if (_rxType == MQTT_PUBLISH) {
@@ -543,7 +547,7 @@ void MqttClient::poll()
543
547
} else {
544
548
if (_rxLength < _rxMessageTopicLength) {
545
549
stop ();
546
- return ;
550
+ return 0 ;
547
551
}
548
552
}
549
553
@@ -645,6 +649,8 @@ void MqttClient::poll()
645
649
stop ();
646
650
}
647
651
}
652
+
653
+ return _connected ? 1 : 0 ;
648
654
}
649
655
650
656
int MqttClient::connect (IPAddress ip, uint16_t port)
@@ -1150,6 +1156,10 @@ uint8_t MqttClient::clientConnected()
1150
1156
return _client->connected ();
1151
1157
}
1152
1158
1159
+ /* *
1160
+ * @brief Return number of available received bytes.
1161
+ * @return Number of available bytes received.
1162
+ */
1153
1163
int MqttClient::clientAvailable ()
1154
1164
{
1155
1165
return _client->available ();
0 commit comments