Change Ip address from HTML web server (

Greetings to everyone. Please consider me a “NOOB” on this, so be patient :confused:

I have a project, i want to build a device that let me turn on/off devices remotly. So with an arduino uno R3 + ethernet shield (esp8266 based) i want to build a web server, with a basic authentication (usr/pass) and manage 2 relays; i have done that part, i have a functional device.

But now, i want to go for more, and im stuck. I want to change IP, MASK, Gateway and, occasionally the mac address,… and if I can user and password too, like a low price router o network device.

So i found some code on this forum, i just forgot the relay control part and im only triying to success with the IP change from the HTML code (web server). I have found the eeprom.h library, and a some code, but the post chance was closed (topic: 120 days old).

I will left the code i adapted and the error im receiving…

Sketch:

#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
IPAddress ip(192, 168, 1, 250);
IPAddress subnet(255, 255, 254, 0);
IPAddress gateway(192, 168, 1, 1);


EthernetServer server(80);

void setup() {

ShieldSetup();
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
  


}

void ShieldSetup() {
  int idcheck = EEPROM.read(0);

  if (idcheck != ID){

  }
  if (idcheck == ID){
    
    for (int i = 0; i < 4; i++){
      ip[i] = EEPROM.read(i+7);
    }
    for (int i = 0; i < 4; i++){
      subnet[i] = EEPROM.read(i+11);
    }
    for (int i = 0; i < 4; i++){
      gateway[i] = EEPROM.read(i+15);
    }
  }      
  Ethernet.begin(mac, ip);
}

void loop() {
 
      EthernetClient client = server.available();
      if (client) {
      TextFinder  finder(client );
      while (client.connected()) {     
      if (client.available()) {
       
        if( finder.find("GET /") ) {
         
          if (finder.findUntil("setup", "\n\r")){
           
          if (finder.findUntil("SBM", "\n\r")){
            byte SET = finder.getValue();
           
              while(finder.findUntil("DT", "\n\r")){
                int val = finder.getValue();
                // if val from "DT" is between 1 and 6 the according value must be a MAC value.
                if(val >= 1 && val <= 6) {
                  mac[val - 1] = finder.getValue();
                }
                // if val from "DT" is between 7 and 10 the according value must be a IP value.
                if(val >= 7 && val <= 10) {
                  ip[val - 7] = finder.getValue();
                }
                // if val from "DT" is between 11 and 14 the according value must be a MASK value.
                if(val >= 11 && val <= 14) {
                  subnet[val - 11] = finder.getValue();
                }
                // if val from "DT" is between 15 and 18 the according value must be a GW value.
                if(val >= 15 && val <= 18) {
                  gateway[val - 15] = finder.getValue();
                }
              }
            // Now that we got all the data, we can save it to EEPROM
            //for (int i = 0 ; i < 6; i++){
              //EEPROM.write(i + 1,mac[i]);
            //}
            for (int i = 0 ; i < 4; i++){
              EEPROM.write(i + 7, ip[i]);
            }
            for (int i = 0 ; i < 4; i++){
              EEPROM.write(i + 11, subnet[i]);
            }
            for (int i = 0 ; i < 4; i++){
              EEPROM.write(i + 15, gateway[i]);
            }
            EEPROM.write(0, 0x92);
           }
          // and from this point on, we can start building our setup page
          // and show it in the client's browser.
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          for (int i = 0; i < 4; i++)
            {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table0[i])));
            client.print( buffer );
            }
          for (int i = 0; i < 3; i++)
            {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[i])));
            client.print( buffer );
            }
          client.print(mac[0],HEX);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[3])));
          client.print( buffer );
          client.print(mac[1],HEX);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[4])));
          client.print( buffer );
          client.print(mac[2],HEX);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[5])));
          client.print( buffer );
          client.print(mac[3],HEX);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[6])));
          client.print( buffer );
          client.print(mac[4],HEX);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[7])));
          client.print( buffer );
          client.print(mac[5],HEX);
          for (int i = 0; i < 4; i++)
            {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[i])));
            client.print( buffer );
            }
          client.print(ip[0],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[4])));
          client.print( buffer );
          client.print(ip[1],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[5])));
          client.print( buffer );
          client.print(ip[2],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[6])));
          client.print( buffer );
          client.print(ip[3],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[0])));
          client.print( buffer );
          client.print(subnet[0],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[1])));
          client.print( buffer );
          client.print(subnet[1],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[2])));
          client.print( buffer );
          client.print(subnet[2],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[3])));
          client.print( buffer );
          client.print(subnet[3],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[0])));
          client.print( buffer );
          client.print(gateway[0],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[1])));
          client.print( buffer );
          client.print(gateway[1],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[2])));
          client.print( buffer );
          client.print(gateway[2],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[3])));
          client.print( buffer );
          client.print(gateway[3],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[4])));
          client.print( buffer );
          for (int i = 0; i < 7; i++)
            {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table5[i])));
            client.print( buffer );
            }
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[5])));
          client.print( buffer );
          client.println();
          client.println();
         
 (F("<tr><td><font color=\"red\" size=\"2\" 
face=\"Verdana\">&nbspYou can not change the MAC 
address</font></td></tr></table>
"));
      }}}}
    delay(1);
    client.stop();
  }
 }

Error (at least one of them): Marked on the line:

void ShieldSetup() {
  int idcheck = EEPROM.read(0);

  if (idcheck != ID){  <------ ERROR

‘ID’ was not declared in this scope

Maybe its an ambitious goal to me, (too high over my possibilities or skills, but but a guy says : “your only real obstacle is yourself”, so thats why im posting… keep trying.

Thank you

Welcome to the forum.

The errors tells you that the compiler does not know what ID means? Every variable need to be declared. For instance,

int value = 0;

tells the compiler create a variable of type integer and call it value. Now when you call

value = 5;

the compiler knows, that is the variable you declared earlier.

ID does not need to be a variable. It could be a constant. Constants are created by using #define.

#define value 5

Now you can use value instead of 5 but you cannot change it.

Scope is a concept that allows variable names to be reused under certain rules without creating conflict. For more details Google "C++ scope".

Do you have a link to where you got the code from as this may give us a clue as to what ID is or how it is defined?