Skip to main content
deleted 5037 characters in body
Source Link

EDIT: per feedback, removed all but the function, with the EEPROM.commit(); suggestion included... still not working

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "xxxxxxxx";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100115200);
         }
    }
  }


void EEPROM_Write(){
SerialEEPROM.begin(115200280);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.printcommit("loading program from EPROM: "); 
   // SerialEEPROM.printlnend(pwmarray1[x]);
    }
}
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "xxxxxxxx";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100);
         }
    }
  }


void EEPROM_Write(){
Serial.begin(115200);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.print("loading program from EPROM: "); 
    Serial.println(pwmarray1[x]);
    }
}

EDIT: per feedback, removed all but the function, with the EEPROM.commit(); suggestion included... still not working

void EEPROM_Write(){
Serial.begin(115200);
EEPROM.begin(280);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();
  EEPROM.commit();
 // EEPROM.end();
}
Removed swear word, fixed syntax highlighting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

first time posting. I am struggling through a program. I am trying to store my uploaded string into an array then write that array to EEPROM. I run the program, upload the new array and store it in the EEPROM. all values display correctly until I reset or power off the device. I am sure I am overwriting or something obvious, but i am breaking down and asking for help.

the read and write EEPROM subroutines are at the bottom of the code. I call the EEPROM_Write() in server.on after parsing the http get.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "fuckhead";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100);
         }
    }
  }


void EEPROM_Write(){
Serial.begin(115200);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.print("loading program from EPROM: "); 
    Serial.println(pwmarray1[x]);
    }
}

The read and write EEPROM subroutines are at the bottom of the code. I call the EEPROM_Write() in server.on after parsing the http get.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "xxxxxxxx";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100);
         }
    }
  }


void EEPROM_Write(){
Serial.begin(115200);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.print("loading program from EPROM: "); 
    Serial.println(pwmarray1[x]);
    }
}

first time posting. I am struggling through a program. I am trying to store my uploaded string into an array then write that array to EEPROM. I run the program, upload the new array and store it in the EEPROM. all values display correctly until I reset or power off the device. I am sure I am overwriting or something obvious, but i am breaking down and asking for help.

the read and write EEPROM subroutines are at the bottom of the code. I call the EEPROM_Write() in server.on after parsing the http get.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "fuckhead";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100);
         }
    }
  }


void EEPROM_Write(){
Serial.begin(115200);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.print("loading program from EPROM: "); 
    Serial.println(pwmarray1[x]);
    }
}

I am struggling through a program. I am trying to store my uploaded string into an array then write that array to EEPROM. I run the program, upload the new array and store it in the EEPROM. all values display correctly until I reset or power off the device. I am sure I am overwriting or something obvious, but i am breaking down and asking for help.

The read and write EEPROM subroutines are at the bottom of the code. I call the EEPROM_Write() in server.on after parsing the http get.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "xxxxxxxx";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100);
         }
    }
  }


void EEPROM_Write(){
Serial.begin(115200);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.print("loading program from EPROM: "); 
    Serial.println(pwmarray1[x]);
    }
}
Source Link

Need help with EEPROM not storing array values on ESP8266 after restart

first time posting. I am struggling through a program. I am trying to store my uploaded string into an array then write that array to EEPROM. I run the program, upload the new array and store it in the EEPROM. all values display correctly until I reset or power off the device. I am sure I am overwriting or something obvious, but i am breaking down and asking for help.

the read and write EEPROM subroutines are at the bottom of the code. I call the EEPROM_Write() in server.on after parsing the http get.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <EEPROM.h>

int pwmarray1[60];

//EPROM VARIABLES
const unsigned EEPROMStartAdress = 0;
const unsigned pwmarray1Size = sizeof pwmarray1 / sizeof pwmarray1[0];

//Fan pins
int fan_pin1 = 0;
int fan_pin2 = 14;

const char* ssid     = "fuckhead";
const char* password = "password";

//field inputs varaibles 
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "imput3";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

AsyncWebServer server(80);

// HTML web page
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>FAN CONTROLLER v1.0</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body bgcolor="#abd0eb">
  <font color="#333333" face="Verdana, Geneva, sans-serif">FAN CONTROLLER v1.0</font>
  <hr style="width:25%;text-align:left;margin-left:0">
  <br>
  <form action="/fanprogram">
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-1">Fan pattern:</font><br>
    <font color="#333333" face="Verdana, Geneva, sans-serif" size="-2">format: FAN 1 value, FAN 2 Value, Time value</font>
    <BR>
    <textarea rows="10" cols="50" name="input1"></textarea><br>
    <input type="submit" value="Submit">
  </form><br>
</body></html>)rawliteral";

void setup(){


    //Declaring FANs  pin as output
  pinMode(fan_pin1, OUTPUT);
  pinMode(fan_pin2, OUTPUT);
  Serial.begin(115200);
  analogWriteFreq(4163);
  
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Print ESP8266 Local IP Address
  Serial.println(WiFi.localIP());


  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });
  


server.on("/fanprogram", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;

    char valinput[299+1];
    
    // GET input1 value on <ESP_IP>/fanprogram?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      inputMessage.toCharArray(valinput,300);

      // Read each command pair 
      char* command = strtok(valinput, ",");
      int index = 0;
      memset(pwmarray1, 0, sizeof(pwmarray1));
      while (command != 0)
      {
        int fanval = atoi(command);
        pwmarray1[index] = fanval;
        index++;
        
        // Find the next command in input string
        command = strtok(0, ",");
        
      }
    EEPROM_Write();
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", 
                                     "Pattern uploaded to Fan Controller (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);

  // Start server
  server.begin();
}


//fan control loop
void loop(){
    if(pwmarray1[0]<1){
    Serial.print("Array is empty, awaiting program.... FEED ME, SEYMOUR!!!"); 
    Serial.println();
    delay(1500);
    }

    else{      
  EEPROM_Read();
for (int i=0; i<20; i++){
  int fan1speed = pwmarray1[i*3];
  Serial.print(fan1speed, DEC); Serial.println();
  int fan2speed = pwmarray1[i*3+1];
  Serial.print(fan2speed, DEC); Serial.println();
  int currentsteptime = pwmarray1[i*3+2];
  Serial.print(currentsteptime, DEC); Serial.println();
  delay(currentsteptime * 100);
         }
    }
  }


void EEPROM_Write(){
Serial.begin(115200);
  // store values in EEPROM
  for (int i = 0; i < pwmarray1Size; i++)
  {
    Serial.println(pwmarray1[i]);
    EEPROM.put( EEPROMStartAdress + (i * sizeof pwmarray1[0]), pwmarray1[i]);
  }
  Serial.println();}

void EEPROM_Read(){
   //load array pwmarray1 with stored values in EPROM
  for (int x = 0; x < pwmarray1Size; x++){
    EEPROM.get(EEPROMStartAdress + (x * sizeof pwmarray1[0]), pwmarray1[x]);
        Serial.print("loading program from EPROM: "); 
    Serial.println(pwmarray1[x]);
    }
}