Static / dynamic IP address ethernetshield

Hallo gents,

I use the ethernetshield with a arduino 328 board and the domotic script for the android.
The script from bl4d3 as can be found else on the forum.
The LED controlled via the Wi-Fi with a android phone is working very well.
But if I switch off the Wi-Fi on the phone and switch on the G3 service the LED is not possible to control.
So I think as long as I am in the Wi-Fi range it is working. But I like to have it over the internet.
I am using a WAG325 ADSL router.
As far as I understand I must change something like a static IP dynamic to a static address but howe and where.

Theo

well the problem is that you must first find out your ip that your phone has when your using the 3G service you can find out by opening your phone browser and type this addy http://www.ip-adress.com/ this should tell you the current ip address your phone has

youll need to change the ip address from your sketch with the one for ip-adress.com , also youll have to do this everytime you connect/disconnect from the 3G service as im sure your ip will change

Thanks for the reply.
I looked for the IP adres on myipaddress.com.
Indeed the IP address will change every time.
To avoid every time looking for the IP address I must change someting in the router
like forwarding the IP address and make a dynamic address to a static address.
I tested your proposal but it didn,t work sorry.

Theo

well im not really sure what do you want to do maybe if you post more details/some code i may give your other ideas

also im not sure if your using your local network or your trying to use the internet - as far as i can tell your using the local network when connecting arduino and phone to the router (so your using ip likes 192.168.1.x unless you configured other local ip class)

anyway more details would help

Hallo Putyn,

Yes indeed I use the local network as I use the Wi-Fi switched on and the LED is working.
The script using is enclosewd and is the script from domotic.
Still the question howe to conrol the LED on a arduino which is mounted on a ethernet sheeld,
My net work is as follows I use a ADSL telephone line which is fed to a WAG325N Wi-Fi router the ethernet sheeld is plugged in the router.

Here the script.

#include <SPI.h>
#include <Ethernet.h>
#include <DallasTemperature.h>
#include <RemoteSwitch.h>
#define ONE_WIRE_BUS 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBE };
byte ip[] = { 192 ,168 ,1 ,15 };
byte gateway[] = { 192 ,168 ,1 ,1 };
byte subnet[] = { 255 ,255 ,255 ,0 };
Server server(5000); 

String readString = String(30);

 

void setup(){
sensors.begin();
Ethernet.begin(mac, ip, gateway, subnet);
delay(500);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
pinMode(4, OUTPUT);
digitalWrite(4, LOW);
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
pinMode(6, OUTPUT);
digitalWrite(6, LOW);
//Serial.begin(9600);
} 

