/* This an Embedded Network Setup Webpage. When you use the default ip-address in a webbrowser You'll see a simple text like: IT WORKS: go to "default-IP"/setup This default webpage can be replaced by your own if you go to "default-IP"/setup in a webbrowser You'll get a network setup page. It will pressent you the current setup filled out When you press SUBMIT, the new values will be saved to EEPROM (and thus still available on RESET). Now you'll have to RESET your Arduino your self and it will be available at your submitted IP. You will need the arduino ethernet shield and some libraries Started in 10/01/2013 last changed 10/01/2013 Version 1.1 Made by JO3RI check http://www.jo3ri.be/arduino */ #include #include #include #include #include //seting up the EthernetShield //change the defaults the match your own network byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; byte ip[] = {192,168,20,177}; byte subnet[] = {255,255,255,0}; byte gateway[] = {192,168,20,1}; byte dnsserver[] = {192,168,20,1}; EthernetServer server(80); // This is our buffer through which we will will "flow" our HTML code. // It has to be as big as the longest character chain +1 including the " char buffer[100]; // This is the HTML code all chopped up. The best way to do this is, is by typing // your HTML code in an editor, counting your characters and divide them by 8. // you can chop your HTML on every place, but not on the \" parts. So remember, // you have to use \" instead of simple " within the HTML, or it will not work. const char htmlx0[] PROGMEM = "Arduino Ethernet Setup Page
  Arduino Ethernet Setup Page

"; PGM_P const string_table0[] PROGMEM = {htmlx0, htmlx1, htmlx2, htmlx3}; const char htmla0[] PROGMEM = "
MAC:"; const char htmla2[] PROGMEM = ".....
IP: ...
MASK: ...
GW: ...

= 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]); } // set ID to the known bit, so when you reset the Arduino is will use the EEPROM values EEPROM.write(0, 0x92); // if al the data has been written to EEPROM we should reset the arduino // for now you'll have to use the hardware reset button } // 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 ); break; }} client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); // put your own html from here on client.print("IT WORKS: go to "); client.print(ip[0],DEC); for (int i= 1; i < 4; i++){ client.print("."); client.print(ip[i],DEC); } client.print("/setup"); // put your own html until here break; } } delay(1); client.stop(); } }