Can somebody give i a clue why it can't connect to a server?
best regards
Nikolaj
This is my output, and futher down is my code:
1
connecting...
0
connection failed
Code:
#include <SPI.h>
#include <Ethernet.h>
// Array to hold the number a SMS is retreived from
char senderNumber[20];
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x38, 0xBC }; //define the ethershields mac address.
//Ethernet options
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "www.nstrade.dk"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("1");
// connection state
boolean notConnected = true;
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
}
else{
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
// give the Ethernet shield a second to initialize:
delay(1000);
}
}
void recivestr(){
Serial.println("connecting...");
Serial.println(client.connect(server, 80));
if (client.connect("www.nstrade.dk", 80)) {
Serial.println("connected");
// Make a HTTP request:
//smsData
client.println("GET /index.php"); //GET /search?q=arduino HTTP/1.1
client.println("Host: www.gamma.compilar.dk");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
recivestr();
delay(10000);
}