LoadProhibited with BLE Sketch ESP32

Hey,

hoffentlich kann mir jemand hier etwas weiterhelfen ich komme hier seit tagen nicht weiter ... :frowning:

Ich habe ein EPS32 (WROOM-32) und nutze dort als Basis das BLE Beispiel Sketch...
ausgehend davon habe ich dann meine Sachen die ich benötige reingebaut... (WLAN, MQTT)
Ich lese damit ein BMS aus und das geht auch soweit eigentlich "fehlerfrei" würde der ESP nur nicht regelmäßig rebooten :wink:

Der Error Code ist:

Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400d5102 PS : 0x00060730 A0 : 0x800d51d0 A1 : 0x3ffdf380
A2 : 0x3ffdf3e8 A3 : 0x0ee10000 A4 : 0x3ffdf3ec A5 : 0x3ffdf3ac
A6 : 0x3fff0488 A7 : 0x3ffdf3e8 A8 : 0x800d5100 A9 : 0x3ffdf360
A10 : 0x3fff158c A11 : 0x00000001 A12 : 0x3fff1e2c A13 : 0x3fff280c
A14 : 0x3fff2595 A15 : 0x3fff280d SAR : 0x00000018 EXCCAUSE: 0x0000001c
EXCVADDR: 0x0ee10000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x400d5102:0x3ffdf380 0x400d51cd:0x3ffdf3a0 0x400d5229:0x3ffdf3d0 0x4011d86d:0x3ffdf420 0x401162ce:0x3ffdf470 0x400906ae:0x3ffdf4a0

the Decoder Says:
PC: 0x400d5102: std::_Rb_tree , std::_Select1st >, std::less , std::allocator > >::_M_copy , std::_Select1st >, std::less , std::allocator > >::_Alloc_node>(std::_Rb_tree_node > const*, std::_Rb_tree_node >*, std::_Rb_tree , std::_Select1st >, std::less , std::allocator > >::_Alloc_node&) at c:\users\scott\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0\bits/stl_tree.h line 570
EXCVADDR: 0x0ee10000

Decoding stack results
0x400d5102: std::_Rb_tree , std::_Select1st >, std::less , std::allocator > >::_M_copy , std::_Select1st >, std::less , std::allocator > >::_Alloc_node>(std::_Rb_tree_node > const*, std::_Rb_tree_node >, std::_Rb_tree , std::_Select1st >, std::less , std::allocator > >::_Alloc_node&) at c:\users\scott\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0\bits/stl_tree.h line 570
0x400d51cd: std::_Rb_tree , std::_Select1st >, std::less , std::allocator > >::_Rb_tree(std::_Rb_tree , std::_Select1st >, std::less , std::allocator > > const&) at c:\users\scott\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0\bits/stl_tree.h line 783
0x400d5229: BLEDevice::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t
) at c:\users\scott\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0\bits/stl_map.h line 186
0x4011d86d: btc_gattc_cb_handler at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c line 31
0x401162ce: btc_task at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/common/btc/core/btc_task.c line 163
0x400906ae: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

ich bin leider nicht in der Lage damit was anzufangen da es für mich so aussieht als ob es vom BLE "0x400d5229: BLEDevice::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, " ausgeht wenn ich es recht verstehe...

ich dachte auch erst das es an ein paar meiner Erweiterungen liegt da ich dort viel nach Strings und Arrays wandeln muss.. aber egal welche Lösungswege ich umgesetzt habe das Ergebnis was immer das gleiche ...

#include "BLEDevice.h"
#include <WiFi.h>
#include <PubSubClient.h>

bool debug_flg = true;

const char* mqtt_server = "";
const int mqtt_port = ;
const char* ssid = "";
const char* password = "";

