2 questions about webserver program code (ethernet shield)

Hi guys,

On the interface of the program below I have three buttons, with each one I send a signal of 500ms from ports 5,6 and 7 respectivelly. When I click on these buttons, the address change from:

http://192.168.1.177

to:

http://192.168.1.177?x or http://192.168.1.177?y or http://192.168.1.177?y

However I want that the address returns to the original form to stop the arduino to continue to send these signals all time. What I need to change?


I'm facing a really crazy bug on my arduino and I hope you know why...

I want to manipulate the webpage with conditions like:

if(variable == 0){ client.println("XXX");}

else if (variable == 1) { client.println("YYY");}

This is working very well until this variable (on the condition) is an attributed integer that receives the value from "EEPROM.read(any number)". After this change, the arduino doesn't send any signal through the ports when I click the button exposed on webpage.

In other words, when I manipulate any variable that receives a value from EEPROM to change the HTML code, the program exhibited on webpage apparently works fine, but the arduino signal ports itself doesn't.


I'm posting below the code resumed to be clear to see:

#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>

boolean incoming = 0;


int order1 = 5;
int order2 = 6;
int order3 = 7;

int value  = 0;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);


void setup()
      {
      Ethernet.begin(mac, ip);
      server.begin();
      Serial.begin(9600);
      pinMode(5, OUTPUT);
      digitalWrite(5, LOW);
      pinMode(6, OUTPUT);
      digitalWrite(6, LOW);
      pinMode(7, OUTPUT);
      digitalWrite(7, LOW);
      }
void loop()
{
        // listen for incoming clients
        EthernetClient client = server.available();
        if (client) {
              // an http request ends with a blank line
              boolean currentLineIsBlank = true;
              String str;
             
              while (client.connected()) {
                      
                      if (client.available()) {
                      
                            char c = client.read();
                            str.concat(c);
                            value = EEPROM.read(0);

                           //1 QUESTION: HOW TO STOP THE ARDUINO TO CONTINUALLY SEND THESE SIGNALS
                            
                            if(str.endsWith("?x")){ 
                                       digitalWrite(order1,HIGH);
                                       delay(500);
                                       digitalWrite(order1, LOW);                                        
                                       }
                            
                            if(str.endsWith("?y")){
                                       digitalWrite(order2,HIGH);
                                       delay(500);
                                       digitalWrite(order2, LOW);                                        
                                       }
                            
                            if(str.endsWith("?z")){
                                       digitalWrite(order1,HIGH);
                                       delay(500);
                                       digitalWrite(order1, LOW);                                        
                                       }
                                       
                            if (c == '\n' && currentLineIsBlank) {
                                  
                                 client.println("HTTP/1.1 200 OK"); //send new page
                                 client.println("Content-Type: text/html");
                                 client.println();     
                                 client.println("<HTML>");
                                       client.println("<HEAD>");
                                             client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
                                             client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");                                             client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
                                            
                                       client.println("</HEAD>");
                                       client.println("<BODY>");
                                             client.println("<H1>Control</H1>");
                                             client.println("<hr />");
                                             client.println("
");  
                                             
                                             //THE BUTTONS:
                                             
                                             client.println("<a href=\"/?x\"\">button 1</a>");
                                             client.println("<a href=\"/?y\"\">button 2</a>
");   
                                             client.println("
"); 
                                             client.println("<a href=\"/?z\"\">button 3</a>"); 
                                             client.println("
"); 
                                       
                                             //2 QUESTION: THE CONDITION THAT NEUTRALIZE THE ARDUINO PORTS 
                                             
                                             //if(value == 0) client.println("the value is 0"); 
                                             
                                       client.println("</BODY>");
                                 client.println("</HTML>");

                                  
                                  break;
                                  }
                            if (c == '\n') {
                                  currentLineIsBlank = true;
                                  } 
                            
                            else if (c != '\r') {
                                  currentLineIsBlank = false;
                                  }
                      }
              }
              // give the web browser time to receive the data
              delay(1);
              // close the connection:
              client.stop();
        }

Modus:
Hi guys,
the address change from:

http://192.168.1.220

to:

http://192.168.1.220?x or http://192.168.1.220?y or http://192.168.1.220?y

However I want that the address returns to the original form to stop the arduino to continue to send these signals all time. What I need to change?

From the code you posted below your webserver is using a different ip address:

IPAddress ip(192,168,1, 177);

I'd either change the posting you made to start this thread and tell something about the webserver at
http://192.168.1.220

Or maybe change the webserver sketch so that the Arduino webserver is really running at that ip address which you enter in your webbrowser.

jurs, thank you and the problem is not this one...I'll edit my post.

Anyone? :frowning:

Modus:
Anyone? :frowning:

You have not provided near enough details to solve the second problem. The first one is a simple re-direct issue and is NOT specific to the Arduino as server. Before you try to make the Arduino a server, you should have set up a PC as a server, and another one on the same LAN as the client, and worked out all the communications issues.

As for the second problem, you've done nothing but a bunch of handwaving and complaining. There is nothing in the code that you posted that reads from EEPROM. There is nothing that shows that there IS a problem - no serial output, nothing that illustrates what the client sees, nothing that indicates what the client sends back to the server.

Modus:
Anyone? :frowning:

So these seem to be your questions (they seem to be HTML questions and NOT Arduino related):

However I want that the address returns to the original form

So you want to send GET requests like that to your webserver
http://192.168.2.177/?x
http://192.168.2.177/?y
http://192.168.2.177/?z
but different from the normal webserver standards you then want the request to redirect the browser to
http://192.168.2.177/
right?
This can be done with a META-refresh of zero seconds duration to the original webserver address.

Do you know how to include a META-refresh in your HTML?