Example Script to Store Arduino Data




(Launch php processing)
require_once ("../../*******/SQL_init.php");
// $table1 = 'ImportMeterDay';
// $table2 = 'ImportMeterNight';
// $table3 = 'ExportMeter';
// $table4 = 'Costings';
// $Host, $DataBasename and $Link all now have values set by the included script

(Stop php processing)

(Usual html page header and start of body section)

// This script will (eventually) be called with command of form :-
//http://www.khormaksarschool.org.uk/******/****inp.php?ArdInp=12345A
// directly from an Arduino microprocessor
// the variable 'ArdInp' will be processed within this script to show which meter it refers
// then added - along with time of receipt - to the appropriate dataBase field
// Different script(s) will extract data from dataBase to display useful info about the meter results.

(re-Launch php processing)
// Pick up Arduino string from calling url
$ArdInp = $_GET['ArdInp'];

// check class of received data (only A to start with but there will be others later)

$OrigLength = strlen($ArdInp);
$Class = substr($ArdInp,$OrigLength-1, 1);
$Flashes = substr($ArdInp,0,$OrigLength-1);

$E7testH = date("H");
$E7testM = date("i");
$E7testS = date("s");
$ReportTime = date(" Y-m-d H:i:s");

if ($E7testH >=1 and $E7testH <8) {
$FileTable = $table2;
} else {
$FileTable = $table1;
}
$SecsSinceMN = $E7testH*3600 + $E7testM*60 + $E7testS ;


$Query="SELECT * FROM $FileTable WHERE (Serial >= 1 ) ";
$Result = mysql_db_query($DataBasename, $Query, $Link);
mysql_close();

// references to serial removed from next line. It will auto-increment.
$Query = "INSERT INTO $FileTable (DateAndTime, SecsSinceMN, Flashes) VALUES ('$ReportTime', '$SecsSinceMN', '$Flashes')";
$Result = mysql_query ($Query, $Link);

mysql_close ($Link); // disconnect from DB

(Stop php processing)
(usual html end of file markers)