Hi. A query. An arduino with an ethernet module where there is a small "server" where one in the web browser puts the IP of the arduino and shows you a page. This page if you click on a button turns on the led on the arduino, and if clicking on another button turns off the led. when one presses the button, technically it makes a redirect or a GET to /? LED = T leaving 192.168.1.7/?LED=T which would make the led turn on. The same by directly placing that url in the browser, and to turn it off 192.168.1.7/?LED=F.
This gives me the possibility to create an android app that when pressing the button sends that request "192.168.1.7/?LED=T"
Now .. how can I make it from another arduino board with a module, simulate that I am pressing that button? for example, that the second arduino is sending every 5 seconds the command "192.168.1.7/?LED=T" to turn on the led, and after 5 seconds to turn it off. I do not know how to do that.
I want to do it like this and not by tcp / udp. it's possible? because it would serve me for future projects that behave like this.
#include <SPI.h>
#include <Ethernet.h>
byte mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
IPAddress ip(192,168,1,7);
EthernetServer servidor(80);
int PIN_LED=8;
String readString=String(30);
String state=String(3);
void setup() {
Ethernet.begin(mac, ip);
servidor.begin();
pinMode(PIN_LED,OUTPUT);
digitalWrite(PIN_LED,LOW);
state="OFF";
}
void loop() {
EthernetClient cliente= servidor.available();
if(cliente) {
boolean lineaenblanco=true;
while(cliente.connected()) {
if(cliente.available()) {
char c=cliente.read();
if(readString.length()<30) {
readString.concat(c);
}
if(c=='\n' && lineaenblanco)
{
int LED = readString.indexOf("LED=");
if(readString.substring(LED,LED+5)=="LED=T") {
digitalWrite(PIN_LED,HIGH);
state="ON"; }
else if (readString.substring(LED,LED+5)=="LED=F") {
digitalWrite(PIN_LED,LOW);
state="OFF";
}
//Cabecera HTTP estándar
cliente.println("HTTP/1.1 200 OK");
cliente.println("Content-Type: text/html");
cliente.println(); //Página Web en HTML
cliente.println("<html>");
cliente.println("<head>");
cliente.println("<title>LED ON/OFF</title>");
cliente.println("</head>");
cliente.println("<body width=100% height=100%>");
cliente.println("<center>");
cliente.println("<h1>LED ON/OFF</h1>");
cliente.print("
");
cliente.print("Estado del LED: ");
cliente.print(state);
cliente.print("
");
cliente.println("<input type=submit value=ON style=width:200px;height:75px onClick=location.href='./?LED=T\'>");
cliente.println("<input type=submit value=OFF style=width:200px;height:75px onClick=location.href='./?LED=F\'>");
cliente.println("</center>");
cliente.println("</body>");
cliente.println("</html>");
cliente.stop();
readString="";
}
}
}
}
}