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:
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();
}