EmbeddedMqttBroker icon indicating copy to clipboard operation
EmbeddedMqttBroker copied to clipboard

Guru Meditation in ReaderMqttPacket::bytesToString when there is some traffic load on the Broaker

Open diodi opened this issue 2 years ago • 5 comments

I modified httpServerAndMqttBroker.ino to operate as as WIFI_AP and to allow up to 8 clients.

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
#include "EmbeddedMqttBroker.h"
...

void setup(){

  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");

  WiFi.mode(WIFI_AP);  
  WiFi.softAP(ssid, password);
  delay(500);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  // Start http server
  server.begin();
...

  // Start the mqtt broker
  broker.setMaxNumClients(8); // set according to your system.
  broker.startBroker();
  Serial.println("broker started"

Connecting two clients and generating some trafic I run into an unhandled exception.

publishing: moba/ToESP
enviando publish
enviando publish
publishing: moba/ToESP
enviando publish
enviando publish
no action
no action
no action
no action
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

The memcopy operation

int ReaderMqttPacket::bytesToString(int index, size_t textFieldLengt,String*textField){
    // reserving memory to copy the mqtt text field.
    char* aux = (char*)malloc(textFieldLengt+1);

    // memcpy is necesary because reader object will be deleted.
    memcpy(aux,&remainingPacket[index],textFieldLengt);

leads to the exception.

Please let me know if you need more. Thank you!

diodi avatar Dec 26 '22 17:12 diodi

ok! it is a important issue, I will fix it.

alexCajas avatar Dec 28 '22 16:12 alexCajas

Hi again, @diodi , can you give information about the clients please? Desktops clients, esp clients maybe?, Is the traffic only two publish?

alexCajas avatar Jan 11 '23 18:01 alexCajas

Two esp clients are active. Both publish serialized JsonDocuments (ArduinoJson.h) to several sub-topics within the same main topic using PubSubClientStatic. Both clients subscribe to the main topic to receive all published information. Thank you for taking a look.

diodi avatar Jan 11 '23 20:01 diodi

I get the same error as described by @diodi. But I also get it without running an Access Point. I use the simpleMqttBroker example with WiFi.mode(WIFI_STA); and with only one client that publishes two topics every 10 seconds (Tasmota on an ESP8266).

When I print out the free memory with ESP.getFreeHeap() I see decreasing free memory after each publication event.

The time until the exception occurs varies, but often is only a couple of minutes. I tried version 1.0.5 and 1.0.3 with basically the same result

rolliracker avatar May 16 '23 19:05 rolliracker