@@ -411,7 +411,12 @@ int MqttClient::unsubscribe(const String& topic)
411411 return unsubscribe (topic.c_str ());
412412}
413413
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 ()
415420{
416421 if (clientAvailable () == 0 && !clientConnected ()) {
417422 _rxState = MQTT_CLIENT_RX_STATE_READ_TYPE;
@@ -441,8 +446,7 @@ void MqttClient::poll()
441446 if (_rxLengthMultiplier > (128 * 128 * 128L )) {
442447 // malformed
443448 stop ();
444-
445- return ;
449+ return 0 ;
446450 }
447451
448452 if ((b & 0x80 ) == 0 ) { // length done
@@ -469,7 +473,7 @@ void MqttClient::poll()
469473
470474 if (malformedResponse) {
471475 stop ();
472- return ;
476+ return 0 ;
473477 }
474478
475479 if (_rxType == MQTT_PUBLISH) {
@@ -543,7 +547,7 @@ void MqttClient::poll()
543547 } else {
544548 if (_rxLength < _rxMessageTopicLength) {
545549 stop ();
546- return ;
550+ return 0 ;
547551 }
548552 }
549553
@@ -645,6 +649,8 @@ void MqttClient::poll()
645649 stop ();
646650 }
647651 }
652+
653+ return _connected ? 1 : 0 ;
648654}
649655
650656int MqttClient::connect (IPAddress ip, uint16_t port)
@@ -1150,6 +1156,10 @@ uint8_t MqttClient::clientConnected()
11501156 return _client->connected ();
11511157}
11521158
1159+ /* *
1160+ * @brief Return number of available received bytes.
1161+ * @return Number of available bytes received.
1162+ */
11531163int MqttClient::clientAvailable ()
11541164{
11551165 return _client->available ();
0 commit comments