//Start Scott Parameters 
byte getdeviceInfo[20] = {0xaa, 0x55, 0x90, 0xeb, 0x97, 0x00, 0xdf, 0x52, 0x88, 0x67, 0x9d, 0x0a, 0x09, 0x6b, 0x9a, 0xf6, 0x70, 0x9a, 0x17, 0xfd}; // Device Infos
//byte getInfo[20] = {0xaa, 0x55, 0x90, 0xeb, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}; 
byte getInfo[20] = {0xaa, 0x55, 0x90, 0xeb, 0x96, 0x00, 0x79, 0x62, 0x96, 0xed, 0xe3, 0xd0, 0x82, 0xa1, 0x9b, 0x5b, 0x3c, 0x9c, 0x4b, 0x5d}; 
//byte balancer_an[20] = {0xaa, 0x55, 0x90, 0xeb, 0x1f, 0x04, 0x01, 0x00, 0x00, 0x00, 0xd3, 0x27, 0x86, 0x3b, 0xe2, 0x12, 0x4d, 0xb0, 0xb6, 0x00};

unsigned long sendingtimer = 5000; // 5 Sekunden
unsigned long sendingtime = 0;
unsigned long mqttpublishtime = 0;

//end Scott parameter 
bool aktive_sending = true;
const int numBytes = 320;
byte receivedBytes_main[numBytes];
int frame = 0;
bool received_start = false;
bool received_start_frame = false;
bool received_complete = false;
bool new_data = false;

//BMS Werte
float spannungzelle01 = 0;
float spannungzelle02 = 0;
float spannungzelle03 = 0;
float spannungzelle04 = 0;
float spannungzelle05 = 0;
float spannungzelle06 = 0;
float spannungzelle07 = 0;
float spannungzelle08 = 0;
float spannungzelle09 = 0;
float spannungzelle10 = 0;
float spannungzelle11 = 0;
float spannungzelle12 = 0;
float spannungzelle13 = 0;
float spannungzelle14 = 0;
float Average_Cell_Voltage = 0;
float Delta_Cell_Voltage = 0;
float Current_Balancer = 0;
float Battery_Voltage = 0;
float Battery_Power = 0;
float Charge_Current = 0;
float Battery_T1 = 0;
float Battery_T2 = 0;
float MOS_Temp = 0;
int Percent_Remain = 0;
float Capacity_Remain = 0;
float Nominal_Capacity = 0;
String Cycle_Count = "";
float Capacity_Cycle = 0;
uint32_t Uptime;
uint8_t sec, mi, hr, days;
float Balance_Curr = 0;
bool charge = false;
bool discharge = false;


// The remote service we wish to connect to.
static BLEUUID serviceUUID("ffe0");
// The characteristic of the remote service we are interested in.
static BLEUUID    charUUID("ffe1"); //ffe1
//static BLEUUID    charUUID2("ffe2"); //ffe1
static boolean doConnect = false;
static boolean connected = false;
static boolean doScan = false;
static BLERemoteCharacteristic* pRemoteCharacteristic;
static BLERemoteCharacteristic* pRemoteCharacteristic2;
static BLEAdvertisedDevice* myDevice;

static void notifyCallback(
  BLERemoteCharacteristic* pBLERemoteCharacteristic,
  uint8_t* pData,
  size_t length,
  bool isNotify) {

    if(pData[0] == 0x55 && pData[1] == 0xAA && pData[2] == 0xEB && pData[3] == 0x90 && pData[4] == 0x02) {
      //Serial.println("Daten anerkannt !");
      received_start = true;
      received_start_frame = true;
      received_complete = false;
      frame = 0;
      for (int i = 0; i < length; i++)  {
       receivedBytes_main[frame] = pData[i];
       frame++;
      }
    }

    if(received_start && !received_start_frame && !received_complete) {
      //Serial.println("Daten erweitert !");
      for (int i = 0; i < length; i++)  {
        receivedBytes_main[frame] = pData[i];
        frame++;
      }
    
      if(frame == 300) {
      //Serial.println("Daten beendet !");
        received_complete = true;
        received_start = false;
        new_data = true;
        //Datenanalyse();
      }          
      
    }
    //Serial.print("frame: ");
    //Serial.println(frame);   
    received_start_frame = false;

}

class MyClientCallback : public BLEClientCallbacks {
  void onConnect(BLEClient* pclient) {
  }

  void onDisconnect(BLEClient* pclient) {
    connected = false;
    Serial.println("onDisconnect");
  }
};

