I am attempting to upload data via a PHP script. The below code outputs the url for debugging, and when putting that url directly into the browser it updates the database successfully, so the problem must be in the connection. But I have no idea how to debug a connection issue. If anyone can see the problem in this code that would be the best help, if not if you could point me in a direction of lines to add to produce output that would tell me where the problem is that would be helpful as well.
(I am not really uploading to www.example.com, just don't want to put my actual PHP script location out there for all to see.)
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x25, 0x00 };
char server[] = "www.example.com";
byte ip[] = { 192,168,1,127 };
EthernetClient client;
String senddata = "";
char inChar;
int siteID = 49;
String inputString = "";
String transmitterid = "0";
String sensorid = "0";
String sensorcondition = "0";
void setup() {
Serial.begin(9600);
Serial.println("Attempting to get an IP address using DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip);
}
Serial.print("My address: ");
Serial.println(Ethernet.localIP());
delay(1000);
Serial.println("Waiting for input...");
}
void loop() {
}
void serialEvent() {
static int i = 0;
while (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar != ','){
inputString += inChar;
}
else {
i++;
switch(i){
case 1:
sensorid = inputString;
inputString = "";
break;
case 2:
sensorcondition = inputString;
inputString = "";
break;
case 3:
transmitterid = inputString;
inputString = "";
break;
}
}
if (inChar == '\n') {
Serial.println(sensorid);
Serial.println(sensorcondition);
Serial.println(transmitterid);
senddata = "GET /updatelog.php?Sensor=";
senddata += sensorid;
senddata += "&Condition=";
senddata += sensorcondition;
senddata += "&transmitter=";
senddata += transmitterid;
senddata += "&siteID=";
senddata += siteID;
senddata += " HTTP/1.0";
if (client.connect(server, 80)) {
client.println(senddata);
Serial.print(senddata);
}
else{
Serial.println("connection failed");
Serial.print(senddata);
}
delay(2000); //let the server process this sensor data before sending more
client.stop();
}
}
}