I’ve been asked by a number of people to provide an example of using the EtherShield library to pass data to a PHP script, to for example store sensor data in a database.
The example here is based on existing code that reads the SHT1x temperature and humidity sensor. The results are passed as parameters to a php script running on a local linux server. The php script then saves the results in a simple text file.
The url format for this example is
The example Arduino sketch can be downloaded here
The PHP script used to test is
< ?php $p1 = $_GET['p1']; $p2 = $_GET['p2']; $p3 = $_GET['p3']; $timestamp = mktime(); //echo "Timestamp is ".date("d/m/Y H:i:s", $timestamp); $your_data = date("d/m/Y H:i:s", $timestamp) . "," . $p1 . "," . $p2 . "," . $p3 . "\n"; echo "OK"; // Open the file for appending $fp = fopen("/var/www/data.txt", "a"); // Write the data to the file fwrite($fp, $your_data); // Close the file fclose($fp); ?>
This creates a file like this: