Example 1 - Server Requests Data From ESP8266
This example is favorable if you have a mains powered ESP8266 module and want to drive everything from a remote server, e.g. Linux PC or Raspberry Pi.
Here is the Flowcode project for reference.
First of all I installed easyPHP on my windows laptop.
Eventually I'll just install Apache, PHP and MySQL on my Linux server but for now I use my Windows laptop to do everything.
Once EasyPHP is installed and running you go to the following URL to access the server config.
http://localhost/home/index.php
Open the MySql Admin and create a new database, I named mine ESP8266.
I then created the following php files, you will need to extract the zip archive into the "C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb" folder or the server root folder if simply using Apache.
You can then access the site using the following URL.
http://localhost/ESP8266
- PageRequest.jpg (61.78 KiB) Viewed 14476 times
Details of the files are shown below.
index.php - main page with various includes, this is our portal into the site and the page we will use to view everything.
links.php - some html links between pages - shown at top and bottom of index
dbopen.php & dbclose.php - Some DB management - open and close the DB
InitTables.php - Initialise and clean the tables
ReqData.php - Requests data from the ESP8266 and adds to MySQL DB
ShowData.php - Shows the contents of the MySQL DB
Please note my PHP code is very quickly bashed out, you would ideally have a lot more error checking and data parsing to accommodate things like the URL not loading etc. Also as i'm on a private server I use root with no password to access the DB. Of course do not do this if your allowing inbound communications from the web.
On the linux server I would do a page request using a Cron task to setup an automated regular poll of the ESP8266 module and it's sensors.
Page request URL from Cron task.
http://localhost/ESP8266/index.php?p=ReqData
Example 2 - ESP8266 Posts Data to Server
This example is better suited to when you need to be able to power down the ESP8266 module to save power for example when running from a battery. This time when the ESP8266 module is powered on it makes a request to a remote HTTP server on the network.
Example Flowcode project.
This has an additional PHP file, PutData.php which collects the page request from the ESP8266 and stores the URL parameters in the DB.
In the Apache configuration file look for this line.
Listen 127.0.0.1:80
And change to this to accept incoming connections from all IPs on the network.
Listen 80
You may also have to open the incoming TCP port 80 on the windows firewall.
Displaying the data
Once you have the data in MySql you can then use a PHP library to give you some nice charts and tables.
This looks like a nice library.
http://www.fusioncharts.com/php-charts/