Creating your own IoT Cloud from scratch using php, Mysql, ESP12E

Creating your own IoT Cloud from scratch using php, Mysql, ESP12E – Part 3

Introduction:

In this tutorial, we will be Creating your own IoT Cloud from scratch using php, Mysql, ESP12E. This is part 3 of tutorial series. If you are seeing this tutorial directly then I will recommend you to read the Introduction of this tutorial first.

So in part 3 of "Creating your own IoT Cloud from scratch using php, Mysql, ESP12E", we will update the DHT11 Temperature and humidity data into mysql using php apis which we created in the previous tutorial. Also, we will make an HTML webpage and using javascript and jquery, we will get the last updated data in the mysql database and show it in the HTML  webpage and also use CSS to enhance it.

We will be first wiring up our circuit on our breadboard from scratch. Keep this following circuit diagram hand and tally your breadboard circuit with the following circuit diagram on each step to avoid any mistakes.

Read-temperature-and-humidity-from-nodemcu-ESP12E-with-DHT11-and-show-it-on-HTML-webpage(Local)-circuit

Read-temperature-and-humidity-from-nodemcu-ESP12E-with-DHT11-and-show-it-on-HTML-webpage(Local)-circuit

And then wire up it on breadboard like this:

Read-temperature-and-humidity-from-nodemcu-ESP12E-with-DHT11-and-show-it-on-HTML-webpage(Local) (5)

Read-temperature-and-humidity-from-nodemcu-ESP12E-with-DHT11-and-show-it-on-HTML-webpage(Local) (5)

Video

Follow the below video step wise. The video contains full instructions along with brief explanation.

Code

Copy and paste the below Arduino code and program your esp12e or nodemcu with it. Don't forget to replace the wifi username, wifi password and host url in the below code. This part will now contain use of  php, Mysql, ESP12E and integrating them together.

 

Now Create a new folder, and download and place the below images inside the folder.

Rename the first image as "humidity" and second image as "temperature" respectively.
 
It doesn't matter where you are placing the folder. The only thing is that the above two images should be placed inside the folder carefully. And rename them as specified above.

After that simply copy and paste the below program in a code editor, and save it as "index.html". Now you have to :
1. Replace the webhost url as instructed in the video.
2. Uncomment the line of "<script src= "...."> " Depending upon where you are running this html page from local or from the hosting server.

Support me by by subscribing to my YouTube channel by hitting the below button.

youtube-iotmonk-subscribe

Please login to get access to the quiz
Creating your own IoT cloud from scratch using php, Mysql, ESP12E – Part 2.2 (Prev Lesson)
(Next Lesson) Creating your own IoT Cloud from scratch using php, Mysql, ESP12E – Part 4
Back to Creating your own IoT Cloud from scratch using php, Mysql, ESP12E

