Hi. I've been messing around with an Arduino sketch to send analog readings over ethernet to a PHP script which will then add said data to a mySQL server. I've had to use the newly added DNS support to connect to the server, and all seems to be working, except that once connected, the webserver appears to be rejecting the Arduino connection and completely discards it.
The Arduino serial says that all is fine and dandy, but the logs in the server don't even list a connection, unless I have the Arduino send the url in the format "http://www.server.comwww.server.com/dbtest.php" rather than the way it should be. When I do this, the log actually shows that the Arduino was connected, but that the client has no http version or any kind of browser characteristics.
I'm wondering if I might be missing some code that is needed for the DNS support, as my original code connected to the webserver via IP only(which couldn't be used, I was forced to go the DNS route). Any help would be much appreciated. Thanks.
I know the code is sloppy and disorganized. It is a concept alpha. I apologize.
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX };
byte ip[] = { 192,168,0,32 };
byte gw[] = {192,168,0,1};
byte subnet[] = { 255, 255, 255, 0 };
char serverName[] = "www.server.com"; // Server URL
int data = 0;
int potPin = A0; // In This case the potentiameter data is taken from pin 2 and sent to a sql server
void setup()
{
pinMode(potPin, INPUT);
Serial.begin(9600); // Used for serial debugging
}
void loop()
{
Serial.println("Program running...");
delay(5000);
senddata(); // Data is sent every 5 seconds
}
void senddata()
{
data = analogRead(potPin); //Reading analog data
Ethernet.begin(mac, ip, gw, subnet);
EthernetClient client;
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
Serial.println();
Serial.println("Connecting to:");
Serial.println(serverName);
delay(1000); //Keeps the connection from freezing
if (client.connect(serverName, 80)) {
Serial.println("Connected.");
delay(2000);
Serial.println("Sending...");
// This sends data from potentiameter to the serial monitor
Serial.println(data);
// End
client.println("GET /dbtest.php?dbtest=35");
//client.println(data);
client.println(" HTTP/1.1");
//client.println("Host: www.server.com");
client.println();
Serial.println();
//This sends any HTTP data Arduino receives to serial monitor
if (client.available()) {
char c = client.read();
Serial.print(c);
}
//End
Serial.println("Transmission complete. Restarting...");
}
else
{
Serial.println("Connection unsuccessful");
}
//}
//stop client
client.stop();
while(client.status() != 0)
{
delay(5);
}
}