Skip to content

Latest commit

 

History

History
90 lines (78 loc) · 3.62 KB

README.md

File metadata and controls

90 lines (78 loc) · 3.62 KB

POST-Arduino-Data-Wireless

In less than 60 minutes, this repo will give you the ability to record data on the Arduino, wirelessly send (POST) and store that data into a MySQL database, and then retrieve and display that data in the browser.

Items You'll Need

Arduino (Uno or similar)
Arduino WiFi Shield
USB cable for Arduino

Getting Started

Setup MySQL Database

  1. Create MySQL Database (I used my web hosts GUI)
  2. Create MySQL User
  3. Give newly created MySQL User access to your newly created MySQL Database
  4. Give newly created MySQL User full privileges to your newly created MySQL Database
  5. Create a table for your database (I used my web hosts phpMyAdmin GUI)
  6. Add 2 columns to your table: yourdata, timestamp
  7. For timestamp column, change the type to DATETIME and the index to PRIMARY

Edit INSERT script

  1. Download insert_mysql.php
  2. Edit the $username, $password, $database, and $tablename to match your setup
$username = "test_user";
$password = "test_password";
$database = "test_db_name_here";
$tablename = "test_table_name_here";
$localhost = "localhost";
  1. Upload insert_mysql.php to your web host (remember this URL for later)

POST Arduino data to MySQL Database

  1. Download arduino_post/arduino_post.ino
  2. Edit yournetwork (wireless network name) and yourpassword (wireless password) to connect to your router
char ssid[] = "yournetwork";  // wireless network name
char password[] = "yourpassword"; // wireless password
  1. Edit www.yourdomain.com (for char server[]) to the domain you are hosting insert_mysql.php (not the full path to the file)
char server[] = "www.yourdomain.com"; // This could also be 192.168.1.18/~me if you are running a server on your computer on a local network.
  1. Edit the POST url to match the path to insert_mysql.php
client.println("POST /insert_mysql.php HTTP/1.1");
  1. Edit www.yourdomain.com for ("Host: www.yourdomain.com"); to the domain you are hosting insert_mysql.php (not the full path to the file)
  2. Connect the Arduino WiFi shield to your Arduino
  3. Connect your Arduino to your computer using your USB cable
  4. Upload your sketch to your Arduino
  5. You should now be POSTing data from your Arduino to your MySQL database. Yippee!

Edit DISPLAY script

  1. Download display_mysql.php
  2. Edit the $db_user, $db_pwd, $database, and $table to match your setup
$db_user = 'yourdbuser';
$db_pwd = 'yourpassword';
$database = 'yourdatabase';
$table = 'yourtable';
  1. Upload display_mysql.php to your web-host (remember this URL for later)
  2. You should now be able to view your database in the browser

Enhancements

POST multiple data points into database
Update Strings in arduino_post

Credits

Dhaval Karwa
Ben Salinas
Tom Igoe's WiFiWebClientRepeating sketch
Display MySQL Tutorial
1% to me.