Dear all.
I am looking for simple example Code where i can edit value on webserver . I found examples for blinking led. reading analog value. But i didnt find any example program Where i can assign value to variable and get changed when put it into update. If any one has implimented code requested to share example code,
I don't understand your question. Is the Arduino acting as a server, and some client needs to change a value on the server? Or, is the Arduino a client trying to change a value on a server?
By now, you certainly should know how to ask questions better, and provide ALL the details AND your code. If you don't have code, it isn't a programming question.
I don't even have an ethernet shield yet I found your answer in less than two minutes. Screw google, until after you have exhausted all the standard issue sample code.
An http server returns information to a client, generally a web browser. However it requires a structured format. This page has an example of that. http://arduino.cc/en/Tutorial/BarometricPressureWebServer
Scroll down to listenForEthernetClients() There's tons more useful info there but that's the guts of it.
Suppose i want to change my slope value and intercept value.
OK. Let's suppose you do.
You have some code that is running on the Arduino. You haven't shown us that code. So, how the f**k are we supposed to help you?
This function i am calling from loop. Here i can Dispaly all value but i cant change value.
I have attached output of my code. Here i wanted to change latitude, longitude, Let me know how to impliemet using Web app
void Ethernet_Control()
{
EthernetClient client = server.available();
// detect if current is the first line
boolean current_line_is_first = true;
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println();
// auto reload webpage every 5 second
client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));
// webpage title
client.println(F("<center><p><h5>Web application V1.0</h5></p><center><hr>
"));
client.print(F("<p><h5>DATE: = <font color=indigo>"));
client.print(local_day);
client.print("/");
client.print(local_month);
client.print("/");
client.print(local_year);
client.println("</font></h5></p>");
client.print(F("<p><h5>TIME: = <font color=indigo>"));
client.print(local_h);
client.print(":");
client.print(local_m);
client.print(":");
client.print(local_s);
client.println("</font></h5></p>");
// client.print(F("<p><h5>LATITUDE: = <font color=indigo>"));
// client.print(latitude);
client.print(" <font> <color=blue> latitude: <input type=text name=01 value=");
client.println(latitude);
//client.println("</font></h5></p>");
//client.print(F("<p><h5>LONGITUDE: = <font color=indigo>"));
client.print(" <font> <color=black> Longitude: <input type=text name=01 value=");
client.println(longitude);
//client.println("</font></h5></p>");
client.print(" <font> <color=blue> Desired_Angle: <input type=text name=01 value=");
//client.print(F("<p><h5>DESIRE_ANGLE: = <font color=indigo>"));
client.println(tracker_des_angle);
// client.println("</font></h5></p>");
client.print(" <font> <color=blue> Actual_Angle: <input type=text name=01 value=");
//client.print(F("<p><h5>ACTUAL ANGLE: = <font color=indigo>"));
client.println(tracker_actual_pos);
//client.println("</font></h5></p>");
//client.print(" <font> <color=blue> Wind_Speed m/s: <input type=text name=01 value=");
client.println(F("</form>
"));
client.print(F("<p><h5>WIND_SPEED M/S: = <font color=indigo>"));
client.print(Wind_Speed);
client.println(F("</form>
"));
// client.println("</font></h5></p>");
client.print(F("<p><h5>WIND_SPEED KMPH: = <font color=BLACK>"));
//client.println(F("</form>
"));
//client.print(" <font> <color=blue> WIND in KMPH: <input type=text name=01 value=");
client.print(Wind_Kmph);
client.println(F("</form>
"));
// client.println("</font></h5></p>");
client.println("<form method=get name=form>");
client.println(F("<button name=d value=1 type=submit style=height:50px;width:80px>FORWARD</button>"));
client.println(F("<button name=d value=2 type=submit style=height:50px;width:80px>REVERSE</button>"));
client.println(F("<button name=d value=3 type=submit style=height:50px;width:80px>STOP</button>"));
client.println(F("</form>
"));
client.println("<form method=\"get\">");
ProcessCheckbox(client);
client.println("</form>");
client.println("</body>");
client.println("</html>");
//Serial.print(HTTP_req);
HTTP_req = ""; // finished with request, empty string
// button functions
/* client.println("<form method=get name=form>");
client.println("<button name=b value=1 type=submit style=height:50px;width:80px>LED On</button>");
client.println("<button name=b value=2 type=submit style=height:50px;width:80px>LED Off</button>");
client.println("</form>
");
*/
// webpage footer
client.println("<p>NOTE: This page will automatically refresh every 5 seconds.</p></center>");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_first = false;
current_line_is_blank = true;
}
else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
// get the first http request
if (current_line_is_first && c == '=') {
for (int i = 0; i < 1; i++) {
c = client.read();
command[i] = c;
}
if (!strcmp(command, "1"))
{
client.print("FWD");
digitalWrite(PWM,1);
digitalWrite(IN1,1);
digitalWrite(IN2,0);
}
if (!strcmp(command, "2"))
{
client.print("REV");
digitalWrite(PWM,1);
digitalWrite(IN1,0);//spdt
digitalWrite(IN2,1);//dpdt
}
if (!strcmp(command, "3"))
{
client.print("STOP");
digitalWrite(PWM,0);
digitalWrite(IN1,0);
digitalWrite(IN2,0);
}
// LED control
/* if (!strcmp(command, "1")) {
digitalWrite(LED, HIGH);
}
else if (!strcmp(command, "2")) {
digitalWrite(LED, LOW);
}*/
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
Here i can Dispaly all value but i cant change value
Do you have a clue what part of the code deals with the GET requests that the client makes?
Do you have a clue WHAT GET requests the client makes?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168,1, 120 };
EthernetServer server(80);
float latitude=13.08;
float longitude=80.20;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Ethernet_Control();
}
void Ethernet_Control()
{
EthernetClient client = server.available();
// detect if current is the first line
boolean current_line_is_first = true;
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && current_line_is_blank) {
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));
client.println(F("<center><p><h5>Web application V1.0</h5></p><center><hr>
"));
client.print(F("<p><h5>DATE: = <font color=indigo>"));
client.print(" <font> <color=blue> latitude: <input type=text name=01 value=");
client.println(latitude);
client.print(" <font> <color=black> Longitude: <input type=text name=01 value=");
client.println(longitude);
client.println("</form>");
client.println("</body>");
client.println("</html>");
client.println("<p>NOTE: This page will automatically refresh every 5 seconds.</p></center>");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_first = false;
current_line_is_blank = true;
}
else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
As i said . I am new bie to webserver Programming
So what? It isn't rocket science to look at the code you posted and figure out what part(s) deal with GET requests. The class names provide a pretty good clue, particularly if you know what a client does (asks for information) and what a server does (provides information).
Once you have an idea what part of the code deals with the client request, you can add a Serial.print() statement to see WHAT the client is asking for.
It wouldn't hurt to post a picture of the web page you are serving now, and explain how the user is supposed to change latitude and/or longitude.
It would also be good to look through the html you are sending, to make sure that all close tags follow the corresponding open tag (yours do not), and that all open tags have matching close tags.
Is there any link you are aware where i can use HTML tag creation.
to make sure that all close tags follow the corresponding open tag (yours do not), and that all open tags have matching close tags.
i didn't understand this.
It wouldn't hurt to post a picture of the web page you are serving now, and explain how the user is supposed to change latitude and/or longitude.
For this i would like to create tag name edit and view. In edit user can set value like example
Time Duration Calculator: Time between two dates/times adding 2 times. it takes data from user and gives result but i wanted if changes made it should refelect in Serial monitor.
if view button pressed . view changed data or current data.
Question is how to create tag of our own
Is there any link you are aware where i can use HTML tag creation.
Plenty of them. HTML Forms is one.
client.println("</form>");
This is a close tag. It goes after a tag. Where IS the tag that it is supposed to follow?
Dear paul;
Here is my code i wanna edit latitude and longitude . I would like to see changes made from latitude and longitude.The out put seem like lmage attached. Now i can enter latitude and longitude . How to assign the variable data received from server.
For example given[. HTML Forms](http://. HTML Forms) if you create username and password. How to receive data /read data entered from user.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168,1, 120 };
EthernetServer server(80);
float latitude=13.08;
float longitude=80.20;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Ethernet_Control();
}
void Ethernet_Control()
{
EthernetClient client = server.available();
// detect if current is the first line
boolean current_line_is_first = true;
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && current_line_is_blank) {
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));
client.println(F("<center><p><h5>Web application V1.0</h5></p><center><hr>
"));
client.print(F("<p><h5>DATE: = <font color=indigo>"));
client.print(" <font> <color=blue> latitude: <input type=text name=01 value=");
client.println(latitude);
client.print(" <font> <color=black> Longitude: <input type=text name=01 value=");
client.println(longitude);
client.println("</form>");
client.println("</body>");
client.println("</html>");
client.println("<p>NOTE: This page will automatically refresh every 5 seconds.</p></center>");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_first = false;
current_line_is_blank = true;
}
else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
How to assign the variable data received from server.
The first question is how to ask an intelligent question. Your Arduino is the server. It is sending data.
If you want the client to display the data, and have the data editable on the client, AND have the edited data on the client sent back to the server, that is possible.
But NOT until all of your f***ing tags match. This is STILL crap:
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));
client.println(F("
Web application V1.0
"));
client.print(F("
DATE: = "));
client.print(" <color=blue> latitude: <input type=text name=01 value=");
client.println(latitude);
client.print(" <color=black> Longitude: <input type=text name=01 value=");
client.println(longitude);
client.println("");
client.println("");
client.println("");
The highlighted end tags DO NOT HAVE MATCHING start tags.
makes no sense except on a form, which you do not have.
I have used code From Ajax . They using same HTML syntax for there code developemnt.
I don't understand why it wont work.
client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));
used instead
client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");
In arduino forum mentioned that it print single Byte.instead of whole word.
client.println("</form>");
client.println("</body>");
client.println("</html>");
How start tag and end tag should look like.If there is synatx like C , Where i can find . Link you mentioned above They also use like within
I have used code From Ajax . They using same HTML syntax for there code developemnt.
I don't understand why it wont work.
Because it is crap.
How start tag and end tag should look like.
I've told you what the end tags look like. Start tags look just like end tags, except that they don't include a /.