{"id":11402,"date":"2015-09-08T14:26:01","date_gmt":"2015-09-08T14:26:01","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=11402"},"modified":"2019-04-02T10:23:34","modified_gmt":"2019-04-02T10:23:34","slug":"how-to-make-two-esp8266-talk","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/how-to-make-two-esp8266-talk\/","title":{"rendered":"How to Make Two ESP8266 Talk"},"content":{"rendered":"<p>In this project\u00a0you\u2019re going to\u00a0make two ESP8266 talk with each other.<!--more--><\/p>\n<p>How it works? You&#8217;re going to\u00a0set one ESP as an Access Point (Server) and another ESP as a Station (Client). Then they&#8217;ll establish a wireless communication and the Client sends a message to the Server saying &#8220;Hello World!&#8221;.<\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-11405\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esp-client-vs-server.png?resize=420%2C280&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esp client vs server\" width=\"420\" height=\"280\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esp-client-vs-server.png?w=600&amp;quality=100&amp;strip=all&amp;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esp-client-vs-server.png?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/p>\n<p>Before continue reading this project, please complete\u00a0the following tutorials:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-esp8266-wifi-transceiver-review\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to get started with the ESP8266<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/flashing-nodemcu-firmware-on-the-esp8266-using-windows\/\" target=\"_blank\" rel=\"noopener noreferrer\">Flash\u00a0both ESPs\u00a0with NodeMCU<\/a><\/li>\n<\/ul>\n<p>If you like the ESP and you want to do more projects\u00a0you can read my eBook <a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">Home Automation using ESP8266 here<\/a>.\u00a0<strong>Let&#8217;s get started!<\/strong><\/p>\n<h2>Parts List<\/h2>\n<p>Here&#8217;s the hardware that you need to complete\u00a0this project:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp-01-wi-fi-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266-01<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/ftdi-programmer-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">FTDI programmer<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/makeradvisor.com\/tools\/esp-01-wi-fi-board\/\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-4815\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/01\/ESP01v0.jpg?resize=224%2C224&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"224\" height=\"224\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/01\/ESP01v0.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/01\/ESP01v0.jpg?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/01\/ESP01v0.jpg?resize=300%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 224px) 100vw, 224px\" \/><\/a><\/p>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>Schematics (3.3V FTDI\u00a0Programmer)<\/h2>\n<p>The schematics for this project are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266 to upload some code. (Repeat the schematics below for the Client and Server)<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-5193\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/03\/ESP-Bitcoin-price_bb.png?resize=588%2C216&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-Bitcoin-price_bb\" width=\"588\" height=\"216\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/03\/ESP-Bitcoin-price_bb.png?w=759&amp;quality=100&amp;strip=all&amp;ssl=1 759w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/03\/ESP-Bitcoin-price_bb.png?resize=300%2C110&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><\/p>\n<h2>Downloading ESPlorer<\/h2>\n<p>I recommend using the ESPlorer program created by 4refr0nt\u00a0to create and save Lua files into your\u00a0ESP8266.<\/p>\n<p>Follow these instructions to download and install ESPlorer:<\/p>\n<ol>\n<li><a href=\"http:\/\/esp8266.ru\/esplorer\/#tutorials\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download\u00a0ESPlorer<\/a><\/li>\n<li>Unzip that folder<\/li>\n<li>Go to the <strong>main\u00a0<\/strong>folder<\/li>\n<li>Run\u00a0<strong>ESPlorer.jar<\/strong>.\u00a0It&#8217;s a JAVA program, so you need JAVA installed on\u00a0your computer<\/li>\n<li>Open the ESPlorer<\/li>\n<\/ol>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-5125\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/02\/esplorer-start.png?resize=424%2C316&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esplorer start\" width=\"424\" height=\"316\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/02\/esplorer-start.png?w=802&amp;quality=100&amp;strip=all&amp;ssl=1 802w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/02\/esplorer-start.png?resize=300%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/p>\n<h2>Writing Your\u00a0Server Script<\/h2>\n<p>Don&#8217;t forget that first you need to <a href=\"https:\/\/randomnerdtutorials.com\/flashing-nodemcu-firmware-on-the-esp8266-using-windows\/\" target=\"_blank\" rel=\"noopener noreferrer\">flash both your\u00a0ESPs with NodeMCU firmare<\/a>. Copy and paste the code below into ESPlorer.<\/p>\n<p><strong>Summary:<\/strong> The ESP Server acts as an Access Point and it has its own SSID=test and Password=12345678. The server is continuously listening for a connection, when it successfully establishes a connection and receives a message prints that string on the serial monitor.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">-- Rui Santos\n-- Complete project details at http:\/\/randomnerdtutorials.com\n-- ESP8266 Server\n\nprint(&quot;ESP8266 Server&quot;)\nwifi.setmode(wifi.STATIONAP);\nwifi.ap.config({ssid=&quot;test&quot;,pwd=&quot;12345678&quot;});\nprint(&quot;Server IP Address:&quot;,wifi.ap.getip())\n\nsv = net.createServer(net.TCP) \nsv:listen(80, function(conn)\n    conn:on(&quot;receive&quot;, function(conn, receivedData) \n        print(&quot;Received Data: &quot; .. receivedData)         \n    end) \n    conn:on(&quot;sent&quot;, function(conn) \n      collectgarbage()\n    end)\nend)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266-Communication\/server.lua\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Uploading Your Lua Script<\/h2>\n<p>When you open the ESPlorer you should see a window similar to the preceding Figure, follow these instructions to send commands to your ESP8266:<\/p>\n<ol>\n<li>Connect your FTDI programmer to your computer<\/li>\n<li>Set bad raute as 9600<\/li>\n<li>Select your FTDI programmer port (COM3, for example)<\/li>\n<li>Press\u00a0Open\/Close<\/li>\n<li>Select NodeMCU+MicroPtyhon tab<\/li>\n<li>Copy the your Lua\u00a0script into\u00a0ESPlorer<\/li>\n<\/ol>\n<p>Then you simply click the button\u00a0<strong>Save to ESP <\/strong>and save your file with the name &#8220;init.lua&#8221;.\u00a0Everything that you need to worry about or change is highlighted in red box in the following Figure.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11406\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esplorer.png?resize=737%2C372&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esplorer\" width=\"737\" height=\"372\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esplorer.png?w=1252&amp;quality=100&amp;strip=all&amp;ssl=1 1252w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esplorer.png?resize=300%2C151&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esplorer.png?resize=1024%2C517&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/p>\n<h2>Writing Your Client\u00a0Script<\/h2>\n<p>Having your ESP flashed with NodeMCU. Copy and paste the code below into ESPlorer. <strong>Summary:<\/strong> The ESP Client\u00a0acts as a Station\u00a0and it is continuously looking\u00a0for an Access Point. When the Client finds the Server establishes a communication and sends a message &#8220;Hello World!&#8221; every 5 seconds.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">-- Rui Santos\n-- Complete project details at http:\/\/randomnerdtutorials.com\n-- ESP8266 Client\n\nprint(&quot;ESP8266 Client&quot;)\nwifi.sta.disconnect()\nwifi.setmode(wifi.STATION) \nwifi.sta.config(&quot;test&quot;,&quot;12345678&quot;) -- connecting to server\nwifi.sta.connect() \nprint(&quot;Looking for a connection&quot;)\n\ntmr.alarm(1, 2000, 1, function()\n     if(wifi.sta.getip()~=nil) then\n          tmr.stop(1)\n          print(&quot;Connected!&quot;)\n          print(&quot;Client IP Address:&quot;,wifi.sta.getip())\n          cl=net.createConnection(net.TCP, 0)\n          cl:connect(80,&quot;192.168.4.1&quot;)\n          tmr.alarm(2, 5000, 1, function() \n            cl:send(&quot;Hello World!&quot;) \n          end)\n      else\n         print(&quot;Connecting...&quot;)\n      end\nend)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266-Communication\/client.lua\" target=\"_blank\">View raw code<\/a><\/p>\n<p><strong>Note:<\/strong> To upload the Client Script code follow the preceding heading called &#8220;Uploading Your Lua Script&#8221;.<\/p>\n<h2>Demonstration<\/h2>\n<p>In this project the Client\u00a0is sending a message \u201cHello World!\u201d to the Server via wireless.\u00a0Here\u2019s what you should see in your\u00a0serial terminal windows (see Figure below).<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11404\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/data-received-esp8266.png?resize=980%2C379&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"data received esp8266\" width=\"980\" height=\"379\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/data-received-esp8266.png?w=980&amp;quality=100&amp;strip=all&amp;ssl=1 980w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/data-received-esp8266.png?resize=300%2C116&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/p>\n<p>Note: On the left window, I\u2019m using the ESPlorer Output Window . On the right window, I\u2019m establishing a serial communication with PuTTY.org.<\/p>\n<h4>Do you have any questions?\u00a0Leave a comment down below!<\/h4>\n<p>Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my <a href=\"https:\/\/randomnerdtutorials.com\/download\" target=\"_blank\" rel=\"noopener noreferrer\">blog<\/a> and my\u00a0Facebook Page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project\u00a0you\u2019re going to\u00a0make two ESP8266 talk with each other.<\/p>\n","protected":false},"author":1,"featured_media":11405,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[214,265,300,240,220,264,219,218],"tags":[],"class_list":["post-11402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266","category-esp8266-project","category-0-esp8266","category-esp8266-projects","category-http-client","category-project","category-request-data","category-web-server"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/09\/esp-client-vs-server.png?fit=600%2C400&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/11402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=11402"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/11402\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/11405"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=11402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=11402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=11402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}