Hi.
I am creating a project for the control of a fan and door via Arduino.
I have arduino wiznet ethernet shield.
My program is as follows:
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 200 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 5; // LED pin
int ledPin2=7;
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON=false; //LED status flag
boolean LED2ON=false;
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT); //Set pin 5 to output
pinMode(ledPin2, OUTPUT); //Set pin 7 to output
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c; //replaces readString.append(c);
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//dirty skip of "GET /favicon.ico HTTP/1.1"
if (readString.indexOf("?") <0)
{
//skip everything
}
else
//lets check if LED should be lighted
if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
{
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFF
LEDON = false;
}
if(readString.indexOf("M=1")>=0)
{
//led has to be turned ON
digitalWrite(ledPin2, HIGH); // set the LED on
LED2ON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin2, LOW); // set the LED OFF
LED2ON = false;
}
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//set background to yellow
client.print("<body style=background-color:White>");
//send first heading
client.println("<font color='red'><h1>Group 10 Server</font></h1>");
client.println("<hr />");
client.println("<hr />");
client.println("<font color='red'><h3>Please select your choice</font></h3>");
client.println("<hr />");
client.println("<hr />");
if(LEDON==true && LED2ON==true)
{
client.println("<h3>FAN</h3><form method=get name=LED><input type=checkbox name=L value=1 CHECKED>ON
<input type=checkbox name=L value=0>OFF
<h3>DOOR</h3><input type=checkbox name=M value=1 CHECKED>OPEN
<input type=checkbox name=M value=0>CLOSE
<input type=submit value=submit></form>");
}
if (LEDON==true && LED2ON==false)
{
client.println("<h3>FAN</h3><form method=get name=LED><input type=checkbox name=L value=1 CHECKED>OPEN
<input type=checkbox name=L value=0>CLOSE
<h3>DOOR</h3><input type=checkbox name=M value=1>OPEN
<input type=checkbox name=M value=0 >CLOSE
<input type=submit value=submit></form>");
}
if (LEDON==false && LED2ON==true)
{
client.println("<h3>FAN</h3><form method=get name=LED><input type=checkbox name=L value=1 >ON
<input type=checkbox name=L value=0>OFF
<h3>DOOR</h3><input type=checkbox name=M value=1 CHECKED>OPEN
<input type=checkbox name=M value=0 >CLOSE
<input type=submit value=submit></form>");
}
if (LEDON==false && LED2ON==false )
{
client.println("<h3>FAN</h3><form method=get name=LED><input type=checkbox name=L value=1 >ON
<input type=checkbox name=L value=0>OFF
<h3>DOOR</h3><input type=checkbox name=M value=1>OPEN
<input type=checkbox name=M value=0 >CLOSE
<input type=submit value=submit></form>");
}
client.println("
");
readString="";
//printing status
client.print("<font size='5'>Fan status: ");
if (LEDON)
client.println("<font color='green' size='5'>ON");
else
client.println("<font color='red' size='5'>OFF");
client.println("<hr />");
client.println("<hr />");
client.print("<font color='black' size='5'>Door status: ");
if (LED2ON)
client.println("<font color='green' size='5'>OPENED");
else
client.println("<font color='red' size='5'>CLOSED");
client.println("<hr />");
client.println("<hr />");
//stopping client
client.stop();
}
}
}
}
}
Now this program works fine in LAN.
But how can I use this program via internet. I have a nokia siemens router. When I enter my IP address(of internet) my router page opens but I want to open the web server interface.
Please help me.