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();
}