Introduction: Arduino, Temp, Humidity, WiFi, MySQL and Highcharts

Picture of Arduino, Temp, Humidity, WiFi, MySQL and Highcharts

This is my first Instructable and while it works as is, it is a prototype/proof of concept only.

This solution is one of a number that are required to monitor an indoor pool installation to allow an engineer to offer suggestions as to how we can save on our energy usage. The overall project is being undertaken by a Year 11 Design and Technology class.

Please note the solution is a remix of other builds and ideas.

Specifically, Tim Kang (http://blueflame-software.com/blog/how-to-load-mysql-results-to-highcharts-using-json/) and Marco Schwartz (https://learn.adafruit.com/wifi-weather-station-arduino-cc3000)

If you just want to fiddle with the database and highcharts, go straight to Step 3.

If you just want to build the sensor, Steps 1 and 2

*********

What I used:

1 Arduino UNO

(1 CC3000 WiFi breakout (http://www.adafruit.com/product/1510) and 1 Arduino prototype board

or

1 CC3000 WiFi shield with ufl connector for ext antenna (http://www.adafruit.com/products/1534))

1 antenna - I used https://www.adafruit.com/products/945

1 adapter - I used https://www.adafruit.com/products/852

1 SHT15 Temp, Humidity sensor - I used https://www.adafruit.com/search?q=sht15

1 case - I used https://www.adafruit.com/products/337

rainbow cable, solder and iron, hotglue gun, stacker and break away pins

Wireless compatible computer

Arduino software

MAMP software (WAMP or LAMP depending on your OS of choice)

a text editor - TextWrangler is an excellent choice for the mac

Browser of your choice.

Step 1: Building the Sensor

Picture of Building the Sensor

Mount the Arduino UNO in the case.

Solder the CC3000 WiFi breakout onto the prototype board (note that I had to shorten the break away pins as the whole unit needs to be able to fit into the case)

Mount the sensor into or onto the case (I used hot glue and have mounted the sensor so that it is less likely to become too wet in the indoor pool environment - time will tell if this is the best orientation but it will be easy to remount if required. The SHT15 has a heater element so I guess if the humidity readings are affected by condensation, I should be able to dry the sensor out.)

Mount the antenna (I used an internal tooth lock washer on the underside of the antenna mount to stop the user from turning the fitting when screwing the antenna onto the mount - this is not in the photo)

If you used the adafruit case, break off the covers, clean them up with a utility knife and pop them into position - I hot glued them for greater security.

Step 2: Download the Sketch

download the sketch:

SHT15_CC3000_MySQL.zip

Open in the Arduino IDE, fill in your own information for the wifi and web server.

Upload the sketch to your arduino, open the serial browser, set it to 115200 baud and watch your solution generate the temp and humidity.

Step 3: Download and Install MAMP

download and install MAMP:

https://www.mamp.info/en/

WARNING - MAMP 3, non PRO version, ships with the ability to switch between PHP 5.1.6 and 5.5.10 only.

Neither of these work with highcharts. I selected 5.1.6 via the preferences pane then renamed the 5.3.28 folder to 5.1.6 - this is a kludge and I need to find a better solution.

Locate the htdocs folder in Applications, MAMP.

download and copy the sht15_cc3000_mysql folder into the htdocs folder.

Step 4: Create Your MySQL Database

Picture of Create Your MySQL Database

Open a terminal window and copy this text at the prompt:

/Applications/MAMP/Library/bin/mysql -uroot -p <

Now, drag the energy_project.sql file (see the photo above) located in the sht15_cc3000_mysql folder in htdocs over the terminal window - this will paste the path (location) of the energy_project.sql file into the terminal window after the <

Now press return and type root at the password prompt.

Press return and you have created your database.

Step 5: Create the Energy_user for Your Database

In a terminal window, copy this text at the prompt:

/Applications/MAMP/Library/bin/mysql energy_project -uroot -p

Now press return and type root at the password prompt.

copy this text at the prompt and replace the your_password with a password of your choice:

GRANT all ON energy_project.* TO energy_user@localhost IDENTIFIED BY 'your_password';

Press return and you have created a database user called energy_user

type exit at the prompt.

Step 6: Edit the Sensor.php File

edit the sensor.php file in the sht15_cc3000_mysql folder in htdocs.

This is the file that is called by your wifi sensor and it places the temp and humidity data into the database.

You have to set the following line so that the password you have specified for the energy_user is the same:

$result = mysql_connect("localhost", "energy_user", "your_password");

Step 7: Edit the Data.php File

edit the data.php file in the sht15_cc3000_mysql folder in htdocs.

This is the file organises the data in the database into a format that highcharts can understand.

You have to set the following line so that the password you have specified for the energy_user is the same:

$con = mysql_connect("localhost","energy_user", "your_password");

Step 8: Check Out Your Handywork!

Picture of Check Out Your Handywork!

If you have created the database correctly and adjusted your_password, you should now be able to test data.php

Make sure that MAMP has been launched

In the browser of your choice on the machine running MAMP, paste in the following URL:

http://localhost:8888/sht15_cc3000_mysql/data.php

You should see my test data.

Now point your browser to:

Point your browser to the following URL:

http://localhost:8888/sht15_cc3000_mysql/

Please remember this is a work in progress - it was strung together to allow my year 11 class to meet their next milestone.

Comments

RealSenthu (author)2016-06-22

I got following message in arduino serial interface

mysql_native_password ˇñ 08s01got packets out of order

timscott22 (author)RealSenthu2016-06-22

Hi RealSenthu

I just googled your problem.

Check the advice here:

https://community.bitnami.com/t/unable-to-view-php...

Regards

Tim

RealSenthu (author)RealSenthu2016-06-22

what's the reason for this? can u help me anyone?

ef.jee1 (author)2015-02-17

for the operating system Windows 7 using XAMPP whether there are distinguished in its programming? please help ..

iven86 (author)ef.jee12015-12-28

Disable your firewall

timscott22 (author)ef.jee12015-02-17

Hi
I haven't tried my setup on windows using xampp but am sure that each step should be very similar.
Regards
Tim

ef.jee1 (author)timscott222015-02-19

ok, thanks...

before I use Wido-Open Source Node Arduino Compatible IOT, in the existing microcontroller CC3000 WiFi shield and I've tried to fit your program code but still can not.
I think the same as you patently above but the program code does not match ..

iven86 (author)2015-12-28

Thanx Bro it's helped me

tim.smith.9469 (author)2015-02-12

Hey Tim. Thank you very much for providing this tutorial. I'm using something like this for my thesis project. I have one issue though when I compile the code for the Arduino, no header file directory. Would you know anything further on the matter?

Arduino: 1.5.8 (Mac OS X), Board: "Arduino Uno"

SHT15_CC3000_MySQL.ino:14:19: fatal error: SHT1x.h: No such file or directory
compilation terminated.
Error compiling.

ghayth_mkh (author)2014-10-12

Thanks ,it worked with me for 5 minutes on windows OS :)

mmonteiro7 (author)2014-10-01

in step 2 you talk to download SHT15_CC3000_MySQL.zip, but where is the link to download.

Thank

timscott22 (author)mmonteiro72014-10-01

Hi

The download is immediately under step 2.

Regards

Tim

mamehdi2000 (author)2014-08-26

Hi Tim,

So I tried it again and it didn't work. I decided to put it on my hosting account. It seems like it's working, however I don't see any data that the arduino outputs. When I open the data.php on my website it shows the following:

[{"name":"time"},{"name":"Temperature"},{"name":"Humidity"}]

and when I open the root folder it shows the plot with no data. On the Arduino side, it says it's data sent and loops back, so it seems like it's working correctly. My guess is that it's not writing the data to the correct location? Any ideas?

Thank again for your help,

Mehdi

mamehdi2000 (author)2014-08-23

Hi Tim,

Thank you for your quick response. I changed everything back to your instructions and also changed it to $con = mysql_connect("localhost","root", "root");

I get an error saying" Could not connect: Unknown MySQL server host with some weird characters... I will try again tomorrow and redo all the steps just in case I'm missing a step. I will keep you posted.

My end goal is to be able to have my data (300 temp sensors) to be plotted on my website and to be able to download all the data, is this possible with this method?

Thank you so much for your help.

mamehdi2000 (author)2014-08-22

Tim, let me start by saying thank you for making this page. It's great to see it's possible to do with Arduino. I followed your instructions step by step, however when I go to test my database (step 8), the webpage is blank. If I change the localhost to "localhost:8888" on step 5 and 6, than I'll get some output, however no new data from my arduino. I noticed my SQL port is 8889 and the apache is 8888... Any help would be appriciated. Thank you.

timscott22 (author)mamehdi20002014-08-23

Dear Mehdi

the 'localhost' in steps 5 and 6 is the host setting for the mysql server. It has to stay as just localhost. The localhost:8888 is the web server localhost. Usually, web servers that are set up on local machines will be operating from port 80 - that is the default port that web traffic uses. Because we are using MAMP, so that the MAMP web server does not interfere with a web server that may be already operating on your machine, MAMP sets its web server port 8888.

If you are not getting any information using the http://localhost:8888/sht15_cc3000_mysql/data.php link, please try the following:

In data.php, change the following line:

$con = mysql_connect("localhost","energy_user", "your_password");

to

$con = mysql_connect("localhost","root", "root");

save and test again.

Let me know if this works.

Regards

Tim

timscott22 (author)2014-05-11

Steps 3 - 7 need to be completed for your external server.

Then you need to edit the sketch lines here to point to your external server and port.

******

// Local server IP, port, and repository (change with your settings !)

uint32_t ip = cc3000.IP2U32(192,168,1,103);//your computers ip address

int port = 8888;//your webserver port (8888 is the default for MAMP)

******

Regards

Tim

mortonc (author)2014-05-11

How would you go about doing this with an external server?

timscott22 (author)2014-05-05

I have just corrected the GRANT statement. The grant needed to be on the database, not the table.

About This Instructable

30,700views

57favorites

More by timscott22:Arduino, Temp, Humidity, WiFi, MySQL and Highcharts
Add instructable to: