Hi,
I have a small web page running from an SD card web server sketch (Mega 2560 before I forget).
The form consists of fields for IP, Subnet and MAC address.
My ultimate goal here is to receive those values via POST and use them as my my parameters in Ethernet.begin when the arduino next restarts.
What I'm struggling with currently is the format the HTML form submits the values in vs the format thee values need to be in to be in my network setting arrays;
byte ip[4];
byte subnet[4];
byte mac[4];
I think the form submits the values as plain ascii text (need to research that more) and the arduino needs bytes in the arrays to begin the Ethernet from.
I found an excellent POST parsing library which I'm using to extract the key/value pairs from the POST data
The POST parsing section of my code currently looks like this;
if(strcmp(httpReq.uri, getip) == 0) {
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
// send XML file containing current network values
XML_response(client);
} else {
// send rest of HTTP header
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
webFile = SD.open("index.htm");
if (webFile) {
while(webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
}
//find a particular parameter name
int pos1=httpReq.getParam("ip1",value);
if(pos1>=1){
Serial.print("Found 'ip1'. Value: ");
Serial.println(value);
ipin[0] = value[0];
}
int pos2=httpReq.getParam("ip2",value);
if(pos2>=1){
Serial.print("Found 'ip2'. Value: ");
Serial.println(value);
ipin[1] = value[0];
}
int pos3=httpReq.getParam("ip3",value);
if(pos3>=1){
Serial.print("Found 'ip3'. Value: ");
Serial.println(value);
ipin[2] = value[0];
}
int pos4=httpReq.getParam("ip4",value);
if(pos4>=1){
Serial.print("Found 'ip4'. Value: ");
Serial.println(value);
ipin[3] = value[0];
}
int pos5=httpReq.getParam("sub1",value);
if(pos5>=1){
Serial.print("Found 'sub1'. Value: ");
Serial.println(value);
subin[0] = value[0];
}
int pos6=httpReq.getParam("sub2",value);
if(pos6>=1){
Serial.print("Found 'sub2'. Value: ");
Serial.println(value);
subin[1] = value[0];
}
int pos7=httpReq.getParam("sub3",value);
if(pos7>=1){
Serial.print("Found 'sub3'. Value: ");
Serial.println(value);
subin[2] = value[0];
}
int pos8=httpReq.getParam("sub4",value);
if(pos8>=1){
Serial.print("Found 'sub4'. Value: ");
Serial.println(value);
subin[3] = value[0];
}
int pos9=httpReq.getParam("mac1",value);
if(pos8>=1){
Serial.print("Found 'mac1'. Value: ");
Serial.println(value);
macin[0] = value[0];
}
int pos10=httpReq.getParam("mac2",value);
if(pos10>=1){
Serial.print("Found 'mac2'. Value: ");
Serial.println(value);
macin[1] = value[0];
}
int pos11=httpReq.getParam("mac3",value);
if(pos11>=1){
Serial.print("Found 'mac3'. Value: ");
Serial.println(value);
macin[2] = value[0];
}
int pos12=httpReq.getParam("mac4",value);
if(pos12>=1){
Serial.print("Found 'mac4'. Value: ");
Serial.println(value);
macin[3] = value[0];
}
int pos13=httpReq.getParam("mac5",value);
if(pos13>=1){
Serial.print("Found 'mac5'. Value: ");
Serial.println(value);
macin[4] = value[0];
}
int pos14=httpReq.getParam("mac6",value);
if(pos14>=1){
Serial.print("Found 'mac6'. Value: ");
Serial.println(value);
macin[5] = value[0];
}
Any tips so I can get headed in the right direction here?
Thanks in advance