bool connectToServer() {
    Serial.print("Forming a connection to ");
    Serial.println(myDevice->getAddress().toString().c_str());
    
    BLEClient*  pClient  = BLEDevice::createClient();
    Serial.println(" - Created client");

    pClient->setClientCallbacks(new MyClientCallback());

    // Connect to the remove BLE Server.
    pClient->connect(myDevice);  // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
    Serial.println(" - Connected to server");

    // Obtain a reference to the service we are after in the remote BLE server.
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService == nullptr) {
      Serial.print("Failed to find our service UUID: ");
      Serial.println(serviceUUID.toString().c_str());
      pClient->disconnect();
      return false;
    }
    Serial.println(" - Found our service");


    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
    if (pRemoteCharacteristic == nullptr) {
      Serial.print("Failed to find our characteristic UUID: ");
      Serial.println(charUUID.toString().c_str());
      pClient->disconnect();
      return false;
    }
    Serial.println(" - Found our characteristic");

    // Read the value of the characteristic.
    if(pRemoteCharacteristic->canRead()) {
      std::string value = pRemoteCharacteristic->readValue();
      Serial.print("The characteristic value was: ");
      Serial.println(value.c_str());
    }

     if(pRemoteCharacteristic->canNotify()) {
      pRemoteCharacteristic->registerForNotify(notifyCallback);
      Serial.println("Notify the characteristic");
    }

// Sending getdevice info
      pRemoteCharacteristic->writeValue(getdeviceInfo, 20);
      sendingtime = millis();
      Serial.println("Sending device Info");

    connected = true;
    return true;
}
/**
 * Scan for BLE servers and find the first one that advertises the service we are looking for.
 */
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
 /**
   * Called for each advertising BLE server.
   */
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    Serial.print("BLE Advertised Device found: ");
    Serial.println(advertisedDevice.toString().c_str());

    // We have found a device, let us now see if it contains the service we are looking for.
    if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID)) {

      BLEDevice::getScan()->stop();
      myDevice = new BLEAdvertisedDevice(advertisedDevice);
      doConnect = true;
      doScan = true;

    } // Found our server
  } // onResult
}; // MyAdvertisedDeviceCallbacks

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

//MQTT
WiFiClient espClient;

void MQTTCallback(char* topic, byte* payload, unsigned int length){
  String Command = "";
    if(strcmp(topic, "BMS_Watchdog/parameter/debugging_aktive") == 0)
  {
   for (int i = 0; i < length; i++) {
     Command = Command + (char)payload[i];
   }  
   if(Command == "true"){
     debug_flg = true;
      if(debug_flg) {
      Serial.println("Debugging: true");
      }
   }
   else if(Command == "false"){
    debug_flg = false;
     if(debug_flg) {
     Serial.println("Debugging: false");
     }
   }
  } 
}

PubSubClient client(mqtt_server, mqtt_port, MQTTCallback, espClient);
long lastReconnectAttempt = 0;

boolean reconnect(){
  if (client.connect("BMS_Wachtdog", "Scott", "Fa-Vo111222Home")) {
    // Once connected, publish an announcement...
    client.publish("BMS_Watchdog/BatteryVoltage","reconnect");
    client.publish("BMS_Watchdog/Battery_Power","reconnect");
    // ... and resubscribe
    client.subscribe("BMS_Watchdog/parameter/debugging_aktive");
    if(debug_flg) {
      Serial.println("MQTT reconnected!");
    }
  }
  else {
   if(debug_flg) {
    Serial.println("MQTT connection failed!");
   }
  }
  return client.connected();
}


void setup() {
  Serial.begin(115200);
  Serial.println("BMS Watchdog V0.1");
  Serial.println("Booting");

  //WIFI Setup
  initWiFi();

  //BLE Setup
  BLEDevice::init("");

  // Retrieve a Scanner and set the callback we want to use to be informed when we
  // have detected a new device.  Specify that we want active scanning and start the
  // scan to run for 5 seconds.
  BLEScan* pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setInterval(1349);
  pBLEScan->setWindow(449);
  pBLEScan->setActiveScan(true);
  pBLEScan->start(5, false);
} // End of setup.


