Hello,
i just build a device to measure my pool temperatures and send these temperatures to my local(!!) apache webserver.
The Arduino works as Server and Client. This worked fine.
Now i want my website to be on an external webserver, so my computer doesn't have to run all day long.
But long story short, thats my problem:
My Arduino CAN'T connect (as client) to any server outside of my local network.
Even though,
- I can access to my arduino (acting as server) from the internet.
- My Arduino can connect to my local webserver (acting as client) and send temperature data.
I just don't understand why the arduino can receive commands from the internet (server mode), but can't send commands by itself (client mode).
My sketch is veery long, so here are the important parts:
#include <SPI.h>
#include <Ethernet.h>
byte ip[] = { 192, 168, 178, 16 }; //ip address to assign the arduino
byte gateway[] = { 192, 168, 178, 1 }; // the router's gateway address
byte subnet[] = { 255, 255, 255, 0 };
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xEA, 0xC9 };
byte bridge_server[] = {192, 168, 178, 21}; // LOCAL SERVER, WORKS!
// char bridge_server[] = "pool.xxxxxxx.de"; // WEBSERVER'S DOMAIN, DOESN'T WORK
// byte bridge_server[] = {88, 84, xxx, xxx}; // WEBSERVER'S IP, DOESN'T WORK
// byte bridge_server[] = {74, 125, 224, 72}; //GOOGLE'S IP, DOESN'T WORK
EthernetServer server = EthernetServer(80); // LISTEN ON PORT 80,
// I SET UP THE PORTFORWARDING IN MY ROUTER, I CAN ACCESS TO THE ARDUINO FROM OUTSIDE OF
// MY NETWORK (tested with iphone and wlan off)
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet); // initialize the ethernet device
server.begin(); // start listening for clients
}
void loop()
{
EthernetClient client;
if (client.connect(bridge_server, 80)) // HERE IT STUCKS, client.connect returns false (exception: local webserver 192.168.178.21)
{
Serial.println("CONNECTION OK!");
... do stuff ...
}
else
{
Serial.println("CANT CONNECT!");
}
EthernetClient client = server.available();
if (client)
{
while (client.connected())
{
if (client.available())
{
.... do something and answer to the connected client, works fine.
}
}
}
}
Does anyone have a solution for my problem??