I want to control the LED through the Internet. First, I controlled it from my Local Area Network (LAN), it 's ok. Then, I tried to control it from WAN but I had the problem:
- I accessed to my modem, using Port Forwarding, forwarded the port 80 to connect to my Arduino. But my modem denied to forward port 80.
- Then I changed my code: "EthernetServer server(80)" to another port. But, after I changed, I could not access to Arduino from the LAN either.
How can i resolve this problem? Please help me. Thank you for your reading.
Here 's my code:
#include<SPI.h>
#include<Ethernet.h>
int led = 9;
byte mac[] = {
0x16, 0x08, 0x19, 0x92, 0x92, 0x19
};
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(80);
String readString;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
pinMode(led, OUTPUT);
Ethernet.begin(mac);
server.begin();
Serial.print("Server ‘s IP: ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 100) {
readString += c;
//In C
}
if (c == '\n') {
Serial.println(readString);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>CONTROL ARDUINO THROUGH THE INTERNET</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<CENTER>");
client.println("<H1>TURN ON AND TURN OFF THE LED</H1>");
client.println("
");
client.println("<a href=\"/ON\"\">TURN ON</a>");
client.println("
");
client.println("
");
client.println("<a href=\"/OFF\"\">TURN OFF</a>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
client.stop();
Serial.println("client disconnected");
if (readString.indexOf("ON") > 0) {
digitalWrite(led, HIGH);
}
if (readString.indexOf("OFF") > 0) {
digitalWrite(led, LOW);
}
readString = "";
}
}
}
}
}