# Set/Change IP Address Web Form - Ethernet Shield

**URL:** <https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392>\
**Category:** General Guidance\
**Created:** [March 4, 2011, 6:45pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392 "2011-03-04T18:45:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 4, 2011, 6:45pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/1 "2011-03-04T18:45:20Z")

</div>

I am attempting to extract an IP address string from a web page set IP address form (working) and overwrite the IP address in the static byte ethernet definition (not working):

Can any one help?

Here is the code so far:

```cpp
//default
static uint32_t ipA=172;
static uint32_t ipB=31;
static uint32_t ipC=1;
static uint32_t ipD=50;

static byte ip[] = { ipA, ipB, ipC, ipD };

 client << F("
") << endl;
          client << F("
") << endl;                
          client << F("Change IP Address:") << endl; 
            client << F("<form name=\"changeipaddress\" action=\"\" method=\"get\">") << endl;
             client << F("<TABLE>") << endl; 
		client << F("<td>IP Address:</td> ");
			client << F("<td style=\"padding-left:10;\"><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip1\" value=\"\"></td>  ");
			client << F("<td><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip2\" value=\"\"></td>  ");
			client << F("<td><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip3\" value=\"\"></td>  ");
			client << F("<td><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip4\" value=\"\"></td>  ");
			client << F("<td colspan=3></td>  ");
		client << F("</tr>  ");  
              
              client << F("<tr><td colspan=\"8\"><input type=\"submit\" value=\"Update\"></td></tr>   ");

             client << F("</TABLE>") << endl; 
            client << F("</form>") << endl;
   
   

       client.println("
");

         
        //String stringTEST = "?ip1=172&ip2=31&ip3=1&ip4=50"; //diag example string
       String stringTEST = stringOne;
       // client.println( stringTEST ); //diag

        int firstequal = stringTEST.indexOf('=');
        int secondequal = stringTEST.indexOf('=', firstequal + 1);
        int thirdequal = stringTEST.indexOf('=', secondequal + 1);
        int fourthequal = stringTEST.indexOf('=', thirdequal + 1);
        
        int firstand = stringTEST.indexOf('&');
        int secondand = stringTEST.indexOf('&', firstand + 1);
        int thirdand = stringTEST.indexOf('&', secondand + 1);
        int fourthand = stringTEST.indexOf('H');      
        
     
              
              client.println("
");
              client.println("IP Address Currently Set To:");  
              client.println("
");
          
          if (stringOne.substring(6,14) == "HIGHTEMP") {
           //client.print("Ignore Temperature String in IP Form"); //for diag ignore temperature set string
          }
          else if (firstequal == -1) {
            //client.print("IP Address Not Entered Correctly");   //for diag         
          }
              else {
            
              client.print(stringTEST.substring(firstequal + 1,firstand)); 
                       client.println(".");         
              client.print(stringTEST.substring(secondequal + 1,secondand)); 
                         client.println(".");                 
              client.print(stringTEST.substring(thirdequal + 1,thirdand)); 
                         client.println(".");                      
              client.println(stringTEST.substring(fourthequal + 1, fourthand - 1));

              //MKM Attempt to set IP address octet 4              
              //stringTEST.substring(fourthequal +1, fourthand -1) = ipD;
              
              
              
              //String ipD_String = stringTEST.substring(fourthequal +1, fourthand -1);
              
              
              client.println("
");
              
              
              //client.println(ipD_String);
              
              //ipD=57; //compiled with just this line
              //ipE=ipD_String; //NO GO
              
              //String ipE =  String('ipD_String');                       // converting a constant char into a String NO GO

              String ipD_string =  String(  stringTEST.substring(fourthequal +1, fourthand -1)            ); 
 
              int n4_IP;
              char carray[6];
              ipD_string.toCharArray(carray, sizeof(carray));
              n4_IP = atoi(carray);
              
              client.println("
");
              
              client.println(n4_IP);
              
             // static uint32_t ipD=n4_IP; // MKM - caused compile error undefined reference to __cxa_guard_acuire
              ipD=n4_IP; //works, ip changes in serial output, but static IP does not change
              
              //ipD = n;
              
              client.println("
");
              
              client.println(ipD);
              
              Serial.println(ipD);

```

Thanks for your expertise..

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [March 4, 2011, 7:10pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/2 "2011-03-04T19:10:31Z")

</div>

please modify your post, select the code and press the # button so ot is wrapped in [code] and [/code] tags.

recipe:

1. at boottime read the IP address and other config from EEPROM. (you need to set it once)
2. If website provides new IP address store it in EEPROM
3. reboot (yes that's another question)

The trick is you need to stop the whole ethernet and restart it over. The above recipe is quite rough but it will work.

you can do it much cleaner but that means that you have to be able to stop and restart your ethernet object from code. Means encapsulating the initialization in functions instead of at boottime.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 7, 2011, 4:34pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/3 "2011-03-07T16:34:36Z")

</div>

That was in line with my thinking, which of course I have no idea how to accomplish as of yet.

1. Not sure how to do this?
2. Not sure how to do this either?
3. Moved Ethernet Shield reset pin, wired digital pin 9 to reset pin in order to call a reset.

```cpp
int resetPin = 9; //wire digital pin 9 to ethernet shield reset pin

digitalWrite(resetPin,LOW); // put reset pin to low which resets the ethernet shield
delay(10000);
digitalWrite(resetPin,HIGH); // set it back to high which turns it back on
delay(2000); 

Ethernet.begin(mac, ip, gateway, subnet); //must re-init ethernet after reset

```

If anyone has a potential solution or example to EEPROM.write() over the static byte IP[] array values, please share your thoughts...

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [March 7, 2011, 4:58pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/4 "2011-03-07T16:58:39Z")

</div>

something like this

```cpp
int eeaddress = 0;

for(int i=0; i< 4; i++) EEPROM.write(eeaddress + i, IP[i]);

for(int i=0; i< 4; i++) IP[i] = EEPROM.read(eeaddress + i);

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 8, 2011, 3:47pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/5 "2011-03-08T15:47:31Z")

</div>

This is now partially working. It currently only sets the 4th ip octet. Also, upon board reset the ip goes back to default, maybe good as a failsafe if your on a UPS anyway. I wanted to make sure it would work before writing the remaining html code. As, or if, I make progress I will post updates here. Anyone with a better way, I'm sure there are many, please feel free to add comments.

```cpp
//MKM - place under includes at top of cpp file
//MKM - for html substring processing

#define maxLengthWEB 100
String inString = String(maxLengthWEB);

```

```cpp
//MKM - this goes under char c = client.read();

if (inString.length() < maxLengthWEB) {
     inString.concat(c);
}

```

```cpp
int ipD_READ = EEPROM.read( ip[3] );;

//mkm - call mkmethernetreset() in setup and also in html section
void mkmethernetreset()
{

  pinMode(resetPin,OUTPUT);
  
  digitalWrite(resetPin,LOW); // reset the ethernet shield
  delay(200);
  
   byte ip[] = { ipA, ipB, ipC, ipD };  
   
  //50 is the default IP address, therefore if it is not 50 it has been changed
  if ( ip[3] != 50 ) {
   EEPROM.write( ip[3], ipD ); 
  }

  ipD_READ = EEPROM.read( ip[3]  );
              Serial.println("BEGIN - just after ethernet reset "); //debug
              Serial.println(ipD_READ);
              Serial.println("END - just after ethernet reset ");
   
  digitalWrite(resetPin,HIGH); // set it back to high
  delay(2000); 
  
  Ethernet.begin(mac, ip, gateway, subnet);  

              Serial.println("BEGIN - just after ethernet  re-init "); //debug
              Serial.println(ipD_READ);
              Serial.println("END - just after ethernet re-init ");
   
}

```

```cpp
//mkm - here is the html form

          client << F("
") << endl;
          client << F("
") << endl;                
          client << F("Change IP Address:") << endl; 
            client << F("<form name=\"changeipaddress\" action=\"\" method=\"get\">") << endl;
             client << F("<TABLE>") << endl; 
		client << F("<td>IP Address:</td> ");
			client << F("<td style=\"padding-left:10;\"><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip1\" value=\"\"></td>  ");
			client << F("<td><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip2\" value=\"\"></td>  ");
			client << F("<td><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip3\" value=\"\"></td>  ");
			client << F("<td><input type=\"text\" size=\"4\" maxlength=\"3\" name=\"ip4\" value=\"\"></td>  ");
			client << F("<td colspan=3></td>  ");
		client << F("</tr>  ");               
              client << F("<tr><td colspan=\"8\"><input type=\"submit\" value=\"Update\"></td></tr>   ");
             client << F("</TABLE>") << endl; 
            client << F("</form>") << endl;
   
       client.println("
");
 
        //String stringTEST = "?ip1=172&ip2=31&ip3=1&ip4=50"; //MKM - placed here for debug
       String stringTEST = stringOne;

        int firstequal = stringTEST.indexOf('=');
        int secondequal = stringTEST.indexOf('=', firstequal + 1);
        int thirdequal = stringTEST.indexOf('=', secondequal + 1);
        int fourthequal = stringTEST.indexOf('=', thirdequal + 1);
        
        int firstand = stringTEST.indexOf('&');
        int secondand = stringTEST.indexOf('&', firstand + 1);
        int thirdand = stringTEST.indexOf('&', secondand + 1);
        int fourthand = stringTEST.indexOf('H');      
              
              client.println("
");
              client.println("IP Address Currently Set To:");  
              client.println("
");
          
          if (stringOne.substring(6,14) == "HIGHTEMP") {
           //client.print("Ignore Temperature String in IP Form"); //for diag ignore temperature set string
          }
          else if (firstequal == -1) {
            //client.print("IP Address Not Entered Correctly");   //for diag, later ip address will need some validation, ie !> 255, etc         
          }
              else {
            
              client.print(stringTEST.substring(firstequal + 1,firstand)); 
                       client.println(".");         
              client.print(stringTEST.substring(secondequal + 1,secondand)); 
                         client.println(".");                 
              client.print(stringTEST.substring(thirdequal + 1,thirdand)); 
                         client.println(".");                      
              client.println(stringTEST.substring(fourthequal + 1, fourthand - 1));             
              
              client.println("
");
              client.println("
");             

              String ipD_string =  String(  stringTEST.substring(fourthequal +1, fourthand -1)            ); 
 
              int n4_IP;
              char carray[6];
              ipD_string.toCharArray(carray, sizeof(carray));
              n4_IP = atoi(carray);
              
              client.println("
");
              
              client.println(n4_IP);

              client.println("
");
              
              client.println(ipD); //debug
              
              Serial.println(ipD); //debug
              
              client.println("
"); //debug

            
         ipD=n4_IP;
            
            
         mkmethernetreset(); //after changing ipD octet 4 reset the shield
            
              //delay(500);

              Serial.println();

          }

```

Thanks for sharing thoughts, suggestions, and code examples..

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 8, 2011, 3:58pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/6 "2011-03-08T15:58:40Z")

</div>

If you need a reset, you could use the watchdog, or do a pseudo-reset by a call to the reset vector.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 11, 2011, 9:38pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/7 "2011-03-11T21:38:27Z")

</div>

Here is an updated working web form that sets IP, Subnet, Gateway, eventually mac if I do not run out of SRAM first. This is not optimal by any means, but it works for on the fly (web based) changes to the network settings.

I do have one more thing to figure out, seeking forums help with, which is saving the IP address that is set to EEPROM and reading the _new_ IP address after rebooting the controller.

```cpp
          //mkm - print the current network settings
                   client << F("
") << "\n"; 
          client << F("<B>Current Network Settings:</B>") << "\n";
                   client << F("
") << "\n";
                   client << F("
") << "\n"; 
          client << ipA << (".") << ipB << (".") << ipC << (".") << ipD << "\n";
                   client << F("
") << "\n";
          client << subnetA << (".") << subnetB << (".") << subnetC << (".") << subnetD << "\n";  
                   client << F("
") << "\n";       
          client << gwA << (".") << gwB << (".") << gwC << (".") << gwD << "\n";          
          

 
          client << F("
") << "\n";
          client << F("
") << "\n";                
          client << F("<B>Change IP Address:</B>") << "\n"; 
            client << F("<form name=\"changeipaddress\" action=\"\" method=\"get\">") << "\n";
             client << F("<TABLE>") << "\n"; 

		client << F("<tr>") << "\n"; 
		client << F("<td>IP Address:</td> ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i1\" value=\"172\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i2\" value=\"31\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i3\" value=\"1\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i4\" value=\"50\"></td>  ") << "\n";
		client << F("</tr>  ") << "\n";               

		client << F("<tr>") << "\n";  
		client << F("<td>Subnet Mask:</td> ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s1\" value=\"255\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s2\" value=\"255\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s3\" value=\"255\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s4\" value=\"0\"></td>  ") << "\n";
		client << F("</tr>  ") << "\n";
 
		client << F("<tr>") << "\n"; 		
		client << F("<td>Gateway:</td> ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g1\" value=\"172\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g2\" value=\"31\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g3\" value=\"1\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g4\" value=\"1\"></td>  ") << "\n";
			client << F("<td><input type=\"hidden\" size=\"3\" maxlength=\"3\" name=\"END\" value=\"END\"></td>  ") << "\n"; //insert hidden form element for final "&" character in string
		client << F("</tr>  ") << "\n";
/*
		client << F("<tr>") << "\n"; 
		client << F("<td>Mac Address:</td> ") << "\n"; //will deal with mac address next
			client << F("<td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"m1\" value=\"\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"m2\" value=\"\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"m3\" value=\"\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"m4\" value=\"\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"m5\" value=\"\"></td>  ") << "\n";
			client << F("<td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"m6\" value=\"\"></td>  ") << "\n";
		client << F("</tr>  ") << "\n";
*/
             
              client << F("<tr><td align=\"center\"><input type=\"submit\" value=\"Update Network Configuration\"></td></tr>   ") << "\n";
              client << F("<tr><td align=\"center\">*After changing IP address change address url in browser</td></tr>   ") << "\n";
             client << F("</TABLE>") << "\n"; 
            client << F("</form>") << "\n";
   
        client << F("
") << "\n";
        
        //stringOne = "?ip1=172&ip2=31&ip3=1&ip4=57&"; //mkm - debug manual set string

        int firstequal = stringOne.indexOf('=');
        int secondequal = stringOne.indexOf('=', firstequal + 1);
        int thirdequal = stringOne.indexOf('=', secondequal + 1);
        int fourthequal = stringOne.indexOf('=', thirdequal + 1);
        
        int fifthequal = stringOne.indexOf('=', fourthequal + 1);
        int sixthequal = stringOne.indexOf('=', fifthequal + 1);
        int seventhequal = stringOne.indexOf('=', sixthequal + 1);
        int eighthequal = stringOne.indexOf('=', seventhequal + 1);        
        
        int ninthequal = stringOne.indexOf('=', eighthequal + 1);
        int tenthequal = stringOne.indexOf('=', ninthequal + 1);
        int eleventhequal = stringOne.indexOf('=', tenthequal + 1);
        int twelvthequal = stringOne.indexOf('=', eleventhequal + 1);        
                     
        int firstand = stringOne.indexOf('&');
        int secondand = stringOne.indexOf('&', firstand + 1);
        int thirdand = stringOne.indexOf('&', secondand + 1);
        int fourthand = stringOne.indexOf('&', thirdand + 1);    
      
        int fifthand = stringOne.indexOf('&', fourthand + 1);
        int sixthand = stringOne.indexOf('&', fifthand + 1);
        int seventhand = stringOne.indexOf('&', sixthand + 1);
        int eighthand = stringOne.indexOf('&', seventhand + 1); 
  
        int ninthand = stringOne.indexOf('&', eighthand + 1);
        int tenthand = stringOne.indexOf('&', ninthand + 1);
        int eleventhand = stringOne.indexOf('&', tenthand + 1);
        int twelvthand = stringOne.indexOf('&', eleventhand + 1);

```

and see next post ...

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 11, 2011, 9:39pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/8 "2011-03-11T21:39:33Z")

</div>

post was too large, so add this to the last one:

```cpp
          if (stringOne.substring(6,14) == "HIGHTEMP") {
            //client.print("Ignore Temperature String in IP Form"); //for debug ignore temperature set string (another form on this page)
          }
          else if (firstequal == -1) {
            //client << F("New IP Address Not Set, Using Defaults") << "\n"; //for debug, later ip address will need some validation, ie !> 255, etc         
          }
          else if (firstequal > -1) {
            //mkm - if firstequal is great than 1 then an ip address was set?
                       
      ////////////////////////////////////////////////////////////////////////////////
      ////////////////////////////////////////////////////////////////////////////////       

        client << F("
") << "\n";           

              String ipA_string = String(  stringOne.substring(firstequal + 1, firstand)  );
              String ipB_string = String(  stringOne.substring(secondequal + 1, secondand)  );
              String ipC_string = String(  stringOne.substring(thirdequal + 1, thirdand)  );
              String ipD_string = String(  stringOne.substring(fourthequal + 1, fourthand)  ); 

              int nA_IP;
              char Aarray[4]; //tested with 1 through 3
              ipA_string.toCharArray(Aarray, sizeof(Aarray));
              nA_IP = atoi(Aarray);
              
              int nB_IP;
              char Barray[4];
              ipB_string.toCharArray(Barray, sizeof(Barray));
              nB_IP = atoi(Barray);   
   
              int nC_IP;
              char Carray[4];
              ipC_string.toCharArray(Carray, sizeof(Carray));
              nC_IP = atoi(Carray);              
 
              int nD_IP;
              char Darray[4];
              ipD_string.toCharArray(Darray, sizeof(Darray));
              nD_IP = atoi(Darray);
                                                          
        client << F("
") << "\n";
         
        ipA=nA_IP;         
        ipB=nB_IP;         
        ipC=nC_IP;            
        ipD=nD_IP;

      ////////////////////////////////////////////////////////////////////////////////                    
      ////////////////////////////////////////////////////////////////////////////////      

        client << F("
") << "\n";   

              String subnetA_string = String(  stringOne.substring(fifthequal + 1, fifthand)  );
              String subnetB_string = String(  stringOne.substring(sixthequal + 1, sixthand)  );
              String subnetC_string = String(  stringOne.substring(seventhequal + 1, seventhand)  );
              String subnetD_string = String(  stringOne.substring(eighthequal + 1, eighthand)  ); 
              
              int nA_SUBNET;
              char SUBNETAarray[4]; //tested with 1 through 3
              subnetA_string.toCharArray(SUBNETAarray, sizeof(SUBNETAarray));
              nA_SUBNET = atoi(SUBNETAarray);
              
              int nB_SUBNET;
              char SUBNETBarray[4];
              subnetB_string.toCharArray(SUBNETBarray, sizeof(SUBNETBarray));
              nB_SUBNET = atoi(SUBNETBarray);   
   
              int nC_SUBNET;
              char SUBNETCarray[4];
              ipC_string.toCharArray(SUBNETCarray, sizeof(SUBNETCarray));
              nC_IP = atoi(Carray);              
 
              int nD_SUBNET;
              char SUBNETDarray[4];
              subnetD_string.toCharArray(SUBNETDarray, sizeof(SUBNETDarray));
              nD_SUBNET = atoi(SUBNETDarray);
                                                          
        client << F("
") << "\n";
         
        subnetA=nA_SUBNET;         
        subnetB=nB_SUBNET;         
        subnetC=nC_SUBNET;            
        subnetD=nD_SUBNET;
   
      ////////////////////////////////////////////////////////////////////////////////          
      ////////////////////////////////////////////////////////////////////////////////      

        client << F("
") << "\n";           

              String gwA_string = String(  stringOne.substring(ninthequal + 1, ninthand)  );
              String gwB_string = String(  stringOne.substring(tenthequal + 1, tenthand)  );
              String gwC_string = String(  stringOne.substring(eleventhequal + 1, eleventhand)  );
              String gwD_string = String(  stringOne.substring(twelvthequal + 1, twelvthand)  ); //last line requires special ending
            //String gwD_string = String(  stringOne.substring(twelvthand )  );

              int nA_GATEWAY;
              char GATEWAYAarray[4]; //tested with 1 through 3
              gwA_string.toCharArray(GATEWAYAarray, sizeof(GATEWAYAarray));
              nA_GATEWAY = atoi(GATEWAYAarray);
              
              int nB_GATEWAY;
              char GATEWAYBarray[4];
              gwB_string.toCharArray(GATEWAYBarray, sizeof(GATEWAYBarray));
              nB_GATEWAY = atoi(GATEWAYBarray);   
   
              int nC_GATEWAY;
              char GATEWAYCarray[4];
              gwC_string.toCharArray(GATEWAYCarray, sizeof(GATEWAYCarray));
              nC_IP = atoi(Carray);              
 
              int nD_GATEWAY;
              char GATEWAYDarray[4];
              gwD_string.toCharArray(GATEWAYDarray, sizeof(GATEWAYDarray));
              nD_GATEWAY = atoi(GATEWAYDarray);
                                                          
        client << F("
") << "\n";
         
        gwA=nA_GATEWAY;         
        gwB=nB_GATEWAY;         
        gwC=nC_GATEWAY;            
        gwD=nD_GATEWAY;
   
      ////////////////////////////////////////////////////////////////////////////////    
      ////////////////////////////////////////////////////////////////////////////////    
           
        mkmethernetreset(); //after changing ip address reset the shield
            
          }

```

If anyone has any ideas on reading the new IP from EERPOM on controller bootup your help is most welcome..

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 11, 2011, 9:43pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/9 "2011-03-11T21:43:47Z")

</div>

And here are the initial network definitions to permanently overwrite through the web form:

```cpp
//need a default starting IP
//but need to overwrite these if if a new value is set through the web form
uint32_t ipA=172;
uint32_t ipB=31;
uint32_t ipC=1;
uint32_t ipD=50;

//need a default starting SUBNET
uint32_t subnetA=255;
uint32_t subnetB=255;
uint32_t subnetC=255;
uint32_t subnetD=0;

//need a default starting GATEWAY
uint32_t gwA=172;
uint32_t gwB=31;
uint32_t gwC=1;
uint32_t gwD=1;

//MKM BEGIN - ETHERNET PARAMETERS
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { ipA, ipB, ipC, ipD };
byte subnet[] = { subnetA, subnetB, subnetC, subnetD };
byte gateway[] = { gwA, gwB, gwC, gwD };
//MKM END - ETHERNET PARAMETERS

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 11, 2011, 9:48pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/10 "2011-03-11T21:48:57Z")

</div>

Tried doing someting like this, but I do not think it does anything at this point?

```cpp
int ipA_READ = EEPROM.read( ip[0] );
int ipB_READ = EEPROM.read( ip[1] );
int ipC_READ = EEPROM.read( ip[2] );
int ipD_READ = EEPROM.read( ip[3] );

int subnetA_READ = EEPROM.read( subnet[0] );
int subnetB_READ = EEPROM.read( subnet[1] );
int subnetC_READ = EEPROM.read( subnet[2] );
int subnetD_READ = EEPROM.read( subnet[3] );

int gwA_READ = EEPROM.read( gateway[0] );
int gwB_READ = EEPROM.read( gateway[1] );
int gwC_READ = EEPROM.read( gateway[2] );
int gwD_READ = EEPROM.read( gateway[3] );

  //if default IP address is not set then overwrite???
  // would need to be if LAST IP address set is different

  if ( ip[0] != 172 ) {
       EEPROM.write( ip[0], ipA ); 
  }
  if ( ip[1] != 31 ) {
       EEPROM.write( ip[1], ipB ); 
  }
  if ( ip[2] != 1 ) {
       EEPROM.write( ip[2], ipC ); 
  }    
  if ( ip[3] != 50 ) {
       EEPROM.write( ip[3], ipD ); 
  }
  
  if ( subnet[0] != 255 ) {
       EEPROM.write( subnet[0], subnetA ); 
  }
  if ( subnet[1] != 255 ) {
       EEPROM.write( subnet[1], subnetB ); 
  }
  if ( subnet[2] != 255 ) {
       EEPROM.write( subnet[2], subnetC ); 
  }    
  if ( subnet[3] != 0 ) {
       EEPROM.write( subnet[3], subnetD ); 
  }
  
  if ( gateway[0] != 172 ) {
       EEPROM.write( gateway[0], gwA ); 
  }
  if ( gateway[1] != 31 ) {
       EEPROM.write( gateway[1], gwB ); 
  }
  if ( gateway[2] != 1 ) {
       EEPROM.write( gateway[2], gwC ); 
  }    
  if ( gateway[3] != 1 ) {
       EEPROM.write( gateway[3], gwD ); 
  }

```

To be continued and ideas most welcome...

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 11, 2011, 11:53pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/11 "2011-03-11T23:53:24Z")

</div>

Snapshot of Network Settings Web Form

![Snapshot - Form IP Changer.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/0/5/b/05bc0aead1f99e2e2c4c9c733a970dbe75d61ab3.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2011, 4:46am UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/12 "2011-03-12T04:46:51Z")

</div>

For anyone following this, I managed to complete the form and it is fully operable now, setting IP/Subnet/Gateway from a web from, storing it to EEPROM.

The EEPROM, I was struggling with b/c it has to be placed precisely in specific areas in order to overwrite the existing values

Here is an example of setting the IP address, I will post the entire form code later with the hopes that someone (an expert, maybe Arduino) will improve upon it.

Example reading/writing eeprom:

```cpp
 int ipA_READ = EEPROM.read( ip[0] );
  int ipB_READ = EEPROM.read( ip[1] );
  int ipC_READ = EEPROM.read( ip[2] );
  int ipD_READ = EEPROM.read( ip[3] );
 
        ipA=nA_IP; 
          EEPROM.write( ip[0], ipA );        
        ipB=nB_IP;  
          EEPROM.write( ip[1], ipB );       
        ipC=nC_IP;
          EEPROM.write( ip[2], ipC );         
        ipD=nD_IP;
          EEPROM.write( ip[3], ipD );

```

---

<div class="post-metadata">

**Author:** ![JO3RI](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@JO3RI](https://forum.arduino.cc/u/JO3RI)\
**Post date:** [March 21, 2011, 1:13pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/13 "2011-03-21T13:13:28Z")

</div>

Hi, I'm very interested in the complete code of this sketch. As you can see in my own post, I'm working on this too:  
[http://arduino.cc/forum/index.php/topic,55044.0.html](http://arduino.cc/forum/index.php/topic,55044.0.html)

Now maybe we can merge both our sketch. You'll get credit for the code and I'll get credit for the layout 😃  
The only thing I'm struggling with, is the forms and the way to submit them.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 22, 2011, 2:35am UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/14 "2011-03-22T02:35:06Z")

</div>

As promised, attached is the pde. I have tested this against an UNO and a DFRduino ATMega328 (Duemilanove) . If anyone improves upon this keep me posted..

 ![Capture - Network Settings Web Control Form.JPG](https://europe1.discourse-cdn.com/arduino/original/1X/cc06871b41c0eea3750f8702e6d3a735e481775e.jpg)

[Network\_Settings\_Web\_Control\_Form.pde](https://forum.arduino.cc/uploads/short-url/nb6Cy9OEtrDAfYXe929RR9opgQU.pde) (21 KB)

---

<div class="post-metadata">

**Author:** ![JO3RI](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@JO3RI](https://forum.arduino.cc/u/JO3RI)\
**Post date:** [March 22, 2011, 11:34am UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/15 "2011-03-22T11:34:29Z")

</div>

Ok, got your code, reading it right now. 😲

Did you change Ethernet.cpp to get this working? And what exactly did you change?

The first thing I'll be doing is to try remaking you sketch, so I understand everything happening. Then I'll put all your HTML in Flash memory, so we have more SRAM. Also I want to have a separate SETUP page, which won't be to hard, because I bought the Arduino Cookbook (amazone kindle for ipad). It has a sketch that just does that.

This way you can have the SETUP page at [http://IP-address/setup](http://IP-address/setup) and your normal webpage at [http://IP-address](http://IP-address).

If you don't mind, I'll be posting this in my own Topic and If I make progress I'll post it here too.

So this is the idea I would use (this is not a sketch):

READ EEPROM "TYPE"  
IF "type" = "" (empty)  
THEN USE PRESET (IP=192.168.1.2, MASK=255.255.255.0,GW=192.168.1.2,MAC=DE:AD:BE:EF:FE:ED)  
ELSE  
IF "type" = "STATIC"  
IF "IP" = "" (empty)  
USE PRESET AND SET TO USE AND PUBLISH  
ELSE READ EEPROM "IP" AND SET TO USE AND PUBLISH

IF "MASK" ="" (empty)  
THEN USE PRESET AND SET TO USE AND PUBLISH  
ELSE READ EEPROM "MASK" AND SET TO USE AND PUBLISH

IF "GW" = "" (empty)  
THEN USE PRESET AND SET TO USE AND PUBLISH  
ELSE READ EEPROM "GW" AND SET TO USE AND PUBLISH

IF "MAC" = ""(empty)  
THEN USE PRESET AND SET TO USE AND PUBLISH  
ELSE READ EEPROM "MAC" AND SET TO USE AND PUBLISH

ELSE USE DHCP AND SET TO USE AND PUBLISH (on the setuppage)

START WEBPAGE  
IF URL= IP  
GOTO WEBPAGE (made by user, and what if user wants multiple pages?)  
ELSE  
IF URL = IP/setup (like in [http://192.168.1.2/setup](http://192.168.1.2/setup))  
GOTO SETUPPAGE  
ELSE SHOW ERROR PAGE

SETUPPAGE  
USE TYPE, IP, MASK, GW, MAC AND PUBLISH  
SHOW FILLOUT FORM FOR TYPE, IP, MASK, GW, MAC AND PUBLISH  
SHOW SUBMIT BUTTON

WEBPAGE  
USE TYPE, IP, MASK, GW, MAC  
SHOW WEBPAGE (made by user)

SUBMIT BUTTON  
WRITE TYPE, IP, MASK, GW, MAC AND PUBLISH TO EEPROM  
RESET ARDUINO

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 22, 2011, 3:31pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/16 "2011-03-22T15:31:10Z")

</div>

I had to change the Ethernet.cpp file b/c I noticed gateway was being set as IP then changing last octet only and subnet was statically set here as well.

Before:  
//uint8\_t gateway[4];  
//gateway[0] = ip[0];  
//gateway[1] = ip[1];  
//gateway[2] = ip[2];  
//gateway[3] = 1;

//uint8\_t subnet[] = {  
//255, 255, 255, 0 };

After:

```cpp
#include "w5100.h"
#include "Ethernet.h"

uint8_t EthernetClass::_state[MAX_SOCK_NUM] = {
  0, 0, 0, 0 };
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 
  0, 0, 0, 0 };

void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway)
{
  begin(mac, ip, gateway);
}

void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway, uint8_t *subnet)
{
  W5100.init();
  W5100.setMACAddress(mac);
  W5100.setIPAddress(ip);
  W5100.setGatewayIp(gateway);
  W5100.setSubnetMask(subnet);
}

EthernetClass Ethernet;

```

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [March 22, 2011, 6:48pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/17 "2011-03-22T18:48:01Z")

</div>

@Jo3ri,  
Fun an Arduino "basic" sketch 🙂

---

<div class="post-metadata">

**Author:** ![JO3RI](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@JO3RI](https://forum.arduino.cc/u/JO3RI)\
**Post date:** [March 23, 2011, 7:58am UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/18 "2011-03-23T07:58:59Z")

</div>

@robtillaart

I know 🙂 But it really helps to write down this kinds of things. Otherwise I get lost in my own coding :~

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 23, 2011, 6:04pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/19 "2011-03-23T18:04:51Z")

</div>

Update: 1st through 3rd IP octet is not saving correctly. Working on a fix.

---

<div class="post-metadata">

**Author:** ![JO3RI](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@JO3RI](https://forum.arduino.cc/u/JO3RI)\
**Post date:** [March 23, 2011, 8:02pm UTC](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392/20 "2011-03-23T20:02:34Z")

</div>

Meanwhile I found out your working on a different Arduino version (mine is 0.22) also I have the new Arduino Ethernet Shield. But the Idea remains the same.

FYI: I thanks to your sketch, I managed to use EEPROM for storing mac, ip, gw, sub and type (static, dhcp or unknown) and showing this info in the webpage.

The sketch starts with setting the pre-sets the first time and writes a knowing bit. The next time it runs, the sketch doesn't use pre-sets, but reads EEPROM: when type is stored as static, it takes static otherwise it takes dhcp.

Now I need to work on the GET forms in html. I haven't found out how to do that yet, but I'll get there.

[Next page](https://forum.arduino.cc/t/set-change-ip-address-web-form-ethernet-shield/54392.md?page=2)
