ESP8266 with a MySQL database

UPDATE: Please see this post for more information and links to code!

If you been following my blog since the beginning, you should remember a tour of some of the websites I’ve built in the past. The last websites I built back then involved PHP and MySQL databases and, even though it’s been such a long time, it certainly helped with this next experiment I did with the ESP8266 module.

tableI now have the ESP8266 module accessing a URL that contains the sensor information. Some PHP code grabs the information from the URL and inserts it into a table on a MySQL database. Check out the code on GitHub. Soon, I’ll have it sending data to both the database and Thing Speak, as it’s currently only sending data to the database.

You can view the live demo at

Once I finish up with the code, it’ll be time to put it into an enclosure… though I’m still waiting for a switch for the LCD backlight…

Thanks for reading!

9 thoughts on “ESP8266 with a MySQL database

  1. Hi, I’m glad to see ur amazing project. I have a question about ur project, when I looked up the php files, I have a problem to insert a value in the coloumn of MySQL database from ur php file, can u tell me the way to create the database ? Thanks


    • I don’t normally create MySQL database tables with code. I make the structures of my databases and tables in phpMyAdmin. If you look through my code, you’ll be able to identify the names I used: date, time temp, hum, and lum. These are either text or float values in the table’s structure (the table is called data).

      I hope this can help you to get it working for your project. Good luck!


  2. Hi, first sorry for my english, but is a very nice project!
    Is possible to have more information about the Hardware for temps sensor and wifi connection?
    Thanks a lot!


  3. I’m using localhost and getting problem in “connecting to host” , how do you write in YOUR_HOST in this :
    const char* host = “YOUR_HOST”;
    when using xampp ??? thanks


  4. (my host)

    boolean thingSpeakWrite(float value1, float value2,float value3)
    String str = “AT+CIPSTART=\”TCP\”,\””;
    str += HOST;
    str += “\”,80″;
    errortype = 1; // Sets appropriate error message.
    errorcount = 1; // Increase error counter.
    Serial.println(“Unsuccessful attemt”);
    Serial.println(“Server hitting successful”);
    // Send data.
    str = “GET /add.php?”;
    str += “temp=”;
    str += value1;
    str += “&humid=”;
    str += value2;
    str += “&light=”;
    str += value3;
    str += ” HTTP/1.1\r\nHost: “;
    //str += ” HTTP/1.1\r\n”;
    str += HOST;
    //str += “\r\n\r\n\r\n”;
    //Serial.println(“Webhost Send”);

    The code isn’t uploading value to my page but works perfectly fine for Thingspeak. Please help


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s