// This is the Arduino main loop function.
void loop() {

//MQTT
  if (!client.connected()) {
   if(debug_flg) {
    Serial.println("MQTT Client not connected");
   }
    if ((millis() - lastReconnectAttempt) > 5000) { // reconnect nach 5 sekunden 
      if(debug_flg) {
       Serial.println("MQTT time for reconnect");
      }
      lastReconnectAttempt = millis();
      // Attempt to reconnect
      if (reconnect()) {
        lastReconnectAttempt = 0;
      }
      else{
       if(debug_flg) {
        Serial.println("MQTT reconnect Error");
       }
      }
    }
  }
  else {
    // Client connected
//    if(debug_flg) {
//     Serial.println("MQTT Client loop");
//    }
    client.loop();
//    if(debug_flg) {
//     Serial.println("MQTT Client loop done");
//   }
  }
  

  // If the flag "doConnect" is true then we have scanned for and found the desired
  // BLE Server with which we wish to connect.  Now we connect to it.  Once we are 
  // connected we set the connected flag to be true.
  
  if (doConnect == true) {
    if (connectToServer()) {

      Serial.println("We are now connected to the BLE Server.");

    } 
    else {
      Serial.println("We have failed to connect to the server; there is nothin more we will do.");
    }
    doConnect = false;
  }

  // If we are connected to a peer BLE Server, update the characteristic each time we are reached
  // with the current time since boot.
  if (connected) {

   if(received_complete) {
//      for (int i = 0; i < 319; i++)  {
//        Serial.print(receivedBytes_main[i],HEX);
//       Serial.print(", ");
//      }
//      Serial.println("");
     if(new_data) {
      Datenanalyse();
     }
     
      if(mqttpublishtime == 0 || (millis() >= (mqttpublishtime + 1000))) {
        mqttpublishtime = millis();
        Data_publish();
      }
      
       
    }

  if(aktive_sending && (millis() - sendingtime) > 500) { // millis() >  sendingtime + sendingtimer
    Serial.println("gesendet!");
    aktive_sending = false;
    //sendingtime = millis();
    pRemoteCharacteristic->writeValue(getInfo, 20);
  }


  }
  //else if(doScan){
  //  BLEDevice::getScan()->start(0);  // this is just example to start scan after disconnect, most likely there is better way to do it in arduino
  //}
//  else if(!connected) {
//    BLEDevice::getScan()->start(0);  // this is just example to start scan after disconnect, most likely there is better way to do it in arduino
//  }
  
  //delay(1000); // Delay a second between loops.
  
} // End of loop

