Methods for Inter Esp8266 Communication
- Send a HTTP request from client to server and the server upon receiving the particular request will perform the desired action, manipulate its Inputs Outputs etc. Consider this method as you are sending an HTTP request(From esp8266) containing data to a website(Server-Host esp8266) and the website than displays the data on a web page(Esp8266 Manipulate I/O Pins).
- Send a HTTP request from client to server. Up on receiving the request the server replies client with some useful information. We read the information at client side and extract the meaningful data from the information forwarded by server.
Both methods have their own advantages. First method is useful when we have a fixed process to be executed when ever we want and we don’t need to pass a real time value or data string etc. For example we want to activate a relay, switch or some home appliance in this case we do not need any real time data string to be manipulated. We can hard code a single request for each peripheral. Second method is useful when we need real time data like time, date etc. For example we have a RTC(Real Time Clock) at server side and we want to update our date and time(Client Side), for this we need a real time data string whose length will be fairly long. So here the second method fits in.
NodeMcu(Esp8266-12E) and Esp8266-01 talking with each other
Esp8266 Client side Circuit Diagram
At client side nodemcu i connected a push button with Pin#D7. Pin#D7 is used as input pin. A push button is connected in series with an led and a resistor. Resistor is grounded and led is at active high side with push button in series. Active high side is supplied +3.3 volt from the nodemcu lua module. Resistor is also grounded with the nodemcu module ground. Pin#D7 normally remains at low level. But when ever push button is pressed the led lights up and the D7 logic level changes to high.
What i want is when ever the push button(At client) is pressed the led connected at the server side(esp8266-01) toggles. So the circuit at the right side is made to achieve this logic. Nodemcu is powered through PC USB plug. You can remove the Led from the circuit is their are power issues but it worked for me and i have no issue with the same configuration. |
Esp8266 Server Side Circuit Diagram
At sever side led is connected to Pin#2 of esp8266-01 module. Esp8266-01 has only two GPIO’s(General Purpose Input Output Pins) GPIO-0 amd GPIO-2. I choose GPIO-2 because GPIO-1 is used during uploading code. A 470 ohm resistor is connected in series to led. Circuit is powered through the same power that we apply to vcc of esp8266 module. Esp8266 is a 3.3 volt chip do not power it with more than 4 volts. The vcc of resistor is connected to vcc of esp8266.
I come across many problems in uploading the code to esp8266-01 from arduino ide and finally i succeeded. I made a tutorial on it after that so that other can take advantage of my learning. I suggest you to take the tutorial before proceeding any further. |
ESp8266 to Esp8266 communication code
server.on(“/Led”, handleRoot);
void handleRoot() {
toggle=!toggle; //Toggling Led Variable
digitalWrite(2,toggle); //Toggle Led
String s = “\r\n\r\n<!DOCTYPE HTML>\r\n<html><h1>Esp8266 Communication</h1> “;
s += “<p>Success!!!</html>\r\n\r\n”;
server.send(200,”text/html”,s); //Reply to the client
}
Note: If we want to use the second method which was discussed above we can insert our data in this web page (confirmation text) and extract it at the client side. This is not a hard task it requires a fixed string format with know parameters etc. I will make tutorial on it in future.
//Request to server to activate the led
client.print(String(“GET “) +”/Led”+” HTTP/1.1\r\n” +
“Host: ” + host + “\r\n” +
“Connection: close\r\n\r\n”);
Important note: Esp8266-01 is used in AP(access point) mode and nodemcu in station mode. Nodemcu is restricted in the client code to connect to the SSID of Esp8266-01 which is
“ESP_D54736”. Server Esp8266-01 is assigning IP to nodemcu client. Their is no password the Esp8266 network is open. Recall high school lectures both devices must be on same network to transfer data between each other. Also some esp8266-01 modules are naughty đ and they did not let change their SSID(Its a question why not roaming on internet?). So if your esp8266-01(server) did not originate with this name “ESP_D54736“. Make sure to change the SSID also in the client code.Filed Under: ESP8266, Microcontroller Projects
Questions related to this article?
đAsk and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.