Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Help for storing variables in memory (non-volatile)#87

MattiaCC93 started this conversation inGeneral
Discussion options

Good morning,
I started from this (fantastic) project to make another one, open-source, and I need a suggestion.

I would need tostore some variables ( short strings and integers) onnon-volatile memory and I would like it to work with bothESP32 andESP8266. Unfortunately I am not an EEPROM and RTC memory expert.

➡️Which library / method should be used to avoid compatibility problems between ESP32 and ESP8622?
➡️ Onwhich memory areas can I write?

I would like my project to work with both hardware.

I will have to read these variables very frequently but, fortunately, I will write infrequently.

As soon as my project is at a good point I will make it public and insert the link of this, or I will fork!
A thousand thanks! 🙏🙏🙏

You must be logged in to vote

Replies: 10 comments

Comment options

My (open-source) project involves the construction of an IoT device that notifies the owner if the home's electricity fails. The goal is to create something very cheap.

There will be an external server (probably on amazon) that receives keepalives from various IoT devices.

Thanks! 🙏

You must be logged in to vote
0 replies
Comment options

I would need to store some variables ( short strings and integers) on non-volatile memory and I would like it to work with both ESP32 and ESP8266. Unfortunately I am not an EEPROM and RTC memory expert.

You can use built-in and betterLittleFS feature of ESP32/ESP8266 for this purpose. EEPROM or RTC has very limited storage and is not advisable to use, unless having very good reason (deep-sleep to save power, etc.).

I will have to read these variables very frequently but, fortunately, I willwrite infrequently.

write infrequently is very helpful as life-time of Flash is short if writing frequently (around 10,000 times or so)

It's also better to use myESP_WiFiManager_Lite library to save you lots of headache and unnecessary complexity (such as to understand and useJson to store / parse data by yourself).

This library as well asESP_WiFiManager_Lite can be used for either ESP32 or ESP8266, and you can read the open-source code to know how to auto-select the correct hardware in compiling.

Good Luck with your seeminglyhelpful andinteresting project.


When you have more experience,I suggest you use the much betterESPAsync_WiFiManager_Lite library.

Have a look atWhy Async is better

You must be logged in to vote
0 replies
Comment options

Thanks@khoih-prog, your words are very useful to me, like gold!

The string that I need to save into the ESP32/ESP8266 is the url of the external amazon server that the IoT device will have to contact every 60 seconds to send the keepalives. This string will presumably remain fixed but ... never say never!

I will study the LittleFS.

One question: why do you advise me to use theLite version of your library? I just managed to get the normal version to work .. should I change and switch to Lite? 😪 Remember: you are talking to a person who lives on powerpoint and excel and every time he has to write code .. he starts to sweat!

Currently I have mixed your library (the full, not the Lite) with a library for making HTTPS calls. The Client part is quite ready, the Server (AWS) part is almost ready. My wife is designing the 3D case of the device!

Greetings from Milan (Italy)

You must be logged in to vote
0 replies
Comment options

Ok, I saw that in your repositories there is always written "why" to choose one library or the other.
I have no excuses, I have to study what you wrote in thereadme of the projects.
Thanks again.

You must be logged in to vote
0 replies
Comment options

@khoih-prog sorry if i contact you for this question.

I just bought five 5️⃣ESP32-WROOM-32 and would like to have a unique key to distinguish them.

I noticed that theESP_getChipId() function returns thesame value for all 5 devices!! 😨

Do you have any quick-win tips?

Thanks you

You must be logged in to vote
0 replies
Comment options

For ESP32, ESP_getChipId() is defined as

#define ESP_getChipId()   ((uint32_t)ESP.getEfuseMac())

Try the official ESP32 exampleGetChipID to see if OK.

You have to use 64 bit to avoid duplication, such as

#define ESP_getChipId()   ((uint64_t)ESP.getEfuseMac())

Modified code