void Datenanalyse() {

//Zellspannungen
spannungzelle01 = (((int)receivedBytes_main[7] << 8 | receivedBytes_main[6])*0.001); 
spannungzelle02 = (((int)receivedBytes_main[9] << 8 | receivedBytes_main[8])*0.001); 
spannungzelle03 = (((int)receivedBytes_main[11] << 8 | receivedBytes_main[10])*0.001); 
spannungzelle04 = (((int)receivedBytes_main[13] << 8 | receivedBytes_main[12])*0.001); 
spannungzelle05 = (((int)receivedBytes_main[15] << 8 | receivedBytes_main[14])*0.001); 
spannungzelle06 = (((int)receivedBytes_main[17] << 8 | receivedBytes_main[16])*0.001); 
spannungzelle07 = (((int)receivedBytes_main[19] << 8 | receivedBytes_main[18])*0.001); 
spannungzelle08 = (((int)receivedBytes_main[21] << 8 | receivedBytes_main[20])*0.001); 
spannungzelle09 = (((int)receivedBytes_main[23] << 8 | receivedBytes_main[22])*0.001); 
spannungzelle10 = (((int)receivedBytes_main[25] << 8 | receivedBytes_main[24])*0.001); 
spannungzelle11 = (((int)receivedBytes_main[27] << 8 | receivedBytes_main[26])*0.001); 
spannungzelle12 = (((int)receivedBytes_main[29] << 8 | receivedBytes_main[28])*0.001); 
spannungzelle13 = (((int)receivedBytes_main[31] << 8 | receivedBytes_main[30])*0.001); 
spannungzelle14 = (((int)receivedBytes_main[33] << 8 | receivedBytes_main[32])*0.001); 
// +20 byte Zelle 15 - 24
// +4 Byte unbekannt
Average_Cell_Voltage = (((int)receivedBytes_main[59] << 8 | receivedBytes_main[58])*0.001); 
Delta_Cell_Voltage = (((int)receivedBytes_main[61] << 8 | receivedBytes_main[60])*0.001); 
Current_Balancer = (((int)receivedBytes_main[63] << 8 | receivedBytes_main[62])*0.001); 
// +48 byte Resistance_Cell1
// +6 byte unbekant 2
Battery_Voltage = (((int)receivedBytes_main[119] << 8 | receivedBytes_main[118])*0.001); 
Battery_Power = (((int)receivedBytes_main[121] << 8 | receivedBytes_main[120])*0.001); 
Charge_Current = (((int)receivedBytes_main[123] << 8 | receivedBytes_main[122])*0.001); 
// +6 byte unbekant 3
Battery_T1 = (((int)receivedBytes_main[131] << 8 | receivedBytes_main[130])*0.1); 
Battery_T2 = (((int)receivedBytes_main[133] << 8 | receivedBytes_main[132])*0.1); 
MOS_Temp = (((int)receivedBytes_main[135] << 8 | receivedBytes_main[134])*0.1); 

if((receivedBytes_main[139] & 0xF0) == 0x0) {
  Balance_Curr = (((int)receivedBytes_main[139] << 8 | receivedBytes_main[138])*0.001); 
}
else if ((receivedBytes_main[139] & 0xF0) == 0xF0) {
  Balance_Curr = ((((int)receivedBytes_main[139] & 0x0F) << 8 | receivedBytes_main[138])*-0.001); 
}
// +2 byte unbekant 4
Percent_Remain = ((int)receivedBytes_main[141]); 
Capacity_Remain = (((int)receivedBytes_main[145] << 24 | receivedBytes_main[144] << 16 | receivedBytes_main[143] << 8 | receivedBytes_main[142])*0.001); 
Nominal_Capacity = (((int)receivedBytes_main[149] << 24 | receivedBytes_main[148] << 16 | receivedBytes_main[147] << 8 | receivedBytes_main[146])*0.001); 
Cycle_Count = receivedBytes_main[153] + receivedBytes_main[152] + receivedBytes_main[151] + receivedBytes_main[150];                        //((String)receivedBytes_main[153] << 24 | receivedBytes_main[152] << 16 | receivedBytes_main[151] << 8 | receivedBytes_main[150])); 
// +6 byte unbekant 5
Capacity_Cycle = (((int)receivedBytes_main[161] << 8 | receivedBytes_main[160])*0.001); 
Uptime = (((int)receivedBytes_main[164] << 16 | receivedBytes_main[163] << 8 | receivedBytes_main[162])); 
sec = Uptime % 60;
  Uptime /= 60;
  mi = Uptime % 60;
  Uptime /= 60;
  hr = Uptime % 24;
  days = Uptime /= 24;

// +1 byte unbekannt
if(receivedBytes_main[166] > 0) {
  charge = true;
}
else if (receivedBytes_main[166] == 0) {
  charge = false;  
}
if(receivedBytes_main[167] > 0) {
  discharge = true;
}
else if (receivedBytes_main[167] == 0) {
  discharge = false;  
}


new_data = false;
//
//       
//Serial.print("Cell Voltages = ");
//Serial.print(spannungzelle01);
//Serial.print("V, ");
//Serial.print(spannungzelle02);
//Serial.print("V, ");
//Serial.print(spannungzelle03);
//Serial.print("V, ");
//Serial.print(spannungzelle04);
//Serial.print("V, ");
//Serial.print(spannungzelle05);
//Serial.print("V, ");
//Serial.print(spannungzelle06);
//Serial.print("V, ");
//Serial.print(spannungzelle07);
//Serial.print("V, ");
//Serial.print(spannungzelle08);
//Serial.print("V, ");
//Serial.print(spannungzelle09);
//Serial.print("V, ");
//Serial.print(spannungzelle10);
//Serial.print("V, ");
//Serial.print(spannungzelle11);
//Serial.print("V, ");
//Serial.print(spannungzelle12);
//Serial.print("V, ");
//Serial.print(spannungzelle13);
//Serial.print("V, ");
//Serial.print(spannungzelle14);
//Serial.print("V, ");
//Serial.println("");
//
////unbekant1 4 byte
//Serial.print("unbekant 1 = ");
//Serial.print(receivedBytes_main[57],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[56],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[55],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[54],HEX);
//Serial.print(", ");
//Serial.println("");
//
//Serial.print("Average Cell Voltage = ");
//Serial.print(Average_Cell_Voltage);
//Serial.println("V, ");
//
//Serial.print("Delta Cell Voltage = ");
//Serial.print(Delta_Cell_Voltage);
//Serial.println("V, ");
//
//Serial.print("Current Balancer = ");
//Serial.print(Current_Balancer);
//Serial.println("V, ");
//
////unbekant 2 6 byte
//Serial.print("unbekant 2 = ");
//Serial.print(receivedBytes_main[117],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[116],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[115],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[114],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[113],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[112],HEX);
//Serial.print(", ");
//Serial.println("");
//
//Serial.print("Battery Voltage = ");
//Serial.print(Battery_Voltage);
//Serial.println("V, ");
//
//Serial.print("Battery Power = ");
//Serial.print(Battery_Power);
//Serial.println("W, ");
//
//Serial.print("Charge Current = ");
//Serial.print(Charge_Current);
//Serial.println("A, ");
//
////unbekant 3 6 byte
//Serial.print("unbekant 3 = ");
//Serial.print(receivedBytes_main[129],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[128],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[127],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[126],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[125],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[124],HEX);
//Serial.print(", ");
//Serial.println("");
//
//Serial.print("Battery T1 = ");
//Serial.print(Battery_T1);
//Serial.println("°C, ");
//
//Serial.print("Battery T2 = ");
//Serial.print(Battery_T2);
//Serial.println("°C, ");
//
//Serial.print("MOS Temp = ");
//Serial.print(MOS_Temp);
//Serial.println("°C, ");
//
//Serial.print("Balance_Curr = ");
//Serial.print(Balance_Curr);
//Serial.println("A, ");
//
//
////unbekant 4 2 byte
//Serial.print("unbekant 4 = ");
//Serial.print(receivedBytes_main[137],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[136],HEX);
//Serial.print(", ");
//Serial.println("");
//
//
//Serial.print("Percent Remain = ");
//Serial.print(Percent_Remain);
//Serial.println("%, ");
//
//Serial.print("Capacity Remain = ");
//Serial.print(Capacity_Remain);
//Serial.println(", ");
//
//Serial.print("Nominal Capacity = ");
//Serial.print(Nominal_Capacity);
//Serial.println(", ");
//
//Serial.print("Cycle Count = ");
//Serial.print(Cycle_Count);
//Serial.println(", ");
//
////unbekant 5 3 byte
//Serial.print("unbekant 5 = ");
//Serial.print(receivedBytes_main[159],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[158],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[157],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[156],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[155],HEX);
//Serial.print(", ");
//Serial.print(receivedBytes_main[154],HEX);
//Serial.print(", ");
//Serial.println("");
//
//Serial.print("Capacity Cycle = ");
//Serial.print(Capacity_Cycle);
//Serial.println(", ");
//
//Serial.print("Tage: "); Serial.print(days);
//Serial.print(" Stunden: "); Serial.print(hr);
//Serial.print(" Minuten: "); Serial.print(mi);
//Serial.print(" Sekunden: "); Serial.println(sec);
//
//
////unbekant 6 1 byte
//Serial.print("unbekant 5 = ");
//Serial.print(receivedBytes_main[165],HEX);
//Serial.print(", ");
//Serial.println("");
//
//Serial.print("Charge on? = ");
//Serial.print(charge);
//Serial.println(", ");
//
//Serial.print("Discharge on? = ");
//Serial.print(discharge);
//Serial.println(", ");
//
////unbekant 6 .... byte
//Serial.print("unbekant 7 = ");
// for (int i = 168; i < 230; i++)  {
//   Serial.print(receivedBytes_main[i],HEX);
//   Serial.print(", ");
// }

}

