How to save sensor output from ESP8266 to MySQL Database (Part 1 – ESP8266 as a Microcontroller)

Today we’re going to learn how to connect ESP8266 to website that store the inputs to MySQL.

To help you, I have created the example website here. This tutorial focuses on storing the sensor output to website, while providing the website that already works. Next part would be building the website itself.

This tutorial uses ESP8266 as a microcontroller, for example NodeMCU and Wemos D1.

Wemos D1
NodeMCU

Code example on PasteBin.

  • Example above are modification of examples “Blink” in Arduino IDE. It will report to website when the LED is on and off every 1 second.
  • Make sure you also copy the include part if you’re going to use part of this program somewhere else.
  • Remember to change the SSID and Password to your wifi settings.
  • If you’re already connected, serial monitor will report your IP.
  • Notice the inputweb() function.
    • Usage : inputweb(identifier,sensor1,sensor2,sensor3,sensor4,sensor5,sensor6,char1,char2,char3)
    • identifier can be used to identify our input. This is public web, so think about something unique.
    • On the page ESP8266 Project Test, you can search your identifier using the search box above.
    • http://project.rinaldo.id/esp8266/input.php? can be replaced later. But we’re not going to build the website now. This tutorial focuses on building the microcontroller that sends output successfully to the website.
    • We’re using GET method to input to the website.
    • sensor1 to sensor6 receives input in decimal format. If you’re not going to use it, just replace it with zero, and the char part using empty quotes. Example : : inputweb("rinaldo.id",analogRead(A0),0,0,0,0,0,"","","");
    • this function can be used in other program, receiving proper variables. That’s why we’re making it into function.
Share Button

By Rinaldo Jonathan

Admin of this site. Artis papan PCB. #zoneRinaldo #Controllerism Studio Demon, Stage Angel, Sleepy Developer, Smoke free. Kalkud SHS 2012, PCR G15.

2 comments

Leave a Reply

Verified by ExactMetrics