Mathias DA COSTA
Mathias DA COSTA

Reputation: 13

Guru meditation error (LoadProhibited) on BLEDevice::Init with ESP32Cam

I'm struggling with a Guru meditation error when I try to use BLEDevice::Init to get credential from a smartphone.

The begining of my code works but when I reach the Init part, I got this message :

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40099c19  PS      : 0x00060330  A0      : 0x8009a8d2  A1      : 0x3ffdbf00  
A2      : 0xffffffff  A3      : 0xffffffff  A4      : 0x20000000  A5      : 0x00060f23  
A6      : 0x00060f20  A7      : 0x00000001  A8      : 0x00000003  A9      : 0x00000006  
A10     : 0x00000027  A11     : 0x0000111c  A12     : 0x00000013  A13     : 0x00000040  
A14     : 0xfffffffc  A15     : 0x00001ebc  SAR     : 0x00000007  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x0000002b  LBEG    : 0x40092a70  LEND    : 0x40092a7b  LCOUNT  : 0x00000000  

Here some sample of my code :

Definition of characteristics and other :

BLEServer *pServer = NULL;
BLECharacteristic *pCharCredential = NULL;
BLECharacteristic *pCharMacAddr = NULL;
BLECharacteristic *pCharMacExtAddr = NULL;
BLECharacteristic *pCharBatLvl = NULL;

BLEService *pService = NULL;
BLEAdvertising *pAdvertising = NULL;

Callbacks :

class MyServerCallbacks : public BLEServerCallbacks
{
  void onConnect(BLEServer *pServer)
  {
    BLEDevice::startAdvertising();
  };
};

class credentialCallback : public BLECharacteristicCallbacks
{
  void onWrite(BLECharacteristic *pCharacteristic)
  {
    std::string value = pCharacteristic->getValue();
    // Store here SSID and password
    SSID = value.substr(0, value.find('|'));
    PWD = value.substr(value.find('|') + 1, value.size());
    state = STATE_SWITCH_MODE;
  }
};

And finally, the part where the exception occures :

case STATE_BLE:
    BLEDevice::init(DEVICE_NAME); // <----- bug here
  

    pServer = BLEDevice::createServer();
    pServer->setCallbacks(new MyServerCallbacks());

    pService = pServer->createService(SERVICE_UUID);

    // Credential
    pCharCredential = pService->createCharacteristic(
        CREDENTIAL_UUID,
        BLECharacteristic::PROPERTY_READ |
            BLECharacteristic::PROPERTY_WRITE |
            BLECharacteristic::PROPERTY_NOTIFY |
            BLECharacteristic::PROPERTY_INDICATE);

    pCharCredential->setCallbacks(new credentialCallback());
    pCharCredential->addDescriptor(new BLE2902());

    // Main cam mac
    pCharMacAddr = pService->createCharacteristic(
        MAC_UUID,
        BLECharacteristic::PROPERTY_READ |
            BLECharacteristic::PROPERTY_WRITE |
            BLECharacteristic::PROPERTY_NOTIFY |
            BLECharacteristic::PROPERTY_INDICATE);

    pCharMacAddr->setValue(WiFi.macAddress().c_str());
    pCharMacAddr->addDescriptor(new BLE2902());

    // Secondary cam mac
    pCharMacExtAddr = pService->createCharacteristic(
        MAC_EXT_UUID,
        BLECharacteristic::PROPERTY_READ |
            BLECharacteristic::PROPERTY_WRITE |
            BLECharacteristic::PROPERTY_NOTIFY |
            BLECharacteristic::PROPERTY_INDICATE);

    pCharMacExtAddr->setValue(macExtCam.c_str());
    pCharMacExtAddr->addDescriptor(new BLE2902());

    // Battery level
    pCharBatLvl = pService->createCharacteristic(
        BAT_LVL_UUID,
        BLECharacteristic::PROPERTY_READ |
            BLECharacteristic::PROPERTY_WRITE |
            BLECharacteristic::PROPERTY_NOTIFY |
            BLECharacteristic::PROPERTY_INDICATE);

    char ctable[5];
    sprintf(ctable, "%d", batLvl);
    pCharBatLvl->setValue(ctable);
    pCharBatLvl->addDescriptor(new BLE2902());

    pService->start();

    pAdvertising = BLEDevice::getAdvertising();
    pAdvertising->addServiceUUID(SERVICE_UUID);
    pAdvertising->setScanResponse(false);
    pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
    BLEDevice::startAdvertising();

    delay(10);
    state = STATE_IDLE;
    break;

One detailed that I have forget is that the problem just appeared few days ago, but it was working before (from October 2022 to 9 March 2023). This detail lead me to some debug try listed below.

I have been struggling since few day and I have tried many things, but always leads to the same error:

Hardware problems :

Software problems :

By watching error message: the problem seems to be a memory allocation problem, but I can't find why it occurs.

Can anyone help me ?

Edit 1 : Add test on NULL pointer before using pServer, pService and all pCharacteristics, but change nothing :

    pServer = BLEDevice::createServer();
    if (pServer == NULL)
    {
      Serial.println("Can't create server");
      break;
    }

Upvotes: 0

Views: 422

Answers (1)

Mathias DA COSTA
Mathias DA COSTA

Reputation: 13

After 3 weeks, I finnaly find why the error occurs. It seems to be a problem of naming, I change the name provided in BLEDevice::Init then pushed the code, and it worked. I gave the old name and it worked again.

Upvotes: 1

Related Questions