Offline
Newbie
Karma: 0
Posts: 31
|
 |
« on: March 04, 2011, 01:45:20 pm » |
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: //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("<BR>") << endl; client << F("<BR>") << 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("<BR>");
//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("<BR>"); client.println("IP Address Currently Set To:"); client.println("<BR>"); 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("<BR>"); //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("<BR>"); 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("<BR>"); client.println(ipD); Serial.println(ipD);
Thanks for your expertise..
|
|
|
|
« Last Edit: March 05, 2011, 07:39:54 pm by techadmin »
|
Logged
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 90
Posts: 9401
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #1 on: March 04, 2011, 02:10:31 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #2 on: March 07, 2011, 11:34:36 am » |
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. 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...
|
|
|
|
« Last Edit: March 07, 2011, 11:47:59 am by techadmin »
|
Logged
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 90
Posts: 9401
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #3 on: March 07, 2011, 11:58:39 am » |
something like this 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);
|
|
|
|
« Last Edit: March 07, 2011, 12:00:32 pm by robtillaart »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #4 on: March 08, 2011, 10:47:31 am » |
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. //MKM - place under includes at top of cpp file //MKM - for html substring processing
#define maxLengthWEB 100 String inString = String(maxLengthWEB);
//MKM - this goes under char c = client.read();
if (inString.length() < maxLengthWEB) { inString.concat(c); }
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 "); }
//mkm - here is the html form
client << F("<BR>") << endl; client << F("<BR>") << 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("<BR>"); //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("<BR>"); client.println("IP Address Currently Set To:"); client.println("<BR>"); 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("<BR>"); client.println("<BR>");
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("<BR>"); client.println(n4_IP);
client.println("<BR>"); client.println(ipD); //debug Serial.println(ipD); //debug client.println("<BR>"); //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..
|
|
|
|
« Last Edit: March 11, 2011, 06:35:24 pm by techadmin »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: March 08, 2011, 10:58:40 am » |
If you need a reset, you could use the watchdog, or do a pseudo-reset by a call to the reset vector.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #6 on: March 11, 2011, 04:38:27 pm » |
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. //mkm - print the current network settings client << F("<BR>") << "\n"; client << F("<B>Current Network Settings:</B>") << "\n"; client << F("<BR>") << "\n"; client << F("<BR>") << "\n"; client << ipA << (".") << ipB << (".") << ipC << (".") << ipD << "\n"; client << F("<BR>") << "\n"; client << subnetA << (".") << subnetB << (".") << subnetC << (".") << subnetD << "\n"; client << F("<BR>") << "\n"; client << gwA << (".") << gwB << (".") << gwC << (".") << gwD << "\n";
client << F("<BR>") << "\n"; client << F("<BR>") << "\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("<BR>") << "\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 ...
|
|
|
|
« Last Edit: March 11, 2011, 04:40:07 pm by techadmin »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #7 on: March 11, 2011, 04:39:33 pm » |
post was too large, so add this to the last one: 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("<BR>") << "\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("<BR>") << "\n"; ipA=nA_IP; ipB=nB_IP; ipC=nC_IP; ipD=nD_IP;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
client << F("<BR>") << "\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("<BR>") << "\n"; subnetA=nA_SUBNET; subnetB=nB_SUBNET; subnetC=nC_SUBNET; subnetD=nD_SUBNET; //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
client << F("<BR>") << "\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("<BR>") << "\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..
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #8 on: March 11, 2011, 04:43:47 pm » |
And here are the initial network definitions to permanently overwrite through the web form: //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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #9 on: March 11, 2011, 04:48:57 pm » |
Tried doing someting like this, but I do not think it does anything at this point? 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...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #10 on: March 11, 2011, 06:53:24 pm » |
Snapshot of Network Settings Web Form
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #11 on: March 11, 2011, 11:46:51 pm » |
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: 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 );
|
|
|
|
|
Logged
|
|
|
|
|
Hamme, Belgium
Offline
Sr. Member
Karma: 3
Posts: 383
|
 |
« Reply #12 on: March 21, 2011, 08:13:28 am » |
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.htmlNow 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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #13 on: March 21, 2011, 09:35:06 pm » |
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..
|
|
|
|
|
Logged
|
|
|
|
|
Hamme, Belgium
Offline
Sr. Member
Karma: 3
Posts: 383
|
 |
« Reply #14 on: March 22, 2011, 06:34:29 am » |
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 and your normal webpage at 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) 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
|
|
|
|
« Last Edit: March 22, 2011, 08:32:45 am by JO3RI »
|
Logged
|
|
|
|
|
|