i have got a problem in transferring data from arduino to sql database (i am using php)
i use ethernet shield to transfer data from client to server
i have local network ...i mean just laptop and arduino connected using straight through cable...no internet connection
i alredy set up database and its interfaces
my sensors are already tested and they are doing fine, problem is in transeferring of data
below is my arduino codes
#include <SPI.h>
#include <Ethernet.h>
float tempB;
float tempC;
float humB;
float humC;
int tempD;
int tempE;
int humD;
int humE;
int tempPin1 = 0;
int tempPin2 = 1;
int humPin1 = 2;
int humPin2 = 3;
String txData ="";
byte mac[] = { 0xDE, 0xA2, 0xDA, 0x0D, 0x83, 0x9D };
byte ip[] = { 192, 168, 1, 199 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 192, 168, 1, 198 };
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
}
void loop()
{
tempB = analogRead(tempPin1);
tempC = analogRead(tempPin2);
humB = analogRead(humPin1);
humC = analogRead(humPin2);
tempD = (5.0 * tempB * 100.0)/1024.0;
tempE = (5.0 * tempC * 100.0)/1024.0;
humD = ((humB)/(1.0305 + (0.000044*tempD) - (0.0000011*tempD*tempD)))/10;
humE = ((humC)/(1.0305 + (0.000044*tempE) - (0.0000011*tempE*tempE)))/10;
txData = "temp1="+ (String (tempD)) + "temp2="+ (String (tempE)) + "hum1="+ (String (humD)) + "hum2="+ (String (humE)) ;
EthernetClient client;
if (client.connect(server,80))
{
Serial.println("Connected to server...");
Serial.println();
client.print("POST /update/update.php HTTP/1.1\n");
client.print("Host: server\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(txData.length());
client.print("\n\n");
client.print(txData);
}
else
{
Serial.println("Connection Failed.");
Serial.println();
}
delay(5000);
}
below is my php script
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'datalogger';
$query = "INSERT INTO monitoring(temp1,temp2,hum1,hum2)
VALUES('$_POST[temp1]', '$_POST[temp2]', '$_POST[hum1]', '$_POST[hum2]')";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db("datalogger");
}
?>
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
comp2.ino (1.94 KB)