i have two arduino mega with ethernet shield
arduino #1 (192.168.2.20)
the code of this arduino is written below
it acts as a server
clients browse to port 80
and they can control him
but if pin 7 is pressed
he will open http get (http://192.168.2.22:94/led1on)
it doesnt work connection fails
and port 80 on this arduino stop working
can someone help me plz?
arduino #2 (192.168.2.22)
this arduino acts as a server
if this arduino get a connection
http://192.168.2.22:94/led1on
it turn led1on
http://192.168.2.22:94/led1off
it turn led1off
this part is working perfect
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBB, 0xAF, 0xFE, 0xED};
String request ="";
IPAddress myDns(8,8,8,8);
EthernetClient client2;
EthernetClient client;
EthernetServer server(80);
IPAddress arduino2(192,168,2,22);
IPAddress ip(192,168,2,20);
String readString = String;
boolean lastConnected = false; // state of the connection last time through the main loop
void setup() {
Serial.begin(9600);
delay(1000);
Ethernet.begin(mac, ip, myDns);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString = readString + c;
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("");
client.println("");
if (readString.indexOf("/alive")>0)
{
Serial.println ("i am in alive");
//client.println("Content-Type: text/html");
client.println();
client.println("I Am Alive :- ) ");
client.println("I Am Alive :- ) ");
client.println();
break;
}
client.println("");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
readString = "";
}
if (client2.available()) {
char c2 = client2.read();
Serial.print(c2);
}
if (!client2.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
client2.stop();
}
if (digitalRead(7) == HIGH)
{
Serial.println (digitalRead(7));
httpRequest("/entrencelighton");
}
}
static String httpRequest(String request) {
if (client2.connect(arduino2, 94)) {
Serial.println("connecting...");
client2.println("GET " + request + " HTTP/1.1");
client2.println("User-Agent: arduino-ethernet");
client2.println("Connection: close");
client2.println();
delay(100);
}
else {
Serial.println("connection failed");
Serial.println("disconnecting.");
client2.stop();
}
}