void loop(){

unsigned long code1;
unsigned long code2;  
unsigned long code3;
unsigned long code4;    
unsigned long code5;
unsigned long code6;  

code1 = 722;
code2 = 726;
code3 = 1694;
code4 = 1698;
code5 = 2018;
code6 = 2022;
code1 |= (unsigned long)315 << 23;
code2 |= (unsigned long)315 << 23;
code3 |= (unsigned long)315 << 23;
code4 |= (unsigned long)315 << 23;
code5 |= (unsigned long)315 << 23;
code6 |= (unsigned long)315 << 23;
code1 |= 3L << 20;
code2 |= 3L << 20;
code3 |= 3L << 20;
code4 |= 3L << 20;
code5 |= 3L << 20;
code6 |= 3L << 20;

sensors.requestTemperatures();  
float temperatureReading_341 = sensors.getTempCByIndex(1);

// float temperatureReading_354 = sensors.getTempCByIndex(1);

//Serial.print(temperatureReading_341);


Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 30)
{
readString = readString + c;
}
if (c == '\n') {
//Serial.print(readString);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();


if(readString.startsWith("GET /?out=3&status=1"))
{RemoteSwitch::sendTelegram(code1,10);
//digitalWrite(3, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(3);
client.print("\"}");
}
if(readString.startsWith("GET /?out=3&status=0"))
{RemoteSwitch::sendTelegram(code2,10);
//digitalWrite(3, LOW);
client.print("{\"status\" : \"0\" , \"out\" : \"");
client.print(3);
client.print("\"}");
}


if(readString.startsWith("GET /?out=4&status=1"))
{RemoteSwitch::sendTelegram(code3,10);
//digitalWrite(4, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(4);
client.print("\"}");
}
if(readString.startsWith("GET /?out=4&status=0"))
{RemoteSwitch::sendTelegram(code4,10);
//digitalWrite(4, LOW);
client.print("{\"status\" : \"0\" , \"out\" : \"");
client.print(4);
client.print("\"}");
}


if(readString.startsWith("GET /?out=5&status=1"))
{RemoteSwitch::sendTelegram(code5,10);
//digitalWrite(5, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(5);
client.print("\"}");
}
if(readString.startsWith("GET /?out=5&status=0"))
{RemoteSwitch::sendTelegram(code6,10);
//digitalWrite(5, LOW);
client.print("{\"status\" : \"0\" , \"out\" : \"");
client.print(5);
client.print("\"}");
}


if(readString.startsWith("GET /?out=6&status=1"))
{Serial.print("Out 6 Status off ");
digitalWrite(6, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(6);
client.print("\"}");
}
if(readString.startsWith("GET /?out=6&status=0"))
{Serial.print("Out 6 Status off ");
digitalWrite(6, LOW);
client.print("{\"status\" : \"0\" , \"out\" : \"");
client.print(6);
client.print("\"}");
}


if(readString.startsWith("GET /?out=9&status=1"))
{Serial.print(temperatureReading_341);
client.print("{\"status\" : \"ok\" , \"value\" : \"");
client.print(temperatureReading_341);
client.print("\"}");
}


//if(readString.startsWith("GET /?out=7&status=1"))
//{Serial.print("\n 10 f_MCP9700A \n");
//client.print("{\"status\" : \"ok\" , \"value\" : \"");
//client.print(temperatureReading_354);
//client.print("\"}");
//}


if(readString.startsWith("GET /?out=all"))
{
Serial.print("\n OUT ALL\n");
client.print("{\"ip\" : \"192.168.1.15\", ");
client.print("\"devices\" : ");
client.print("[{ \"type\" : \"light\", \"name\" : \"Lamp1\", \"out\" : \"");
client.print("3");
client.print("\"}");
client.print(",{ \"type\" : \"light\", \"name\" : \"Lamp 2\", \"out\" : \"");
client.print("4");
client.print("\"}");
client.print(",{ \"type\" : \"light\", \"name\" : \"Lamp 3\", \"out\" : \"");
client.print("5");
client.print("\"}");
client.print(",{ \"type\" : \"light\", \"name\" : \"Enable Rf\", \"out\" : \"");
client.print("6");
client.print("\"}");
client.print(",{ \"type\" : \"temperature\", \"name\" : \"Temp 1\", \"out\" : \"");
client.print("9");
client.print("\"}");
//client.print(",{ \"type\" : \"temperature\", \"name\" : \"Temp 2\", \"out\" : \"");
//client.print("7");
//client.print("\"}");
client.print("]}");
}
readString="";
client.stop();
}
}
}
}
}



 











Logged

Kind regards,

Theo

ok let me know if i got this correct
your arduino acts like an web server on port 5000 and does different task based on the request url
you connect with your phone to the wireless network then open the web browser/application which connects to the webserver running on 192.168.1.15 :5000
and you want to be able to control the arduino from the internet using your phone

if that is correct you need to do something like this
first you need to do a port forwarding (im not familiar with your router so youll need to google that if you dont already know how to do it)
and you need to forward all the traffic that comes from external ip (the internet) on port 5000 to the local ip assigned to arduino (192.168.1.15 port 5000)

then all you need to do its find your external ip (you can do that by clicking on the link i posted in the second post) and point your phone web browser/application to that ip and port

correct me if im wrong :slight_smile:

http://www.no-ip.com/ offers a nice (free or paid) service to have a "real webaddress" mapped upon your router external port that can be portforwarded to your arduino.

Did it a few months ago so I could monitor status of sensors behind a firewall. Worked like a charm

also http://dyn.com/ and http://freedns.afraid.org/ and http://www.tzo.com/ or http://www.zoneedit.com/ offer the same service

but you should look at your router management page there youll have an option to use such a service for example my asus router can update services from dyn.com, tzo.com and zoneedit.com but im using freedns.afraid.org because they offer more options but youll be just fine with no-ip.org or dyn.com

Best Robtilaart,

Thanks for your reply.
I am still busy to solve this problem.
Your solution seems to me very workable.
Still two points to think over 1) with your solution is it still working with either local as it do now and via G3 with the same android app?
2) On the domotic topic posted on 06-01-2011 by Arduino-idea the app is working local as well as via G3????
I get the ideer this is doubtfull!
I hope this problem will be solved.

Theo