Go Down

Topic: database communication internet (Read 772 times) previous topic - next topic

luan47

Good afternoon,

Next, I'm almost a week reading articles and publications and simply not found what I want.
To facilitate understanding, I need a variable to be sent to the arduino for a database on the Internet.
Limitations: no direct communication with the computer (the Arduino will be powered by a source and communicate via the ethernet shield)

Given this:
- The classic php that creates a communication via socket will not work;
- The html dynamically created arduino's works, but there is no way to save data;

Possible solution:
- Provide a php page on a web server and make the arduino access (eg www.mysite.com/pagina.php?variable), and through the get() in php play data in the database.

Does anyone know how to do this, or has done something similar?

Thank you, I put my hand to share information about it.
Sorry for my english.
Big hug.

PaulS

You can have the Arduino-as-client issue a GET request, invoking a PHP script that stores data in a database. I know, because I do just that.

Code: [Select]
  if (client.connect())
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /pub/getValue.php?ID=2 HTTP/1.0");
    client.println();
  }
  else
  {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }


The getValue.php script is located in the pub folder on the web server. The data of interest is ID=2. The script accesses a MySQL database to get a value from a table with a column called ID. The column contains the value 2. Another column contains the value of interest.

The php script looks like:
Code: [Select]
<?php
require_once 'library/functions.php';
?>


<?php
include 
'library/config.php';
include 'library/opendb.php';

// foreach($_GET as $key=>$value)
// {
// echo "<p>GET: $key = [$value]</p>";
// }

$id $_GET['ID'];

$valueQuery "SELECT value FROM beer.tags WHERE ID = $id";
// echo "<p>Query: $valueQuery</p>";
$valueResult mysql_query($valueQuery);
if($valueResult)
{
$row mysql_fetch_assoc($valueResult);
$value $row['value'];
echo "$value";
}

include 'library/closedb.php';
?>



You can easily change what the script does to store data, instead. If you need help, ask.


luan47

Seriously what is it? Hell, I imagined something much more complex. I will implement it and post a return. Thank you!!!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy