Hello all,
Been an Arduino owner for about a week now, learning a lot, but a little stuck on a few things. I waa hoping someone would give a hand.
Having an issue getting the Ethernet shield to reach a outside server, for example trying to post a variable to a server that I have that is NOT on the local network.
I have tried many examples found on the net, a few from here and it just does not connect. I have placed the IP of the Arduino in the DMZ, I have set subnet and DNS. I am not new to networking so I am a bit stumpped as this should be working.
((I do have it set to get obtain an IP automatically, and that works as it prints to serial as well as to a 16x2 LCD I have hooked up.))
and my second issue is how to get the string from a text box. For example I have a working login form, I want to be able to put the email in a form and click submit, it should then store the email address in a variable. Nothing I have tried has worked and I am thinking maybe I am missing something about the way Arduino and html work.
Any hints or ideas? also if anyone know a GOOD tutorial on the way post and get work inside arduino HTML I would be grateful as I have seen many examples, and I think I understand how it works, but more information would be great.
Red1:
and my second issue is how to get the string from a text box. For example I have a working login form, I want to be able to put the email in a form and click submit, it should then store the email address in a variable. Nothing I have tried has worked and I am thinking maybe I am missing something about the way Arduino and html work.
Is your Arduino operating as a client to another web server, or will the Arduino be the web server responding to external client requests? I have some familiarity with the latter.
I think for both you need to research HTML GET and POST request headers - you need to know the low level multi line conversation that takes place between web servers and browsers and then emulate or respond to that within your Arduino code.
If you are operating as a web server you will also need to know how to generate the (high level) HTML to be displayed as web pages by the client. If you are operating as a (browser) client you may have to learn how to parse the (high level) HTML content received from your external server and how to extract the information needed by the Arduino application.
So are you stuck at the low level or the high level?
//zoomkat 12-08-12
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84);; //server port
String readString;
//////////////////////
void setup(){
pinMode(5, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("server text box test1"); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //see what was captured
//now output HTML data header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Arduino GET test page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>HTML form GET example</H1>");
client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page
client.println("Pin 5 'on' or 'off': <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>
");
client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Change Pin 5!'>");
client.println("</FORM>");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
/////////////////////
if(readString.indexOf("on") >0)//checks for on
{
digitalWrite(5, HIGH); // set pin 5 high
Serial.println("Led On");
}
if(readString.indexOf("off") >0)//checks for off
{
digitalWrite(5, LOW); // set pin 5 low
Serial.println("Led Off");
}
//clearing string for next read
readString="";
}
}
}
}
}