Monday , 25 September 2023
Breaking News
Home > Tutorials > Arduino Tutorials > How to read data from database with PHP for WeMos EPS8266

How to read data from database with PHP for WeMos EPS8266


Dear friends today we will learn more interesting thing. We are going to pull out data from Database using PHP for WeMos. It is very important step for creating project for accessing devices status online.


Let’s suppose you are going to design a project that have several electronics instruments and you need a web based software that will set the status of each instrument ON or OFF and then from database you pull data and get status of each instrument and then perform action on each instrument based on pulled data with WeMos of Arduino.


Here is the solution.

You need a Server, Database and some PHP code that will do the magic. First design a database and then write code in PHP and then from WeMos send GET request to server, it will send you status of instrument and you just do something in WeMos.

For simplicity I will work on only two records. Let’s suppose I have installed two lights, one in my Guest Room and second in my Office for this database will be like this:

Now you have database and now you need PHP code to handle the request. Copy and paste below code and save as get_status.php into server. Here is PHP code:-

Code is very simple you just receive GET request from anywhere and then look value into database based on request and then simple echo status. On the other hand, in WeMos, you send the request to get_status.php with a parameter and then receive reply from server and store it into variable and then perform action based on that reply.

Now lets see what happened in WeMos. First see the code:-

As you can see I wrote a function for getting status of device and then in loop I called the function and provide parameters. The purpose of the function is that, you do not need to write complete code for every device, just call function in loop and then set parameters.

Now start the server and upload the code to WeMos and open Serial Monitor. You will see status from database.

Now change the values from 0 to 1 or 1 to 0 in database and see the result on serial monitor.

Hope you enjoy the tutorial. Sorry for broken English.

Have a nice day and Happy Coding. See you in next tutorial.

About Muhammad Faryad

Muhammad Faryad is a professional web application developer. He has been working for 5 years in ICE786 Technologies Pvt. Ltd as a Senior Programmer and Developer. You can contact him on facebook at


  1. Thanks for the code sample.
    I wonder whether the approach will work if I move ‘WiFiServer server(80);’ into ‘get_device_status’ so the server won’t be global object any more.

  2. Ary Pradicka Sukma

    ( on php code, whats that means ?

  3. Hello,

    I was looking for a example exactly like yours, but i’m having a issue.

    the arduino IDE says “it found multiples libreries for “WifiClient.h”

    Do you know how to solve this?

  4. where php data to connect to your sql database

    is that include once ‘’ ????

  5. Hi, thank you for your tut. Sadly it does not work for me.
    Nowhere in your code I’ve to enter the SQL database name and password.

    Also, I assume I can use ”” instead of the IP adress


  6. Sir, thank you but when I tried it like this in my chrome:
    I got this error: “Error:SELECT device_status FROM devices_status WHERE device_name=’0′ LIMIT 1”
    What could be the issue? I fixed db connection and I wrote it by my self 🙂
    but couldn’t get right result?

Leave a Reply

Ad Test

%d bloggers like this: