W5100 ethernet connection problems to 4G

Hello,

i have a problem getting thing working. I have a arduino mega with a W5100 shield. It all works fine, i can connect with the server on my mobile phone with 4g and with my local network.
My goal is to control some in an outputs on my phone no matter where i am.

The problem:

When i disconnect arduino from the power supply then wait a few minutes and plug the power in again, the arduino will connect to my lokal network, but it fails to connect to my 4g network. This meen if i am connected with my WIFI i can connect to the shield, when i connected to 4G then i cant connect to the shield.

To fix this issue i have to unplug the power from the router, wait few seconds then connect the power again. And voila i can connect to 4G.

What is the problem and how to solve this problem ?

//zoomkat 1-10-11
//web LED code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
  0x22, 0x22, 0x34, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0,25);


//byte gateway[] = {
  //192,168,0,1
//};

byte gateway[] = {
  192,168,0,1
};
byte subnet[] = {
  255,255,255,0
};

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(903); //server port

String readString;

//////////////////////

void setup(){

  pinMode(22, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  //enable serial data print
  Serial.begin(9600);
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  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(c); //uncomment to see in serial monitor
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString);

          //now output HTML data header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>HTML form GET example</H1>");

          client.println("<FORM ACTION=\"http://213.**.**.**:903\" method=get >");

          client.println("Pin 4 \"on\" or \"off\": <INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\">
");

          client.println("<INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Change Pin 4!\">");

          client.println("</FORM>");

          client.println("
");

          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          /////////////////////
          if(readString.indexOf("1005") >0)//checks for on
          {
            digitalWrite(22, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("10051990") >0)//checks for off
          {
            digitalWrite(22, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

You are using 255.255.255.0 as the gateway.

// change this 
  Ethernet.begin(mac, ip, gateway, subnet);
// to this
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

Didn't work...

When i disconnect arduino from the power supply then wait a few minutes and plug the power in again, the arduino will connect to my lokal network, but it fails to connect to my 4g network. This meen if i am connected with my WIFI i can connect to the shield, when i connected to 4G then i cant connect to the shield.

This is not an arduino problem but a network problem. I guess you have some special configuration on the router that forwards traffic to the Arduino. And how do you know the IP address of your network on the phone when connected to the 4G? I get the impression that you only have access to the Arduino on WiFi anyway and you just think that you're on 4G although the traffic is handled by WiFi.

pylon:
I get the impression that you only have access to the Arduino on WiFi anyway and you just think that you're on 4G although the traffic is handled by WiFi.

Wrong.

When i reset my modem, while arduino is on i just type in the inet explorer my ip and the selected portnumber then it will jump to my server.
I can get on the server everywhere outside and at work, the network that im using on my phone is 4g not WIFI!!! I can control buttons en read values.

The point is:

when i unplug the arduino from its power source and reconnect it after 2 minutes, just THEN i am only able to connect to my home wifi and thats it. I cannot connect with 4g anymore, to solve this i have to restart the modem again.

"you just think that you're on 4G although the traffic is handled by WiFi" that is a insult.

hazanovo:
"you just think that you're on 4G although the traffic is handled by WiFi" that is a insult.

Doesn't take much to rile you up, does it?

If I was pylon, I would be insulted by your answer.

Without a GSM shield, I don't quite understand how your Arduino is able to connect to 4G.
Makes no sense.

Power off your router.
Power on your Arduino.
Try to connect to website www.yahoo.com
You won't be able to.

maybe my question was not clear.

myphone(4g)--->ip internetcompany--->router(port)------>w5100 (this is what i meen with my 4g to webserver) and this work great.

to connect to my webserver on my phone i type in the internet explorer : ip internetcompany:port

this will connect me to the w5100 server.

when i dissconnect arduino from its powersource and reconnect it after 2 minutes, then it will not connect my phone(4g) to the w5100 anymore.

When that happen i am only able to connect with my phone(home wifi) and thats it. To solve this problem i have to restart my modem. After restarting modem i can again connect with my phone(4g).

I looking for a solution to solve this without restarting my modem everyday..

Sounds like your router is the problem.
Not sure why you are posting here.

Because i was hoping it was a code problem... But now i am pretty sure its the router.