void Data_publish() {
 String zelle01_str, zelle02_str, zelle03_str, zelle04_str, zelle05_str, zelle06_str, zelle07_str, zelle08_str, zelle09_str, zelle10_str, zelle11_str, zelle12_str, zelle13_str, zelle14_str;
 char zelle01_char[4], zelle02_char[4], zelle03_char[4], zelle04_char[4], zelle05_char[4], zelle06_char[4], zelle07_char[4], zelle08_char[4], zelle09_char[4], zelle10_char[4], zelle11_char[4], zelle12_char[4], zelle13_char[4], zelle14_char[4];

 String Battery_Voltage_str, Balance_Curr_str, Delta_Cell_Voltage_str, MOS_Temp_str, sec_str, mi_str, hr_str, days_str;
 char Battery_Voltage_char[5], Balance_Curr_char[4], Delta_Cell_Voltage_char[4], MOS_Temp_char[5], sec_char[2], mi_char[2], hr_char[2], days_char[3];;
 
 zelle01_str = String(spannungzelle01); //converting ftemp (the float variable above) to a string
 zelle01_str.toCharArray(zelle01_char, zelle01_str.length() + 1); //packaging up the data to publish to mqtt whoa...
client.publish("BMS_Watchdog/Data/Zelle_01",zelle01_char);

 zelle02_str = String(spannungzelle02); 
 zelle02_str.toCharArray(zelle02_char, zelle02_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_02",zelle02_char);

 zelle03_str = String(spannungzelle03); 
 zelle03_str.toCharArray(zelle03_char, zelle03_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_03",zelle03_char);
 
 zelle04_str = String(spannungzelle04); 
 zelle04_str.toCharArray(zelle04_char, zelle04_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_04",zelle04_char);

 zelle05_str = String(spannungzelle05); 
 zelle05_str.toCharArray(zelle05_char, zelle05_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_05",zelle05_char);
 
 zelle06_str = String(spannungzelle06); 
 zelle06_str.toCharArray(zelle06_char, zelle06_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_06",zelle06_char);
 
 zelle07_str = String(spannungzelle07); 
 zelle07_str.toCharArray(zelle07_char, zelle07_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_07",zelle07_char);
  
 zelle08_str = String(spannungzelle08); 
 zelle08_str.toCharArray(zelle08_char, zelle08_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_08",zelle08_char);
  
 zelle09_str = String(spannungzelle09); 
 zelle09_str.toCharArray(zelle09_char, zelle09_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_09",zelle09_char);
  
 zelle10_str = String(spannungzelle10); 
 zelle10_str.toCharArray(zelle10_char, zelle10_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_10",zelle10_char);
  
 zelle11_str = String(spannungzelle11); 
 zelle11_str.toCharArray(zelle11_char, zelle11_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_11",zelle11_char);
  
 zelle12_str = String(spannungzelle12); 
 zelle12_str.toCharArray(zelle12_char, zelle12_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_12",zelle12_char);
  
 zelle13_str = String(spannungzelle13); 
 zelle13_str.toCharArray(zelle13_char, zelle13_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_13",zelle13_char);
  
 zelle14_str = String(spannungzelle14); 
 zelle14_str.toCharArray(zelle14_char, zelle14_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_14",zelle14_char);
  
 //dtostrf(spannungzelle14, 5, 2, result); // Leave room for too large numbers!
 //client.publish("BMS_Watchdog/Data/Zelle_14",result);
 //client.publish("BMS_Watchdog/Data/Zelle_02",String(spannungzelle02).c_str());
 // Average_Cell_Voltage = 0;
 // Current_Balancer = 0;

 Battery_Voltage_str = String(Battery_Voltage); 
 Battery_Voltage_str.toCharArray(Battery_Voltage_char, Battery_Voltage_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Battery_Voltage",Battery_Voltage_char);
 
 Delta_Cell_Voltage_str = String(Delta_Cell_Voltage); 
 Delta_Cell_Voltage_str.toCharArray(Delta_Cell_Voltage_char, Delta_Cell_Voltage_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Delta_Cell_Voltage",Delta_Cell_Voltage_char);
 
 MOS_Temp_str = String(MOS_Temp); 
 MOS_Temp_str.toCharArray(MOS_Temp_char, MOS_Temp_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/MOS_Temp",MOS_Temp_char);

// Battery_Power 
// Charge_Current
// Battery_T1 
// Battery_T2 
// Percent_Remain
// Capacity_Remain
// Nominal_Capacity
// Cycle_Count
//// Capacity_Cycle 

 Balance_Curr_str = String(Balance_Curr); 
 Balance_Curr_str.toCharArray(Balance_Curr_char, Balance_Curr_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Balance_Current",Balance_Curr_char);
// 
// dtostrf(Balance_Curr, 5, 2, result); // Leave room for too large numbers!
// client.publish("BMS_Watchdog/Data/Zelle_14",result);
// 

 sec_str = String(sec); 
 sec_str.toCharArray(sec_char, sec_str.length() + 1); 
 client.publish("BMS_Watchdog/Uptime/Sekunde",sec_char);

 mi_str = String(mi); 
 mi_str.toCharArray(mi_char, mi_str.length() + 1); 
 client.publish("BMS_Watchdog/Uptime/Minuten",mi_char);

 hr_str = String(hr); 
 hr_str.toCharArray(hr_char, hr_str.length() + 1); 
 client.publish("BMS_Watchdog/Uptime/Stunden",hr_char);

 days_str = String(days); 
 days_str.toCharArray(days_char, days_str.length() + 1); 
 client.publish("BMS_Watchdog/Uptime/Tage",days_char);
 
}

Ich vermute das du irgendwas überschreibst oder der Speicher vollläuft...

Bleibt frame unter 320?
Wird in connectToServer() das erzeugte pClient irgendwo wieder freigegeben?

Hey,

ja das vermute ich auch aber ich hab keine Ahnung wer oder wo :wink:

ich schau mir das mit dem frame mal nochmal an ggf fange ich einen Überlauf einfach mit einen "Abbruch" erstmal ab und schau ob das mal passiert ..

was genau meinst du mit pClient wieder freigeben ?

kann man sich die Speicher ausgeben lassen ? also wie voll diese sind ...

Hey,

du bist mein Man !
ich habe einfach eine abfrage eingebaut ob frame >300 ist und siehe da selten aber es kommt vor ...
dann ist klar das ich es dann überschreibe ...
hab es nun mit einer Fehlermeldung und Abbruch abgefangen und nun scheint es stabil zu laufen...

Danke dir... manchmal steht man echt auf dem schlauch ...

sag, machen solche Code Duplikate wirklich Sinn?

 zelle01_str = String(spannungzelle01); //converting ftemp (the float variable above) to a string
 zelle01_str.toCharArray(zelle01_char, zelle01_str.length() + 1); //packaging up the data to publish to mqtt whoa...
 client.publish("BMS_Watchdog/Data/Zelle_01",zelle01_char);

 zelle02_str = String(spannungzelle02); 
 zelle02_str.toCharArray(zelle02_char, zelle02_str.length() + 1); 
 client.publish("BMS_Watchdog/Data/Zelle_02",zelle02_char);

//usw
}

das könntest doch auch auch in einer for schleife abarbeiten. Deine ganzen Zelle01_str .. ZelleXX_str ... die verwendest eh nur einmalig zur Ausgabe - brauchst also gar nicht. Also könntest deinen "BMS_Watchdo/Data/Zelle_XX" auch dynamisch zusammenstellen und dann eben den gewandelten Wert übertragen .. aber nicht 20 mal als Codeduplikat hinschreiben.

Da hast du vollkommen recht ich bin da auch kein freund von aber das war jetzt erstmal die schnelle Lösung... zumal ich auch dachte das mein Problem ggf genau von der String verarbeitung käme ...

mal sehen ob ich das in eine FOR Schleife lege ...
dient ja alles nur zur mQTT übertragung ..