The skectch I've upload crashes random (sometimes after 48h).
=> I'm trying to detect the memory corruption using heap_caps_check_integrity_all and heap_caps_print_heap_info
Unfortunately, heap_caps_print_heap_info doesn't print anything on serial monitor.
Q1. Is there any chance to make heap_caps_print_heap_info to print info to the serial monitor?
Q2. What method did you use to track down a mem. corruption on Nano ESP32?
Indeed, I'm using String class a lot. But it is going to be a nightmare to replace it.
I also use esp_now protocol to communicate between two Nano ESP32.
When the board is in the default configuration produced by having Tools > USB Mode > Normal mode (TinyUSB) selected from the Arduino IDE menus, stdout is printed to the hardware serial interface on pins 0 and 1. You can connect a USB to serial bridge module or cable (AKA "FTDI") to those pins. If you open the port of the bridge in a terminal (you can use the Arduino IDE Serial Monitor if you like) and configure it for 115200 baud, you will then see the heap information.
I'm not sure if there is a way to redirect the stdout to the TinyUSB CDC port of the board's USB connection.
You can get the stdout on the board's CDC port if you select Tools > USB Mode > Debug mode (Hardware CDC) from the Arduino IDE menus and then upload the sketch again, following the procedure documented here:
(stop when you get to the "Start Debugging" section of the tutorial, since the instructions from then on are specific to using the IDE's integrated sketch debugger rather than about configuring the board's USB mode in general)
After that, you will see the information from heap_caps_print_heap_info printed in Serial Monitor when connected to the normal port of the Nano ESP32 board.
Please note that, due to a quirk of the "esp32" boards platform configuration, when the board is configured in this "Hardware CDC" mode, it will be identified as a random ESP32 board by Arduino IDE. Please ignore the inappropriate identification. Just make sure that you always have Tools > Board > Arduino ESP32 Boards > Arduino Nano ESP32 selected in the Arduino IDE menus instead of whatever random board it is being identified as and everything will work fine.
That is managed by the Espressif guys. I might be mistaken, but I think the fix is part of the upcoming arduino-esp32 3.x core (a 3.0.0RC1 is available on their development json). As it's a major release there are many differences, be sure to check the migration guide if you want to try it out