Running the following code on an ESP8266-1
#include <EEPROM.h> // To store wifi SSID and passwords in memory
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
int MAX_NUMBER_OF_STORED_WIFIS = 10;
char ssid[10][50];
char password[10][50];
void setup() {
Serial.begin(9600);
EEPROM.begin(1024);
Serial.println("Setup done...");
char ssid[] = "Ekman";
char password[] = "my password";
rearrangeMemory(ssid,password);
}
void loop() {
}
void writeWifiMemory() {
Serial.println("Writing new memory");
int p = 0;
for(int n = 0; n < MAX_NUMBER_OF_STORED_WIFIS;n++) {
for(int i = 0; i < strlen(ssid[n]); i++) {
EEPROM.write(p, ssid[n][i]);
EEPROM.commit();
Serial.print("Just wrote: ");
Serial.print(ssid[n][i]);
Serial.print(", on position: ");
Serial.print(p);
Serial.print(", and I read: ");
char tmpss = EEPROM.read(p);
Serial.println(tmpss);
p++;
}
EEPROM.write(p,';');
EEPROM.commit();
p++;
for(int i = 0; i < strlen(password[n]); i++) {
EEPROM.write(p, password[n][i]);
EEPROM.commit();
Serial.print("Just wrote: ");
Serial.print(password[n][i]);
Serial.print(", on position: ");
Serial.print(p);
Serial.print(", and I read: ");
char tmpss = EEPROM.read(p);
Serial.println(tmpss);
p++;
}
EEPROM.write(p,'\0');
EEPROM.commit();
p++;
}
EEPROM.write(p,'\0');
EEPROM.commit();
}
void rearrangeMemory(char tmp_ssid[50], char tmp_psw[50]) {
Serial.print("Re-arranging the memory by adding ");
Serial.print(tmp_ssid);
Serial.println(" on the top");
for(int n = MAX_NUMBER_OF_STORED_WIFIS;n >= 1;n = n - 1) {
for(int i = 0; i < 50; i++){
ssid[n][i] = ssid[n-1][i];
}
for(int i = 0; i < 50; i++){
password[n][i] = password[n-1][i];
}
}
for(int i = 0; i < 50; i++){
ssid[0][i] = tmp_ssid[i];
}
for(int i = 0; i < 50; i++){
password[0][i] = tmp_psw[i];
}
Serial.print("It has now been re-arranged, so ");
Serial.print(ssid[0]);
Serial.println(" is on the top");
writeWifiMemory();
}
and it returns this:
Setup done...
Re-arranging the memory by adding Ekman on the top
It has now been re-arranged, so Ekman is on the top
Writing new memory
Just wrote: E, on position: 0, and I read: �
Just wrote: k, on position: 1, and I read: �
Just wrote: m, on position: 2, and I read: �
Just wrote: a, on position: 3, and I read: �
Just wrote: n, on position: 4, and I read: �
Just wrote: m, on position: 6, and I read: �
Just wrote: y, on position: 7, and I read: �
Just wrote: , on position: 8, and I read: �
Just wrote: p, on position: 9, and I read: �
Just wrote: a, on position: 10, and I read: �
Just wrote: s, on position: 11, and I read: �
Just wrote: s, on position: 12, and I read: �
Just wrote: w, on position: 13, and I read: �
Just wrote: o, on position: 14, and I read: �
Just wrote: r, on position: 15, and I read: �
Just wrote: d, on position: 16, and I read: �
Why doesn't it return anything?