/* The true ESP32 chip ID is essentially its MAC address.This sketch provides an alternate chip ID that matches the output of the ESP.getChipId() function on ESP8266 (i.e. a 32-bit integer matching the last 3 bytes of the MAC address. This is less unique than the MAC address chip ID, but is helpful when you need an identifier that can be no more than a 32-bit integer (like for switch...case).created 2020-06-07 by cweinhoferwith help from Cicicok */uint32_t chipId = 0;void setup() {Serial.begin(115200);while (!Serial && millis() < 5000);}void loop() {for(int i=0; i<17; i=i+8) {  chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;}Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());Serial.printf("This chip has %d cores\n", ESP.getChipCores());        Serial.print("Chip ID: 0x"); Serial.println(chipId, HEX);        Serial.print("getEfuseMac: 0x"); Serial.println((uint64_t)ESP.getEfuseMac(), HEX);  delay(3000);}
You must be logged in to vote
0 replies
Comment options

Tested on several ESP32 boards.

ESP32 Chip model = ESP32-D0WDQ5 Rev 1This chip has 2 coresChip ID: 0x91248getEfuseMac: 0x481209ABF498

ESP32 Chip model = ESP32-D0WDQ5 Rev 1This chip has 2 coresChip ID: 0x85288getEfuseMac: 0x885208ABF498

ESP32 Chip model = ESP32-D0WDQ5 Rev 1This chip has 2 coresChip ID: 0x90ADCgetEfuseMac: 0xDC0A09ABF498

ESP32 Chip model = ESP32-D0WDQ6 Rev 1This chip has 2 coresChip ID: 0xE968A9getEfuseMac: 0xA968E92DE6B4
You must be logged in to vote
0 replies
Comment options

BTW, this is the better code, to identify Organizational Unique Identifier (OUI) as well as 24-bit chipID

/* The true ESP32 chip ID is essentially its MAC address.  This sketch provides an alternate chip ID that matches  the output of the ESP.getChipId() function on ESP8266  (i.e. a 32-bit integer matching the last 3 bytes of  the MAC address. This is less unique than the  MAC address chip ID, but is helpful when you need  an identifier that can be no more than a 32-bit integer  (like for switch...case).  created 2020-06-07 by cweinhofer  with help from Cicicok */uint32_t chipId = 0;void setup(){  Serial.begin(115200);  //while (!Serial);  while (!Serial && millis() < 5000);}void loop(){  Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());  Serial.printf("This chip has %d cores\n", ESP.getChipCores());  uint64_t chipId64 = 0;  for (int i = 0; i < 6; i++)  {    chipId64 |= ( ( (uint64_t) ESP.getEfuseMac() >> (40 - (i * 8)) ) & 0xff ) << (i * 8);  }  // Organizational Unique Identifier (OUI)  uint32_t chipOUI = chipId64 >> 24;  uint64_t chipId24 = chipId64 & 0xFFFFFF;  Serial.print("Chip_ID_64: 0x"); Serial.println(chipId64, HEX);  Serial.print("chipOUI: 0x");  Serial.println(chipOUI, HEX);  Serial.print("chipId24: 0x"); Serial.println(chipId24, HEX);  Serial.print("getEfuseMac: 0x"); Serial.println((uint64_t)ESP.getEfuseMac(), HEX);  delay(60000);}

Output

ESP32 Chip model = ESP32-D0WDQ5 Rev 1This chip has 2 coresChip_ID_64: 0x98F4AB085288chipOUI: 0x98F4ABchipId24: 0x85288getEfuseMac: 0x885208ABF498
You must be logged in to vote
0 replies
Comment options

Hi@MattiaCC93

The newESP_WiFiManager releases v1.11.0 has just been published to fix theESP32 chipID bug. Your contribution is noted inContributions and Thanks.

Be confident now and spot many more bugs 👍

Best Regards,


Releases v1.11.0

  1. Fix ESP32 chipID. CheckHelp for storing variables in memory (non-volatile) #87
  2. Add ESP32 ESP_getChipOUI() function
  3. Display new info on Config Portal for ESP32
  4. Remove dependency onLittleFS_esp32 library to prevent PIO error when using new ESP32 core v1.0.6+

Info

You must be logged in to vote
0 replies
Comment options

Thank you@khoih-prog ! For me it is an honor

You can see my ESP32 happy to have a unique ChipID()..
image

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
2 participants
@MattiaCC93@khoih-prog

[8]ページ先頭

©2009-2025 Movatter.jp