Pages: [1]   Go Down
Author Topic: database communication internet  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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:
<?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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: