hi When I tried WIFI connection in code esp/esp-idf/example/bluetooth/gatt_client/main/gattc_demo.c , the code worked well. However, if i try to run
xTaskCreate(&aws_iot_mqtt_task, "AWS IoT", 8192*2, NULL, 5, NULL);
after wifi connection, the following error occurs.

So I tried adjusting the MAKE MENUCONFIG -> Component config -> mbededTLS -> TLS maximum message content length to 1000, 2000, 4000, 8000, 10000, 16000 etc, but the same error occurred and the esp32 module was rebooting.
In the blufi code as well, aws did not work. What is the problem?
This is the code.
What is free heap before you start the TLS operation?
How to check free heap?
xPortGetFreeHeapSize()
This is the result of inserting code
printf("xPortGetFreeHeapSize :%d\n", xPortGetFreeHeapSize() );
into each section.
Immediately after connecting the Bluetooth
-> 55660
Immediately after connecting wifi (place where code xTaskCreate(&aws_iot_mqtt_task, "AWS IoT", 8192*2, NULL, 5, NULL); should be inserted)
-> 54084
Bluetooth uses ~90k of heap (in your code)
AWS IoT about 60k
so you have 54k and need ~60k to do the handshake.
@copercini after task stack allocated should be 38k and with content length set to 4k it seems like it should be enough?
Introduction to main function before connecting Bluetooth.
-> 145692Immediately after connecting the Bluetooth
-> 55660
ok until here
Immediately after connecting wifi (place where code xTaskCreate(&aws_iot_mqtt_task, "AWS IoT", 8192*2, NULL, 5, NULL); should be inserted)
-> 54084
for TLS you need about 60k of heap... So your final heap should be -5k, which is impossible....
you got 54084 after, because TLS handshake fail and all heap was free when it occur.
Maybe it can be only problem in certificate, because -0x7200 is MBEDTLS_ERR_SSL_INVALID_RECORD, but I think it's probably out of heap.
@copercini test of HTTPS request example with 8k stack, 8k content length uses 32k max.
@negativekelvin I have tried the blufi example with the https example combined. That worked fine when modified the TLS message size shrunk to 8kB each.
But, when implemented AWS IoT, the message size does not seem enough. It disconnects from the client as soon as it successfully connects.
So the next thing I tried, was to have BLE and WiFi initiate separately. I would initiate BLE first, get SSID and password via text, wait for successful connection to WiFi, (by watching for GOT_IP event), I restart the chip, and connect to the memory-saved ssid and password. Even this fails with AWS IoT library implemented.
Only reason I try to use BLE here is for initial bootstrapping of the WiFi chip. When sent out the consumer, how could one provide SSID and password for home/work AP? Any other solution to this?
@copercini the error message displayed changes as I change the TLS message length. Although it states SSL_INVALID_RECORD, I agree that it is related to the memory.
@seopyoon Could you share your code? I'm very interested in this, as I'm sure plenty of other ESP32 developers are right now. Perhaps some extra eyes may yield something.
@copercini
Is there any idea to increase the heap size?
@ekfhdwofhd you can add a external SRAM chip. But most of the chips out there right now have a bug in the silicon itself which prevents use of external ram at the moment. Surely there must be a way to free up more heap somewhere. I don't see why a state machine which only allows BLE + Wifi (No TLS, just ping to confirm connect) and Wifi + TLS + AWS IoT wouldn't work. I'd really like to take a look at this code.
@ksitko sorry for the confusion. Having BLE+WIFI at one state, and WIFI+TLS on the other works. I had put bluetooth init code in the second stage when I said it didn't work.
@seopyoon so just to confirm, do you have AWS IoT working then? Would you be willing to share the code?
It's possible to cut the size of CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN from sdkconfig.h. Considerable gain in heap space but you will need to know there are no long messages being sent. I cut mine from 16384 to 4900. 4800 is the size of a certificate sent in my handshake. there are a few k's of heap space to gain from messing around with Bluetooth too, it doesn't matter if you are doing simple things like scanning advertisements or something like that.
Hi ekfhdwofhd, is this problem solved now?
Most helpful comment
@seopyoon Could you share your code? I'm very interested in this, as I'm sure plenty of other ESP32 developers are right now. Perhaps some extra eyes may yield something.