I am attempting to pst data to a mySQL database on my remote server via a php script I wrote.
When I call the script via: "www.***.com/add.php?=Data1=47&Data2=49" then it posts to my database correctly.
Now I need my Arduino to do this via that script??? I've read numerous ways to do it but none have worked for me.
Below is my Setup section:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println(""); //Blank Line
Serial.println("Gaines' Arduino Chicken Coop Controler!");
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
// Start up the Sensor library
sensors.begin();
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
Serial.print("Controller is at: ");
Serial.println(Ethernet.localIP());
// Setup Outputs
pinMode(waterPump, OUTPUT);
pinMode(rainBarrel, OUTPUT);
pinMode(ventFan, OUTPUT);
pinMode(heatLamp, OUTPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(feedSensorA, OUTPUT);
pinMode(feedSensorB, OUTPUT);
// Setup Inputs
pinMode(watererLevel, INPUT);
pinMode(walkDoor, INPUT);
pinMode(chickenDoor, INPUT);
pinMode(photoCell, INPUT);
pinMode(barrelLevel, INPUT_PULLUP);
data = ""; //Blanks out Data String
Serial.println("Setup Complete");
Serial.println("");
} //Closes Setup
Below is the ethernet section of my code:
void sendData() { //ETHERNET Stuff
// Set Data String to send to PHP Script
data ="iTemp=" + iTemp + "&oTemp=" + oTemp + "&lLevel=" + lLevel + "&wDoor=" + wDoor + "&cDoor=" + cDoor + "&wLevel=" + wLevel + "&wPump=" + wPump + "&rBarrel=" + rBarrel + "&vFan=" + vFan + "&hLamp=" + hLamp;
if (client.connect(server, 80)) { //
Serial.println("");
Serial.println("Connected");
Serial.println("Sending Data to mySQL");
client.print("GET /coop/scripts/add.php?");
// client.print(data); // Tried this an didn't work. Data string is above if statement.
client.print("iTemp=");
client.print( insideTemperature );
client.print("oTemp=");
client.print( outsideTemperature );
client.print("&lLevel=");
client.print( lightLevel );
client.print("&wDoor=");
client.print( wDoor );
client.print("&cDoor=");
client.print(cDoor);
client.print("&wLevel=");
client.print(wLevel);
client.print("&wPump=");
client.print(wPump);
client.print("&rBarrel=");
client.print(rBarrel);
client.print("&vFan=");
client.print(vFan);
client.print("&hLamp=");
client.print(hLamp);
client.println(" HTTP/1.1");
client.println("Host: http://www.hscfire.com"); // SERVER ADDRESS
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Connection: close" );
client.println();
client.println();
Serial.println("Data Sent..");
Serial.println("");
} // Closes If Client Connect
else {
Serial.println("Connection Failed");
}
if (client.connected()) {
client.stop(); // close the connection:
Serial.println("Connection Closed");
Serial.println("");
}
}
And the short section above Setup that pertains to Ethernet:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,200);
char server[] = "hscfire.com"; // no www in front, is that OK?
// Start the Ethernet Client
EthernetClient client;
When the arduino runs it does all the correct Serial prints for debugging and says connected from this function but nothing is posted to my database. I'm at my wits end and can't figure this out.
I can post the complete code if needed but just alot of control stuff.
Any help is appreciated!
-Gaines