Bluetooth low energy taking up a lot of heap

cyborgium
Posts: 1
Joined: Mon Oct 08, 2018 2:10 pm

Bluetooth low energy taking up a lot of heap

Postby cyborgium » Tue Jan 22, 2019 2:28 pm

Hi,

I'm working on a project which requires BLE. I'm basically finished with the project, however I've ran out of heap. Using the following line I was able to narrow down what uses it all up:

Code: Select all

ESP.getFreeHeap();
As you might have guessed by the title, it's BLE. I don't know much about BLE but I found an example project that basically does what I need it to, send and receive json strings: https://desire.giesecke.tk/index.php/20 ... -over-ble/

So my question, is there something I can do more efficiently BLE wise that would save me some heap? Below is the code that initialises BLE, I think that's enough though if you'd require more of my code to answer my question, do let me know.

Code: Select all

/** Characteristic for digital output */
BLECharacteristic *pCharacteristicWiFi;
/** BLE Advertiser */
BLEAdvertising* pAdvertising;
/** BLE Service */
BLEService *pService;
/** BLE Server */
BLEServer *pServer;

void initBLE() {
  Serial.println("Initialising BLE...");
  // Initialize BLE and set output power
  BLEDevice::init(apName);
  BLEDevice::setPower(ESP_PWR_LVL_P7);

  // Create BLE Server
  pServer = BLEDevice::createServer();

  // Set server callbacks
  pServer->setCallbacks(new BLECallbackHandler());

  // Create BLE Service
  pService = pServer->createService(BLEUUID(SERVICE_UUID), 20);

  // Create BLE Characteristic for WiFi settings
  pCharacteristicWiFi = pService->createCharacteristic(
                          BLEUUID(WIFI_UUID),
                          // WIFI_UUID,
                          BLECharacteristic::PROPERTY_READ |
                          BLECharacteristic::PROPERTY_WRITE
                        );
  pCharacteristicWiFi->setCallbacks(new MyCallbackHandler());

  // Start the service
  pService->start();

  // Start advertising
  pAdvertising = pServer->getAdvertising();
  pAdvertising->start();
}
Thanks

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Bluetooth low energy taking up a lot of heap

Postby chegewara » Fri Jan 25, 2019 8:20 pm

Yes, using ble with arduino is not easy because you cant free bt classic heap. Ive heard that arduino bt hal is doing this, but i cant confirm.

Basically bluetooth is reserving about 70kB from heap.

Who is online

Users browsing this forum: No registered users and 160 guests