knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.78k stars 1.46k forks source link

It steals memory from other functions #1011

Open AB-informatica-service opened 1 year ago

AB-informatica-service commented 1 year ago

Hi every one,

As recommended this using SSLClient to connect with MQTT Broker, I increased the library buffer: //unsigned char m_iobuf[2048]; unsigned char m_iobuf[BR_SSL_BUFSIZE_BIDI];

As recommended herei: #https://github.com/OPEnSLab-OSU/SSLClient/issues/46

My code is: SSLClientParameters mTLS = SSLClientParameters::fromPEM(AWS_CERT_CRT, sizeof AWS_CERT_CRT, AWS_CERT_PRIVATE, sizeof AWS_CERT_PRIVATE); this->sslClient->setMutualAuthParams(mTLS);

Dopo la creazione del Client faccio: this->mqtt = new PubSubClient(AWS_IOT_ENDPOINT, 8883, AbiotMQTT::subscribeHandler, this->client); `while (!mqtt->connect(BROKER_ID)) { Serial.print("."); log_e("Impossibile connettersi al broker MQTT"); return false; }

log_e("Iscrizione al topic %s", TOPIC_SUB);
while (!mqtt->subscribe(TOPIC_SUB))
{
    Serial.print(".");
    delay(500);
}
delay(100);

log_i("Connesso al broker: %s ", String(mqtt->connected()).c_str());
mqtt->setBufferSize(MQTT_PACKET_SIZE);
return mqtt->connected();`

Now I have the problem that ESP32-S3 PIN 17 remains HIGH after object creation and on this pin I run a LoRa TX modem (I use it only to transmit). I noticed that if before using this modem create the modem object again, it works. But it is not normal that I have to recreate the LoRa modem object every time.

Also after some time (about 30 min) I have problems with SSL and I have to reconnect to the Broker, the serial monitor says this:

(SSLClient)(SSL_ERROR)(m_update_engine): Error writing to m_client (SSLClient)(SSL_ERROR)(m_update_engine): 0 (SSLClient)(SSL_WARN)(connected): Socket was dropped unexpectedly (this can be an alternative to closing the connection) [1323214] ### Unhandled: +PDP: DEACT

0, SEND FAIL

+SAPBR 1: DEACT (SSLClient)(SSL_ERROR)(connected): Not connected because write error is set (SSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_CLIENT_WRITE_FAIL (SSLClient)(SSL_ERROR)(available): SSL engine failed to update. [1325641][I][AbiotClient.cpp:576] loop(): Network disconnected [1329720][I][AbiotClient.cpp:587] loop(): GPRS disconnected! [1329720][I][AbiotClient.cpp:588] loop(): Connecting to [1329720][I][AbiotClient.cpp:589] loop(): iot.truphone.com [1330188] ### Daylight savings time state updated. [1330229] ### Network time and time zone updated. [1333049] ### Daylight savings time state updated. [1333090] ### Network time and time zone updated. (SSLClient)(SSL_ERROR)(connected): Not connected because write error is set (SSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_CLIENT_WRITE_FAIL (SSLClient)(SSL_ERROR)(connected): Not connected because write error is set (SSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_CLIENT_WRITE_FAIL [1334042][I][AbiotMQTT.cpp:65] loop(): Connessione con broker MQTT disconnesso (SSLClient)(SSL_ERROR)(connected): Not connected because write error is set (SSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_CLIENT_WRITE_FAIL (SSLClient)(SSL_ERROR)(connected): Not connected because write error is set (SSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_CLIENT_WRITE_FAIL [1349176][E][AbiotMQTT.cpp:79] loop(): Iscrizione al topic abiot/6e3dadf2-0edf-4ac2-b94d-5128aff877d0 [1349287][I][AbiotMQTT.cpp:87] loop(): Connesso al broker: 1

I did some tests: if I exclude the LoRa TX modem, these SSL errors never come out. Conversely, if I exclude SSL and therefore do not use MQTT, the LoRa modem always works fine without recreating the modem object before each transmission.

In my mind it seems like they don't have enough space and they steal each other's memory, I checked how much RAM I have available and I always have at least 202556 bytes (according to esp_get_free_heap_size()).

This goes out of my knowledge, I ask for support.

Thank you