Open wegunterjr opened 6 years ago
Like i said before, you have to change order you are doing your calls.
You need at least 75kB free heap to even start with mbedTLS (or maybe even more). To get even more free ram i had to delete default task in arduino:
vTaskDelete(NULL)
in setup(), this gives me about 7kB, but you have to replace it with your own task with heap 2-4kB stackAlso, like i said before (maybe its bad idea), i have task which is doing some operations and create another task and delete itself. This way im in position where my last task is using minimum amount of heap.
There is still big issue, when your aws IoT disconnecting for some reason, you wont be able to connect because there is not enough free heap. Stopping ble, deleting ble task or any other actions on ble wont help because bluedroid stack (esp-idf ble) is statically load into ram.
@chegewara WOW! 75K.... I did release bt classic memory in setup(), and that is a little better, but still... wow!
Its mostly because mbedTLS handshake requires 2 buffers (TX and RX) 15kB each. Then library itself and probably aes library, its a lot.
How do you get 200k?
Hi, its very hard to make it both work together. Its because ble is using a lot of ram and mbedTLS (ssl) needs a lot of ram for handshake. You can make it work togheter, but you need to free as much heap as you can before you even start, then connect with aws mqtt and when you are connected then you can finally connect to ble peer device. In my app i am starting with over 200kB free heap and when i am connected to ble device i have about 20kB free heap.
my challenge is that the user workflow i am working on now has them find the device using BLE then connect to wifi... I guess I could consider alternative workflow...
I dont remember, but right now just to check it and i have less:
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310
FREE stack: 7492
FREE heap: 183108
Here is few lines of my setup():
void setup() {
Serial.begin(115200);
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
Serial.print("FREE stack: ");
Serial.println(uxTaskGetStackHighWaterMark(NULL));
Serial.print("FREE heap: ");
Serial.println(esp_get_free_heap_size());
BLEDevice::init("");
And all includes, but im not sure i am using all right now:
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <MQTTClient.h> //you need to install this library: https://github.com/256dpi/arduino-mqtt
#include <ArduinoJson.h>
#include "BLEDevice.h"
#include <freertos/event_groups.h>
This is my heap readout during each step of connection. It gets to the handshake part with about 68k, but it fails there.. any suggestions? `
`