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

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

Introduction:

In this tutorial, we will be Creating your own IoT Cloud from scratch using php, Mysql, ESP12E. This is part 4 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 4 of "Creating your own IoT Cloud from scratch using php, Mysql, ESP12E", we will be controlling three led connected to our esp12e or nodemcu module through an HTML webpage. We will be scripting in javascript and also we will be using css for our HTML page. In the part 2 of tutorial, we have already created the api's to control led. We are not going to consume those api's to control our esp12e or nodemcu module.

Circuit Diagram and Breadboard Image

So start of by making the circuit on the breadboard. Refer the below image for reference.

 

Video

Now watch the below video. I have given step by step instructions in the video:

Code

PHP Api Code

Copy the below code and replace it in the "read_all.php" file which we created on our webhost server.

Arduino Code

Copy the below arduino code and program your esp12e or nodemcu with it. Make sure that you replace the wifi username, password and the webhost url.

 

HTML Code

Copy the below code and paste it in a notepad++ file, and save it as 'index.html'. Make sure that you have replaced webhost url in the code.

Support me 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 3 (Prev Lesson)
Back to Creating your own IoT Cloud from scratch using php, Mysql, ESP12E

Comments ( 69 )

  • Ovan

    Hi, your tutorial is great and detailed. I have perfectly done it. And i have a question. Can the weather and led Arduino code combine together to become one and send to the ESP-12E to work it?

    • Offcourse you can do it.

  • Md Nirob

    Please extend this tutorial about showing JSON data in chart format. Pls…..

    • I am planning to. But watch my latest video. I am also introducing machine learning.

  • Amirul

    hi, thank you for your great tutorial, its really helpful ! i have a request, can you please make a similar tutorial for iot attendance system using rfid?

    • I think I responded on my youtube channel. 🙂

  • Hakan Tutkun

    Hi ! Firstly, thanks for great tutorials. I got this error while I was trying,

    “parseObject() failed”

    What can cause this error ?

      • Mats

        I have the same error, tried installing the library again multiple times but didn’t work. In de Arduino IDE becomes orange but does not become orange. Not sure why.. do you have a solution?

        • Hi Mats,
          Can you uninstall arduino and install again the fresh version?

  • Alenth

    hi, your tutorial was helpful..but i got a problem while parsing string and showed the message

    parseObject() failed

    can you help me please?

      • Edwin Abraham Thomas

        I am having the same issue please help me
        The api is workind with posan

        • Edwin Abraham Thomas

          Sorry,
          I meant that the api was working on postman

          • Please check the arduino code again then.

        • Please check the arduino code again then.

  • Deni sugiarto

    hi i get problem. r u can help me? i run webserver locally with MYSQL version Server version: 5.5.39.
    This is result from serial monitor:

    Connecting to Wifi Warga
    ………….
    WiFi connected
    IP address:
    192.168.1.111
    Netmask: 255.255.255.0
    Gateway: 192.168.1.1
    connecting to 192.168.1.102
    Here1
    Requesting URL: /api/led/read_all.php?id=1

    closing connection
    connecting to 192.168.1.102
    Here2
    Requesting URL: /api/led/read_all.php?id=2

    closing connection
    connecting to 192.168.1.102
    Here3
    Requesting URL: /api/led/read_all.php?id=3

    closing connection
    connecting to 192.168.1.102
    Requesting URL: /api/led/read_all.php?id=3

    closing connection.

    led nothing happen when value is on.

  • Satyam singh

    Hello sir, is it possible to show Hardware (NodeMcu) online/offline status when client drop their internet connection or shutdown?

    • Yes, You have to write a server code probably in nodejs which will continuously check the last updated data. Let’s say if your device has not send data or not done any handshake for lets say 1 minute, then you can show the status as offline.

  • Mark

    Hi.. i got a problem.when iam pressing the button from my webpage it was updating on my database,tried with postman tool also but..my led is not responding accordingly.please provide some suggestion sir.

    • Please check your arduino code. If it is updating the database on button press, then the server code is working fine.

  • Shashank Sekhar

    I need a better understanding of how to take data in a database from a localhost server to the NodeMcu board.Can you please help me out? Please add your E-mail so that I can explain to you my problem in details.

    • Sorry Shashank, This is custom project, and I don’t do custom requests until there are lot of request for same topic. Hope you understand. Happy learning 🙂

  • Ravi

    Your video is super and I am inspired and have come with an idea Could you do a custom project for me

    • Thanks Ravi. I am glad that my tutorials are useful for you. Please read the “terms of use” http://iotmonk.com/terms-of-use/ of this website. I cannot do custom request or custom projects until there are lot of requests coming for same project.

  • Ravi

    Your video is super and I am inspired by your teaching and have come with an idea Could you do a custom project for me

    • Thanks Ravi. I am glad that my tutorials are useful for you. Please read the “terms of use” http://iotmonk.com/terms-of-use/ of this website. I cannot do custom request or custom projects until there are lot of requests coming for same project.

  • SickWorm

    Thanks fot tutorial is wery useful. But im interest how to put files in api folder behind protected folder with username and pass… To get more protection of data information?

  • Shashank Shankar

    hello vivek thank you so much for the guide
    i am using Xampp control panel to host the phpmyadmin and i was successfully able to write a phpcode to send data from my NodeMCU to mysql database. now i need your help to do the reverse process i.e, reading data from mysql table to esp8266
    can you help me please

    • Hi Shashank, I am glad that my tutorials are helping you out. The read process is also given in the tutorial. Please check again.

  • Hi, I have a problem
    Here1
    Requesting URL: /api/led/read_all.php?id=1
    parseObject() failed
    connecting to http://www.alterno.cl
    Here2
    Requesting URL: /api/led/read_all.php?id=2
    parseObject() failed
    connecting to http://www.alterno.cl
    Here3
    Requesting URL: /api/led/read_all.php?id=3
    parseObject() failed

    its tell me parseObject() failed, I checked the api and i dont know the problem, can u upload again the arduino code, maybe you upload a wrong arduino code, because i can change by the html in my host but its not working the arduino.

    thanks.

    • Did you check the api through postman first?

  • Faye

    what is the diference between MYSQL and Json in your program.thank

    • MYSQL is the database and JSON is the format in which we represent database so that it is easier for our applications to consume the data.

  • Moaad

    hi vivek
    I have problem in adruino code the esp8266 isn’t connected with server ,connecting failed
    and I tested all the php script with postman all the request passed successfully .what can I do to resolve this probleme?

    • What is the response of the postman?

  • Faye

    Thanks Sir for this tutorial. I have a problem that the ESP8266 module can’t connect to server.

    • did you test the api in postman?

  • Niraj

    Does it work for ESP 32?
    I am getting error with parseObject() failed on serial monitor.

    • Yes, you may have to modify the code a bit. ALso did you check the api in postman?

  • Jaejoong song

    You are the best. Really best.
    IoT is a Big Forest.
    There are many programming trees.
    I tried many trees for months.
    If I read books about the trees
    ( php, mySQL, client, server, c#, js, android studio,
    IoT platform, Web service….wow it is confusing)

    With your really small, but including all example code ,
    I could understand the Big Forest easilly.
    Now, I can go faster to the forest, and expand my application.

    I am a controller designer with MICOM in south Korea,
    and windows programer, and studied Android Studio recently.
    And I have big problem upgrading User Interface on my controller.
    LCD spec changes fast, and I should maintain stock,
    cannot buy small amount, …. I had to use HMI.
    I didn’t think much about the need of IoT
    till several months ago.

    After understanding IoT,
    I found that all phones and PC will work as UI .
    So I will remove most of UIs from my controller.

    Thank you so much. You reduced me months.
    In Fact, Yesterday Night I went to a big Book store to search a book which explanes IoT like you. But failed.
    All IoT platform code in the WEB search
    is too big to understand,
    or for their commercial advertisement,
    or cloudless (database less) IoT.
    I have a home http://www.jaejoong.co.kr
    I will say thank you again.

    • Thank you for you kind words..! I am moved by it.

    • Thank you so much…! I appreciate your kind words. Also please check your email.

  • NK

    I hve an error parseObject() failed
    in IOT LED project that you been teach ,but an error

    • Can you try that with postman and send the screenshot somewhere?

  • NK

    yes I did and shows no error
    I have same problem
    parseObject() failed

    • Can you try that with postman and send the screenshot somewhere?

  • Jun

    Congratatulations Sir vivek! you have very nice tutorial which can help us in making some projects in nodemcu. I hope you can help me in my project, which would deal with real time and database. I would like to turn on and off my appliances in specified time using php and save in the database the consumed current or energy. please help me…

  • Mandola

    Dear vivek
    thank you for this great tutorial
    I have a question can I use ESP8266 v-01 instead of v-12 to accomplish this tutorial ?
    another question can I make esp8266 to connect to wifi through 192.168.4.1 IP by using wifi manager with this tutorial codes ?
    I don`t want to make hard code to connect esp to wifi !
    I want to make a project that anyone can connect to its wifi and used it to make smart light or smart switch ?
    thank you in advance

    • You cannot learn anything without getting intimidated. 🙂 . Be persistent you will be able to learn it. Now answering technical question:
      I have a question can I use ESP8266 v-01 instead of v-12 to accomplish this tutorial ?
      yes
      another question can I make esp8266 to connect to wifi through 192.168.4.1 IP by using wifi manager with this tutorial codes ?
      yes
      I don`t want to make hard code to connect esp to wifi !
      You can start wifi in AP mode and then configure the credentials using the URL. And then start that in client mode.
      I want to make a project that anyone can connect to its wifi and used it to make smart light or smart switch ?
      Yes you can definitely make it. See “sonoff switch”.

  • PRANJAL BHAGAT

    C:\Users\bhaga\Desktop\sketch_oct04a\sketch_oct04a.ino: In function ‘void loop()’:

    sketch_oct04a:95:7: error: ‘StaticJsonBuffer’ was not declared in this scope

    StaticJsonBuffer jsonBuffer;

    ^

    sketch_oct04a:95:29: error: ‘jsonBuffer’ was not declared in this scope

    StaticJsonBuffer jsonBuffer;

    ^

    sketch_oct04a:98:12: error: ‘json_parsed’ was not declared in this scope

    if (!json_parsed.success())

    ^

    sketch_oct04a:103:20: error: ‘json_parsed’ was not declared in this scope

    String led = json_parsed[“led”][0][“status”];

    ^

    C:\Users\bhaga\Desktop\sketch_oct04a\sketch_oct04a.ino: At global scope:

    sketch_oct04a:145:3: error: ‘Serial’ does not name a type

    Serial.println();

    ^

    sketch_oct04a:146:3: error: ‘Serial’ does not name a type

    Serial.println(“closing connection”);

    ^

    sketch_oct04a:147:8: error: expected constructor, destructor, or type conversion before ‘(‘ token

    delay(3000);

    ^

    sketch_oct04a:148:1: error: expected declaration before ‘}’ token

    }

    ^

    exit status 1
    ‘StaticJsonBuffer’ was not declared in this scope

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    this is my problem with arduino code. please tell me the solution sir.

    • Please check the video again, and add the library properly in your Arduino IDE.

  • Arduino: 1.8.6 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    Build options changed, rebuilding all
    F:\esp8266-01\api\espLED\espLED.ino: In function ‘void loop()’:

    espLED:100:7: error: ‘StaticJsonBuffer’ was not declared in this scope

    StaticJsonBuffer jsonBuffer;

    ^

    espLED:100:29: error: ‘jsonBuffer’ was not declared in this scope

    StaticJsonBuffer jsonBuffer;

    ^

    espLED:102:24: error: ‘class ArduinoJson::JsonObject’ has no member named ‘success’

    if (!json_parsed.success())

    ^

    exit status 1
    ‘StaticJsonBuffer’ was not declared in this scope

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    this is my problem. please help me

    • problem was solved. i installed latest library which is beta version. after i change to stable version its running .
      thank you so much for such great tutorial with documentation.

    • Please check the video again, and add the library properly in your Arduino IDE.

  • Rohit

    ‘StaticJsonBuffer’ was not declared in this scope

    i am getting this error,can u please guide me ?TIA.

    • Please check the video again, and add the library properly in your Arduino IDE.

  • Abu1Omar1

    Thanks a lot Bhi,

    I have doubt. in large quantity of esp’s in the network, and also full of data packets transmission, speed of WiFi, etc.. Does the response time will get delayed by time. If yes then how to avoid that?

    Thanks again.

    • You use scalable cloud server such as aws. Then you use multiple security levels for data manipulation. Then you use distributed database for storing such kind of data. And in the case where there is requirement of realtime data you use mqtt or socket for data transfer.

  • Rakib

    Arduino: 1.8.5 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, 4M (3M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    C:\Users\Lenovo\AppData\Local\Temp\arduino_modified_sketch_955983\cc.ino: In function ‘void loop()’:

    cc:99: error: ‘StaticJsonBuffer’ was not declared in this scope

    StaticJsonBuffer jsonBuffer;

    ^

    cc:99: error: ‘jsonBuffer’ was not declared in this scope

    StaticJsonBuffer jsonBuffer;

    ^

    cc:101: error: ‘class ArduinoJson650_0_0::JsonObject’ has no member named ‘success’

    if (!json_parsed.success())

    ^

    exit status 1
    ‘StaticJsonBuffer’ was not declared in this scope

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    How to solve this problem ?

    • C’mon Man. You have to import the library. Its already mentioned in the video.

  • Renaud Montes

    Beautiful, thank you very much for sharing your knowledge Vivek, keep up the great work, outstanding material to get started in the fabulous IoT world!

    • Thank you so much for your kind words 🙂

  • Hicham

    Hi, does you arduino software loop for ever and connect and disconect to webside and get date even if you are not sending any command from the website?

    Thanks for your answer inadvace.
    Regards,
    Hicham

    • Hi Hicham, the date data is being taken care of php api. You can offcourse modify nodemcu to take data from the RTC.

Post a Reply