I’m thinking of a project which will require me to use the wifi.h library with an ESP32 and also write some variables to EEPROM. Does the wifi.h library use the EEPROM to store the network details? If so, how do I make sure not to use the addresses that the wifi library uses when writing my own variables?
That may help in a way but I will still need to use the wifi.h library as it will be a commercial project and the wifi.h library creates a web portal for people to store their own wifi credentials, as I wont know them in advance, the wifi.h library I assume must store it in the 512 bytes of EEPROM, but the Perferences library must also use the same EEPROM so maybe the two are not compatible. Essentially I will be storing wifi credentials and also som very basic user entered data to the EEPROM. I may need to look through the library code to see if they both use the EEPROM and if they use the same addresses.
Ah ok, my terminology is a little wrong, but still, if i use preferences library and wifi library, could there be an issue where they overwrite each other’s data in the flash storage? Or is there no risk of this?
The ESP32 has a memory space for Core0, a memory storage space for core1 and a shared memory space. When the WiFi.h is used from the Arduino ESP32 core, core0's memory space gets allocated for WiFI.
The default core for setup() and loop() is core1 and core 1's memory space.
WiFi uses some of the shard memory space, If core1 is not using freeRTOS then core1 does not use the shared memory space.
When creating task and using WiFi, pin all tasks to core1. Core0 can be used for user defined tasks but it is not recommended when WIFi is in use.
I have eaxmple code of the use of ps_calloc and ps_malloc. They work under the Arduino ESP32 core.
ETA, malloc is not aware of the ESP32's shared memory scheme, thus the reason for the macros.
ETA. There are other memory spaces available for the user such as RCT_SLOW and RTC_FAST. RTC SLOW memory can be used to pass data from the ULP processor to the main processor or have data persist across deep sleeps. While 8K of 32 bit RAM is available as RTC_SLOW ram the Arduino ESP32 core can only access 2K.
The code is open source, so you could have a look. A quick glance suggests that they either use SPIFFS or NVS, and the main concern is that there's an 'erase' function that seems to erase all flash/nvs contents indiscriminately. I leave further digging up to you. Just keep in mind that non-volatile storage on ESP platforms works in a more sophisticated way than on entry-level Arduinos where you basically have to manually keep track of what is stored in which location. The ESP platform takes over this task and functions more or less like a simple file system (SPIFFS) or database (NVS).