Hi
I've been trying to connect to the Ethernet Shield from the web without any success.
It is working perfectly on the LAN but that's all...
I have a Internet Provider with the box that gives me a static IP.
Static IP : 78.XXX.XX.XXX
I have my router/box that has an IP : 192.168.0.254
My Ethernet Shield has it's IP : 192.168.0.177
and I have redirected ports in my router : External (80) - ip (192.168.0177) - internal (80)
How should I connect to my Ethernet Shield on my phone ?
I have tried like this :
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xB0, 0x52 }; //physical mac address
byte ip[] = { 192, 168, 0, 177 }; // l'arduino
byte gateway[] = { 78, XXX, XX, XXX }; // static IP of router
byte subnet [] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
int statePin = 0;
//////////////////////
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println("server LED test 1.0"); // check
}
But impossible to connect from my phone (i'll post the entire code at the end)
How should I manage to get a good connection. Seems that their are different good/bad ways of connecting..
Thanks for your help
my entire code :
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xB0, 0x52 }; //physical mac address
byte ip[] = { 192, 168, 0, 177 }; // ip de l'arduino
byte gateway[] = { 78, XXX, XXX, XXX }; //
byte subnet [] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
int statePin = 0;
//////////////////////
void setup(){
pinMode(6, OUTPUT); // Pin de la Led
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println("server LED test 1.0"); // verification que c'ets loadé.
}
void loop(){
// creation connexion
EthernetClient 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;
Serial.print ("lecture de C ");
Serial.print(readString);
Serial.println (" ");
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println ("Lecture de readstring");
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />");
client.println("<TITLE>Home Automation</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Home Automation</H1>");
client.println("<hr />");
client.println("
");
client.println("<a href=\"/?lighton\"\">Turn On Light</a>");
client.println("<a href=\"/?lightoff\"\">Turn Off Light</a>
");
client.println("
");
client.println("<a href=\"/?lightblink\"\">Blink Led</a>
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("?lighton") >0)//checks for on
{
Serial.println("Led On");
statePin = 0;
}
if(readString.indexOf("?lightoff") >0)//checks for off
{
Serial.println("Led Off");
statePin = 1;
}
if(readString.indexOf("?lightblink") >0)//checks for off
{
Serial.println("Led blink");
statePin = 2;
}
//clearing string for next read
readString="";
}
}
}
}
if (statePin == 0)
{ //Serial.println ("STATE PIN IS ON");
digitalWrite (6, HIGH);
}
if (statePin == 1)
{
//Serial.println ("STATE PIN IS OFF");
digitalWrite (6, LOW);
}
if (statePin == 2)
{
Serial.println ("STATE PIN IS BLINKING");
digitalWrite (6, HIGH);
delay(300);
digitalWrite (6, LOW);
delay(300);
}
}