I am trying to get the Arduino to talk with an external PHP server. This works great when the PHP server is on the local network. But if i try to get it to connect with an external server, I get connection failed. Have tried to solve this for a while. Is there something that needs to be added when talking to http. I know it's not the port or the router cause i have gotten stuff like the twitter client in the library to work with port 80.
This is the (network part) of the code that works locally. (When I have the server running on a computer on the network).
–––––––––––––––––––––––––––––––––––
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x08, 0x84 };
byte ip[] = { 172, 16, 3, 191 };
byte gateway[] = { 172, 168, 3, 354 };
byte subnet[] = { 255, 255, 252, 0 };
byte server[] = {172,16,3,21};
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
Serial.begin(9600);
}
void loop()
{
if (client.connect(server, 80)) {
Serial.println("connected...");
Serial.println("ARDUINO: forming HTTP request message");
//Sensor 1
client.print("GET /arduino.php?sensor1=");
client.print("stove&");
client.print("value1=");
client.print(state);
client.print("&");
client.println();
Serial.println("ARDUINO: HTTP message sent");
delay(0);
client.stop();
}
else
{
Serial.println("connection failure");
delay(2000);
}
}
Same code, but to a web server. Doesn't work at the moment.
––––––––––––––––––––––––––––––––––––––––––
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x08, 0x84 };
byte ip[] = { 172, 16, 3, 191 };
byte gateway[] = { 172, 168, 3, 354 };
byte subnet[] = { 255, 255, 252, 0 };
char serverName [] = "http://arpho.mobi";
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
Serial.begin(9600);
}
void loop()
{
if (client.connect(serverName, 80)) {
Serial.println("connected...");
Serial.println("ARDUINO: forming HTTP request message");
//Sensor 1
client.print("GET /app/arduino.php?sensor1=");
client.print("stove&");
client.print("value1=");
client.print(state);
client.print("&");
client.println();
Serial.println("ARDUINO: HTTP message sent");
delay(0);
client.stop();
}
else
{
Serial.println("connection failure");
}
}