c_cpp 读/写ESP8266 EEPROM - 来自https://forum.arduino.cc/index.php?topic=461677.0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 读/写ESP8266 EEPROM - 来自https://forum.arduino.cc/index.php?topic=461677.0相关的知识,希望对你有一定的参考价值。
#include <EEPROM.h>
char wifi_ssid_private[32];
char wifi_password_private[32];
char clientName[10] = "newClient";
char ipAddr[16] = "172.024.001.001";//Pi Access Point IP-Adr.
//startAdr: offset (bytes), writeString: String to be written to EEPROM
void writeEEPROM(int startAdr, int laenge, char* writeString) {
EEPROM.begin(512); //Max bytes of eeprom to use
yield();
Serial.println();
Serial.print("writing EEPROM: ");
//write to eeprom
for (int i = 0; i < laenge; i++)
{
EEPROM.write(startAdr + i, writeString[i]);
Serial.print(writeString[i]);
}
EEPROM.commit();
EEPROM.end();
}
void readEEPROM(int startAdr, int maxLength, char* dest) {
EEPROM.begin(512);
delay(10);
for (int i = 0; i < maxLength; i++)
{
dest[i] = char(EEPROM.read(startAdr + i));
}
EEPROM.end();
Serial.print("ready reading EEPROM:");
Serial.println(dest);
}
void setup() {
Serial.begin(9600);
delay(100);
strcat(wifi_ssid_private, "SSID1234");
strcat(wifi_password_private, "PW1234");
writeEEPROM(0,32,wifi_ssid_private);//32 byte max length
writeEEPROM(32,32, wifi_password_private);//32 byte max length
writeEEPROM(64,10, clientName);//10 byte max length
writeEEPROM(74,16, ipAddr);//16 byte max length
/*85 byte saved in total?*/
Serial.println("everything saved...");
readEEPROM(0,32,wifi_ssid_private);
readEEPROM(32,32,wifi_password_private);
readEEPROM(64,10,clientName);
readEEPROM(74,16,ipAddr);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Loop");
delay(1000);
}
以上是关于c_cpp 读/写ESP8266 EEPROM - 来自https://forum.arduino.cc/index.php?topic=461677.0的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp 通过ESP8266 EEPROM中的网页提供WIFI SSID,密码和Blynk密钥 - 来自https://community.blynk.cc/t/feeding-wifi-ssid-
Arduino ESP8266 For EEPROM经典应用案例二
Arduino ESP32/8266 利用EEPROM对数据进行读写操作
Arduino ESP8266 For EEPROM数据存储示例
Arduino ESP8266 For EEPROM经典应用案例一
Arduino ESP8266 SmartConfig配网+EEPROM保存+OLED显示