I am using the below web client sketch that connects to server 192.168.1.3
#include <SFE_BMP180.h>
#include <SPI.h>
#include <Ethernet.h>
#include<dht.h>
dht DHT;
// You will need to create an SFE_BMP180 object, here called "pressure":
SFE_BMP180 bmp;
#define DHT11_PIN 8
double tempInC;
int humidity;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
EthernetClient client;
char server[] = "192.168.1.3"; // IP Adres (or name) of server to dump data to
long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 250000; //READING INTERVAL
String data;
void setup() {
Serial.begin(9600);
while (!Serial) {
; //wait for serial port to connect. Needed for native USB port only
}
if (bmp.begin()) {
Serial.println("BMP init Success");
}
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /arduino/add.php?temp1=31.32&&hum1=16 HTTP/1.1");
client.print("Host: ");
client.println(server);
client.print("Content-Length: ");
client.println(data.length());
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
data = "";
}
void loop() {
int chk = DHT.read11(DHT11_PIN);
char status;
status = bmp.startTemperature();
// tempInC = DHT.temperature;
if (status != 0) {
delay(status);
status = bmp.getTemperature(tempInC);
}
else Serial.println("error retrieving temperature measurement\n");
humidity = DHT.humidity;
data = "?temp1=" + String(tempInC) + "&&hum1=" + String(humidity);
if (client.connect(server, 80)) {
Serial.print(F("connected. My IP is "));
Serial.println(Ethernet.localIP());
// Make a HTTP request:
client.print("GET /arduino/add.php");
client.print(data);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
// client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
}
else {
Serial.println("connection failed");
}
Serial.println(data);
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
}
// delay(60000); // WAIT FOR A MINUTE BEFORE SENDING AGAIN
delay(20000);
}
I am not sure what is wrong with the code above , it just doesnt inserts into database however if I directly executes the 192.168.1.3/arduino/add.php?temp1=31.32&&hum1=16
then it works.
<?php
include("connect.php");
$link=Connection();
$temp1=$_GET["temp1"];
$hum1=$_GET["hum1"];
$query = "INSERT INTO `tempLog` (`temperature`, `humidity`)
VALUES ('".$temp1."','".$hum1."')";
mysql_query($query,$link);
mysql_close($link);
header("Location: index.php");
?>
which makes me think that PHP SQL part is correct some not right with my arduino sketch,
Can anyone of you guys please help.