I am new in Arduino, so I take ready sketch from Internet to control ON/OFF four relays connected to Arduino Mega via WEB interface. WEB server works on port 7400 on my unit and NMAP shows that port is open. But nothing in display in Firefox. Serial terminal shows that IP address is correct but when I try in web browser http://IP_OF_ARDUINO:7400 timeout is reported after several minutes. Below is my skech. Can anybody help me? What I am doing wrong?
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = {
0x1C, 0xAA, 0xBB, 0xCC, 0xDE, 0x22
};
EthernetServer server(7400);// WWW server port
const byte wyj1 = 46;// Przekaznik 1
const byte wyj2 = 47;// Przekaznik 2
const byte wyj3 = 48;// Przekaznik 3
const byte wyj4 = 49;// Przekaznik 4
String readString;
File plik;
void setup() {
delay(400);
pinMode(wyj1, OUTPUT);
pinMode(wyj2, OUTPUT);
pinMode(wyj3, OUTPUT);
pinMode(wyj4, OUTPUT);
Serial.begin(9600);
Serial.println("Arduino MEGA z Ethernet");
if (!SD.begin(4))
{
Serial.println("Nie wykryto karty SD");
//return; //przerwij program
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Nie mogę uzyskac adresu z DHCP");
for (;;)
;
}
// print your local IP address:
Serial.print("Moj adres IP: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
server.begin();
}
void loop() {
EthernetClient client = server.available();
if (client == true)
{
while (client.connected())
{
if (client.available())
{
char c = client.read();// Read char by char HTTP request
Serial.write(c);
if (readString.length() < 100)
{
readString = readString + c;// Store characters to string
}
if (c == '\n')
{
Serial.println(readString);
client.println("http/1.1 200 ok");// Send standard http headers
client.println("content-type: text/html");
client.println("Connection: close");
client.println();
client.println("<!doctype html><html>");
client.println("<body bgcolor='blue'>");
client.println("<center><head><title>Domowy system sterowania</title></head>");
client.println("<h2>Arduino MEGA serwer WEB(v1)</h2>");
client.println("<h4>To jest moj system</h4>");
client.println("<hr/><p> Kliknij na przycisk aby zminic stan ON/OFF <p/><hr/>");
client.print("<input type=button value='Wyjscie-1 ON' onmousedown=location.href='/?wyj1_on'>");
client.println("<input type=button value='Wyjscie-1 OFF' onmousedown=location.href='/?wyj1_off'>
");
client.print("<input type=button value='Wyjscie-2 ON' onmousedown=location.href='/?wyj2_on'>");
client.println("<input type=button value='Wyjscie-2 OFF' onmousedown=location.href='/?wyj2_off'>
");
client.print("<input type=button value='Wyjscie-3 ON' onmousedown=location.href='/?wy3_on'>");
client.println("<input type=button value='Wyjscie-3 OFF' onmousedown=location.href='/?wyj3_off'>
");
client.print("<input type=button value='Wyjscie-4 ON' onmousedown=location.href='/?wyj4_on'>");
client.println("<input type=button value='Wyjscie-4 OFF' onmousedown=location.href='/?wyj4_off'>
<hr/>");
client.println("</body></html>");
delay(1);// Page loading delay
client.stop();// Stopping client
if(readString.indexOf("/?wyj1_on") > 0) digitalWrite(wyj1, HIGH);
if(readString.indexOf("/?wyj1_off") > 0) digitalWrite(wyj1, LOW);
if(readString.indexOf("/?wyj2_on") > 0) digitalWrite(wyj2, HIGH);
if(readString.indexOf("/?wyj2_off") > 0) digitalWrite(wyj2, LOW);
if(readString.indexOf("/?wyj3_on") > 0) digitalWrite(wyj3, HIGH);
if(readString.indexOf("/?wyj3_off") > 0) digitalWrite(wyj3, LOW);
if(readString.indexOf("/?wyj4_on") > 0) digitalWrite(wyj4, HIGH);
if(readString.indexOf("/?wyj4_off") > 0) digitalWrite(wyj4, LOW);
readString = "";// Clearing string for next read
}// End of line reached
}// End of client available
}// End of client connected
}// End of client connection
}