Pages: [1]   Go Down
Author Topic: arduino+mysql (help)  (Read 4418 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Code:
<html>

<?php

//echo ("update_db.php indicator");
$DATA $_GET['temperatura'];
$DATA1 $_GET['sviesa'];



//Connect to database
$con mysql_connect("localhost""root""");
if(!
$con)
      &
#123;
      
die('Could not connect: ' .mysql_error());
      &
#125;
      
      
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
« Last Edit: January 13, 2011, 11:52:11 am by MantasRS » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46044
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can send all the data in one call:
GET /perkeliam.php?temperatura=valOne[glow]&nextName=valTwo&anotherName=anotherVal&lastName=lastValue[/glow]

Obviously, the GET request requires multiple client.print() statements (8 at least).

Then, the PHP script simply gets the 4 different values from the input string.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for fast answering. My knowledge is very poor could you show how it would look realized in the code?  :-[
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can i ask a question?
You are using USB connect or ethernetshield?
Because i'm using php with USB connection but i have some trouble to read serial value
Thank a lot
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im using ethernet shield
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46044
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
could you show how it would look realized in the code?
Code:
client.print("GET /perkeliam.php?temperatura=");
client.print(temperatura);
client.print("&nextName=");
client.print(valTwo);
client.print("&anotherName=");
client.print(anotherVal);
client.print("&lastName=");
client.print(lastValue);
This assumes, of course, that the variables exist and are valued. And that the names mean something. Neither of these assumptions is true, but the structure is correct.
Logged

Pages: [1]   Go Up
Jump to: