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.
Arduino (Uno or similar)
Arduino WiFi Shield
USB cable for Arduino
- Create MySQL Database (I used my web hosts GUI)
- Create MySQL User
- Give newly created MySQL User access to your newly created MySQL Database
- Give newly created MySQL User full privileges to your newly created MySQL Database
- Create a table for your database (I used my web hosts phpMyAdmin GUI)
- Add 2 columns to your table:
yourdata
,timestamp
- For timestamp column, change the
type
toDATETIME
and theindex
toPRIMARY
- Download
insert_mysql.php
- 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";
- Upload
insert_mysql.php
to your web host (remember this URL for later)
- Download arduino_post/arduino_post.ino
- Edit
yournetwork
(wireless network name) andyourpassword
(wireless password) to connect to your router
char ssid[] = "yournetwork"; // wireless network name
char password[] = "yourpassword"; // wireless password
- Edit
www.yourdomain.com
(forchar 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.
- Edit the POST url to match the path to
insert_mysql.php
client.println("POST /insert_mysql.php HTTP/1.1");
- Edit
www.yourdomain.com
for("Host: www.yourdomain.com");
to the domain you are hostinginsert_mysql.php
(not the full path to the file) - Connect the Arduino WiFi shield to your Arduino
- Connect your Arduino to your computer using your USB cable
- Upload your sketch to your Arduino
- You should now be POSTing data from your Arduino to your MySQL database. Yippee!
- Download
display_mysql.php
- Edit the
$db_user
,$db_pwd
,$database
, and$table
to match your setup
$db_user = 'yourdbuser';
$db_pwd = 'yourpassword';
$database = 'yourdatabase';
$table = 'yourtable';
- Upload
display_mysql.php
to your web-host (remember this URL for later) - You should now be able to view your database in the browser
POST multiple data points into database
Update Strings in arduino_post
Dhaval Karwa
Ben Salinas
Tom Igoe's WiFiWebClientRepeating sketch
Display MySQL Tutorial
1% to me.