Hi I'm new here, and I faced with the problem. I found code witch allows received sensor data sent to mysql. However, I have a 4 of sensors and want to transfer data to MySQL. Here is my code:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 77 };
byte gw[] = {192,168,1,83};
byte server[] = { 192, 168, 1, 83 }; // Server IP
byte subnet[] = { 255, 255, 255, 0 };
float data = 0;
float tempPin = 2; // In This case the temperature is taken from pin 2 and sent to a sql server
float temperatura=0;
float sviesPin = 5;
float sviesa = 0;
void setup()
{
pinMode(tempPin, INPUT);
Serial.begin(9600); // Used for serial debugging
}
void loop()
{
Serial.println("Program running...");
delay(500);
senddata(); // Data is sent every 5 seconds
}
void senddata()
{
data = analogRead(tempPin); //Reading analog data
temperatura = ((data*500)/1024);
sviesa = analogRead(sviesPin);
Ethernet.begin(mac, ip, gw, subnet);
Client client(server, 80);
Serial.println();
Serial.println("ATE :)");
delay(1000); //Keeps the connection from freezing
if (client.connect()) {
Serial.println("Connected");
client.print("GET /perkeliam.php?temperatura=");
client.print(temperatura);
Serial.print(temperatura);
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.83");
client.println();
Serial.println();
client.print("GET /perkeliam.php?sviesa=");
Serial.print(sviesa);
client.print(sviesa);
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.83");
client.println();
Serial.println();
}
else
{
Serial.println("Connection unsuccesfull");
}
//}
//stop client
client.stop();
while(client.status() != 0)
{
delay(5000);
}
}
here's my PHP
<html>
<?php
//echo ("update_db.php indicator");
$DATA = $_GET['temperatura'];
$DATA1 = $_GET['sviesa'];
//Connect to database
$con = mysql_connect("localhost", "root", "");
if(!$con)
{
die('Could not connect: ' .mysql_error());
}
mysql_select_db("duomenys", $con);
mysql_query(" INSERT INTO temperatura (id, temp, sviesa, Data) VALUES ('NULL', $DATA, $DATA1, NOW())");
mysql_close($con);
?>
</html>
It sends only the first value, while the other disappears who knows where. I would be very grateful for the help. Sorry for my English