Interfacing an Arduino to MySQL on a Raspberry via GSM

Hi All,

my project is to have the following architecture :

  • in a field an Arduino UnO talking with 3 Nano (bluetooth). The UNO gathers data from its 3 slaves and has to put them in a MySQL database located in a Raspberry 15 km away.

  • I would like to use the GSM Shield but I can not manage to find such an exemple on the Net.

Arduino --> GSM ---> MySQL.

On the Raspberry I have Apache, MySQl and PHPmyAdmin working.

How can I make the link ?

I am looking forward to reading from you. Some link would be highly appereciated.

I thank you in advance

Pierrick

Write a python script that receives the data from the arduino and stores it in the database.

lg, couka

Write a python script that receives the data from the arduino and stores it in the database.

When he already has PHP installed and configured? Why? PHP and MySQL go hand in hand.

PaulS: When he already has PHP installed and configured? Why? PHP and MySQL go hand in hand.

PHPmyadmin is just a management tool for mySQL databases, so to me that's not a clear indication that OP knows any PHP. Since he wants to use a Raspberry where Python is the most used language, I thought that's the approach that has the best support in the Raspberry community.

But I totally agree, PHP and MySQL go hand in hand.

lg, couka

PHPmyadmin is just a management tool for mySQL databases, so to me that's not a clear indication that OP knows any PHP.

Possibly a valid consideration. But, the fact that PHPMyAdmin is installed and functioning indicates that PHP is installed, too.

A PHP script to insert data from a GET request into a MySQL database is nearly trivial. I have a dozen or more examples, if OP wanted to go that route, without learning a lot about PHP.

Thank you all,

PaulS, I would be pleased to receive an exemple of PHP program to receive data from the GSM and place them in a MySQL table.

Pierrick

OK Travis_farmer for the library but I have a GSM between the Arduino ans MySql.

It doesn't seem to be supported by this library.

pifouni:
Thank you all,

PaulS, I would be pleased to receive an exemple of PHP program to receive data from the GSM and place them in a MySQL table.

Pierrick

Here is one example, that expects the data to be POSTed, but _POST could easily be changed to _GET.

<?php
	require_once 'library/functions.php';
	checkLogin(1);

	if(isset($_POST['addterm']))
	{
		include 'library/config.php';
		include 'library/opendb.php';

		$sm = $_POST['sm'];
		$sd = 1;
		$sy = $_POST['sy'];

		$em = $_POST['em'];
		$ed = 28;
		$ey = $_POST['ey'];

		$tn = $_POST['termname'];
		if(strlen($tn) < 1)
		{
			echo "<p>Term name not valid</p>";
		}
		else
		{
			if($ey < $sy)
			{
				echo "<p>End date must be greater than start date</p>";
			}
			else if($sy == $ey && $em <= $sm)
			{
				echo "<p>End date must be greater than start date</p>";
			}
			else
			{
				$query = "INSERT INTO term (StartDate,EndDate,TermName,Status) VALUES (";
				$query .= "'$sy-$sm-$sd 00:00:00', '$ey-$em-$ed 00:00:00', '$tn', '')";
	//			echo "<p>Query: $query</p>";
				$result = mysql_query($query);
				if($result)
				{
					$count = mysql_affected_rows();
	//				echo "<p>Count = $count</p>";
					if($count == 1)
						echo "<h3>Term added successfully</h3>";
				}
				else
				{
					$msg = mysql_error();
					echo "<p>Error: $msg</p>";
				}
				echo "<hr>"; 
			}
		}
		include 'library/closedb.php';
	}
?>

<form method="POST" action="Admin.php?page=AddTerm">
<table>
  <tr>
    <td>
      Term name:
    </td>
    <td>
      <input name="termname" type="text" id="termname" />
    </td>
  </tr>
  <tr>
    <td>
      Start date: 
    </td>
    <td>
      <select name="sm" id="sm" size="1">
        <option value="1">January</option>
        <option value="2">February</option>
        <option value="3">March</option>
        <option value="4">April</option>
        <option value="5">May</option>
        <option value="6">June</option>
        <option value="7">July</option>
        <option value="8">August</option>
        <option value="9">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
      </select>
    </td>
    <td>
      <select name="sy" id="sy" size="1">
        <option value="2008">2008</option>
        <option value="2009">2009</option>
        <option value="2010">2010</option>
        <option value="2011">2011</option>
        <option value="2012">2012</option>
        <option value="2013">2013</option>
        <option value="2014">2014</option>
        <option value="2015">2015</option>
        <option value="2016">2016</option>
        <option value="2017">2017</option>
		<option value="2018">2018</option>
		<option value="2019">2019</option>
		<option value="2020">2020</option>
		<option value="2021">2021</option>
		<option value="2022">2022</option>
		<option value="2023">2023</option>
		<option value="2024">2024</option>
		<option value="2025">2025</option>
		<option value="2026">2026</option>
		<option value="2027">2027</option>
	  </select>
    </td>
  </tr>
  <tr>
    <td>
      End date: 
    </td>
    <td>
      <select name="em" id="em" size="1">
        <option value="1">January</option>
        <option value="2">February</option>
        <option value="3">March</option>
        <option value="4">April</option>
        <option value="5">May</option>
        <option value="6">June</option>
        <option value="7">July</option>
        <option value="8">August</option>
        <option value="9">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
	  </select>
    </td>
    <td>
      <select name="ey" id="ey" size="1">
        <option value="2008">2008</option>
        <option value="2009">2009</option>
        <option value="2010">2010</option>
        <option value="2011">2011</option>
        <option value="2012">2012</option>
        <option value="2013">2013</option>
        <option value="2014">2014</option>
        <option value="2015">2015</option>
        <option value="2016">2016</option>
        <option value="2017">2017</option>
		<option value="2018">2018</option>
		<option value="2019">2019</option>
		<option value="2020">2020</option>
		<option value="2021">2021</option>
		<option value="2022">2022</option>
		<option value="2023">2023</option>
		<option value="2024">2024</option>
		<option value="2025">2025</option>
		<option value="2026">2026</option>
		<option value="2027">2027</option>
      </select>
    </td>
  </tr>
</table>
  <input name="addterm" type="submit" id="addterm" value="Add term!" />
</form>

You would not need any of the html stuff.

The referenced files are:
config.php:

<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'pub';
$dbpass = 'maddave';
$dbname = 'beer';
?>

You’d obviously substitute your own server name, user name, password, and data base name.

opendb.php:

<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname);
?>

closedb.php:

<?php
// an example of closedb.php
// it does nothing but closing
// a mysql database connection

mysql_close($conn);
?>

The functions.php file really isn’t required. I just routinely included it, so that some functions I use all the time are available, if I need them - things like checkLogin() which makes sure that the user has logged in with valid credentials, a routine to write the _POST variables to a file, one to write the _GET variables to a file, one to write the _SESSION variables to a file, etc.