Bluetooth low energy taking up a lot of heap
Posted: 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:
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.
Thanks
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();
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();
}