Comments ( 28 )

  • SUNRIT PAUL

    Very useful tutorial… thanks a lot…just only two quaries
    1.”what to do if I want to send floating value to the esp8266 from the database.
    2.Can I add more than one esp8266 to the database containing defarent sensening parameter value?

    • Hi Sunrit, here is the answer:
      1.”what to do if I want to send floating value to the esp8266 from the database.
      -> You need to first store the floating value in float variable in arduino code. Then you need to convert the float value in string. And then you can send it to database. Since the database in mysql is varchar or string, then it will easily store the value.
      2.Can I add more than one esp8266 to the database containing defarent sensening parameter value?
      -> Yes you can. To avoid confusion, you can create a new field in the database called device id. So if you are sending from device 1, send the device id along with the parameters.
      Hope this helps.
      Please Support me by subscribing to my youtube channel https://www.youtube.com/channel/UCduc9YE9oZlw36YmTQ6rDEQ?view_as=subscriber

      • Sunrit

        sir I want to send a floating value from the data base to the esp8266 for controlling fan speed…please help me

        • Convert float value to string and then send it on the cloud.

  • Sunrit

    please provide me a tutorial or code…if possible

    • Hi Sunrit, its in the page only. Please check other parts.

  • Pal

    Thank You So Much. Keep making more such videos. Excellent work and very helpful with my project 🙂

    • Thanks Pal, I will surely try to keep it up…!!

      • Nishanth

        sir after uploading the Arduino code in serial monitor it is showing as
        ” failed to read data from dht sensor! ”
        please help me solve this issue ASAP.

        • Your DHT sensor , arduino is not able to read from it. Check pin connections properly.

  • Nishanth

    sir after uploading the Arduino code in serial monitor it is showing as
    ” failed to read data from dht sensor! ”
    please help me solve this issue ASAP.

    • Check the connection with DHT11. Which sensor you are using? what pin have you connected to? Please check the circuit thoroughly. Its problem with your circuit.

  • Nishanth

    sir it is showing as
    exit status -1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).
    please help me with this

    • Have you selected proper board?

  • John

    Hi. I am trying to upload in the ESP8266 the above code, but it fails. It returns the following error:
    C:\Users\at\Documents\Arduino\sketch_jul07g\sketch_jul07g.ino:10:9: note: in expansion of macro ‘DHTPIN’

    DHT dht(DHTPIN, DHTTYPE);

    ^

    Using library ESP8266WiFi at version 1.0 in folder: C:\Users\at\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi
    Using library DHT_sensor_library at version 1.2.3 in folder: C:\Users\at\Documents\Arduino\libraries\DHT_sensor_library
    exit status 1
    ‘D1’ was not declared in this scope

    Any ideas on how to fix that please?

    • YOu have not declared D1 pin. Check the code again.

  • Faiz

    hi… may i get library ESP8166WIFI.h ?
    i can’t find it
    thanks a lot

    • Install the library by Sketch->Include Railway->Manage library->search library and install it.

  • Samhan

    Hello Sir,

    Thank You so much for great explanation and I’m really excited and tried this with my Arduino Pro Mini. Unfortunately, I’m getting following error when tried to compile the code:

    In file included from C:\Users\Althaffz\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFi.h:33:0,

    from C:\Users\Althaffz\Documents\Arduino\Samhan\test_3\test_3.ino:1:

    C:\Users\Althaffz\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFiType.h:26:19: fatal error: queue.h: No such file or directory

    #include

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino Pro or Pro Mini.

    Please be kind enough to assist me out.

    Many Thanks!!!!

    • Hi,
      Please select the right board from Arduino->boards->nodemcu 1.0

  • Rakesh

    brother, your tutorials were really awesome. thanks for making such tutorial videos in your leisure time. Its really helpful for me. once again thank you bro.

    • Thanks Rakesh. Thank you so much for appreciation.

  • Rakesh

    Bro, if i need to include some authentication facilities to upload data, what are the changes i need to do in that code.

    • Just use any hard coded api key or any normal username and password. In the api just check if the api which you are receiving contains username and password or not. If it matches update the data if not then don’t update.

  • Rakesh

    bro, what to do if we need to view data collected over a period of time? is it possible to store infinite data that has been captured form sensor?

    • Depends upon your database. Generally your database is “infinite”. You pay per usage.

  • Rourab

    for non http website somehow this code is not working, I have checked that from the url while I am hitting mywebsite/insert.h>temp=32&hum=76, successfully the database getting the value, but while this request is coming from nodemcu, data has not been entered. The serial output that I am getting is :
    WiFi connected
    IP address:
    192.168.43.59
    Netmask: 255.255.255.0
    Gateway: 192.168.43.1
    connecting to rourab.com
    Requesting URL: /iot/weather/insert.php?temp=32.00&hum=74.00

    closing connection
    connecting to rourab.com
    Requesting URL: /iot/weather/insert.php?temp=32.00&hum=75.00

    • did you test it with postman?

Post a Reply