This library provides function to begin our HTTP connection with any website and send GET/POST requests. You can go through the documentation of this library. We will be using ESP8266HTTPClient library for our task. Now it is time to program ESP such that it can send and receive messages from the server. Now click on add New file and name this file as “datastorage.txt” and create. You need to upload the file in “public_html” folder. Now click on Upload button, choose file “writefile.php” from the computer, and upload it. Click on Upload Files and it will redirect you to a new page where you will see all the files working in the backend of your website. You will see this link on your dashboard at the top. Now it is time to add these two files in File Manager of your Server. In case of False, there might be some error. IF flag is true, means Data is stored successfully. Filename, data and flag (FILE_APPEND) are arguments of this function. Now file_put_contents () is a function used to push the contents in the file. $fileContent is the variable, which appends ‘\n’ (next line) character at end of the text. Must not forget to put ‘ ’ semicolon at end of every instruction. Then GET request is added to get the text after the ‘=’ sign in the URL and that text will be saved in the variable named ‘val’. Paste the below code into the file and again save it.Ĭode started with initialization (Basic PHP code syntax). Open any text Editor and save it with name writefile.php Now PHP script to append data to file with name "writefile.php" I thought it would be very easy for anyone if we can make a custom URL that can be used to write data in the file as well read from the file.Ĭustom URL to write data in the file will be. We do not need PHP script to read data from a file. We need PHP scripts to write data to the file. In addition, this key will be used to recognize the ESP, which wants to communicate. Each ESP connected to the server will add its key while sending data to file. ESP8266 can read the data from the file as well write the data into the file. Therefore, instead of communicating directly, Server will act as an intermediate and both ESPs will communicate with Server. I have two ESP8266 and both are needed to communicate with each other. There will be a text file with name “datastorage.txt”. Next step is to create a model on our desk which we will follow while communication to Web Server. You will get Password for your domain name, do remember that also. Most importantly, create your domain name and remember it. The website provides you an easy interface where you can choose, drag and drop things to create your first website. You will need to follow the instructions and create your website. The first step is to create a WEB SERVER and we will use 000Webhost for this. This instructable may go bit longer, but you must read it completely because you will find everything for ESP8266 Communication here whether you have plans to create a communication channel between several ESPs or between ESP8266 and Server. I will describe the whole procedure in detail. You do not need any prior knowledge of HTML, CSS, JAVASCRIPT and PHP, RUBY ON RAILS. In this instructable, I will be using 000WebHost Website, which helps you to make this project efficiently and easily. The second method is to create a However, there are many websites, which provide free Web Hosting facility to Host your Website and get server space (Limited) for a period free. We need something robust, which can be used by any Network over WEB from anywhere in the world. However, using a LOCAL Server is not a great deal. Use Sub Mask and Gateway (Gateway will be the IP address of Router) with IP address and you will be able to communicate with a fixed IP. Choose any IP address outside this range and set it in ESP8266 code. Open your Router settings and in Network Settings find the DHCP range. You can create a LOCAL Server using ESP8266 with fixed IP. After some days, IP will change because router IP changes in range Ģ. (You must have used this earlier while making basic Led Controller using WEB). You can use that IP for communication by reading and writing on it. When it will connect to the internet, it will automatically create a local instance of WEB and will provide you the IP of that server. You can create a LOCAL Server using ESP8266. The first method is to create a LOCAL Server:ġ. There are two types of communication channels, which one can construct and use in their project. Therefore, I decided to start this by myself from scratch.ĮSP8266 is a robust and cheap Wi-Fi module, which help you to communicate with the server as well as with other ESP8266. I tried to find resources on the Internet and got a lot of stuff but the complete description from scratch was not present anywhere. I was working on this project for last 2-3 days.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |