operations |
comment | "parent_author":"",<br>"parent_permlink":"utopian-io",<br>"author":"japh",<br>"permlink":"create-a-local-chat-server-using-nodemcu-devkit-v1-0-board-via-telnet",<br>"title":"Create a Local Chat Server using NodeMCU devkit v1.0 board via Telnet",<br>"body":"#### What Will I Learn? <br><hr>\n\n- You will learn how to make a chat server that operates within the local area network using NodeMCU devkit v1.0 board.\n- You will learn how devices can connect to the created chat server using a telnet client application.\n- You will learn some possible applications of this tutorial on the society.<p><\/p>\n#### Requirements\n<center><hr><b>Materials Needed<\/b><hr><\/center>\n- NodeMCU devkit v1.0\n- USB Cable (Type A to Mini B)\n- Computer\n\n<center><hr><b>Software Applications <\/b><hr><\/center>\n- Open-Source Arduino Software (IDE) \/ Arduino IDE\n- <b>For testing:<\/b> Any Existing Telnet Client Applications for computers,<br> tablets,<br> or mobile phones. Example: <em>Simple Telnet Client,<br> ConnectBot and etc.<\/em>\n\n#### Difficulty<hr>\n- Intermediate\n\n<hr><p><br>\n<b>Description: <\/b><p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517868729\/yoot7hknr7imasksh9ft.png<br><sup><sub>Image References: <a href=\"https:\/\/circuit.rocks\/image\/cache\/product\/DPO02102N\/nodemcu-lua-wifi-board-based-on-esp8266-cp2102-module-dpo02102n-365-500x500.jpg\">1<\/a>,<br> <a href=\"https:\/\/www.ssh.com\/s\/telnet-network-attack-1370x912-GdyrENjH.png\">2<\/a><\/sub><\/sup><\/center><p>\nA <b>chat server<\/b> refers to a computer which is committed for giving processing power to deal with and maintain chatting and it clients. Utilizing telnet to run charges on remote PCs is a brisk method to administrate servers and different workstations. <p><b>Telnet<\/b> is a convention utilized on the Internet or local area network to give a bidirectional intelligent text-based facility that is utilizing virtual terminal connection. Telnet client applications are accessible for all platforms of computer,<br> virtually.<p>In this tutorial,<br> we will create a simple telnet server that could manage basic chatting functionality using NodeMCU devkit v1.0 board. The server should support various associated clients. Messages sent to the server are communicated to all associated clients' facility that is utilizing a virtual terminal association. For testing,<br> we will just need to implement a conversation between two devices in our network to test our chat server. But the number of clients on the chat server can be easily adjusted,<br> afterwards. We will need to use the Wi-Fi capabilities of our NodeMCU devkit v1.0 to support the local chat server using telnet.\n<p><blockquote>For further research about NodeMCU\ndevkit v1.0. Here is its official <a href=\"www.nodemcu.com\">website<\/a><\/blockquote><p>\n\n\n<h2>Tutorial Contents<\/h2><hr>\n<center><b>\"Create a Local Chat Server using NodeMCU devkit v1.0 board via Telnet \"<\/b><\/center><p><\/p>\n<b>Step 1:<\/b><center><b><em>\"Downloading the ESP8266 Boards<br>and its Necessary Files\"<\/em><\/b><\/center><hr>\n<br>Open Arduino IDE then,<br> check if you have the ESP8266 library from your installed libraries . This is necessary to configure the NodeMCU to run on Arduino IDE. \n<em><b>Note:<\/b> Make sure that you have already downloaded and installed the boards and the necessary files to run the NodeMCU devkit v1.0. If you haven't install or download them,<br> kindly click <a href=\"https:\/\/utopian.io\/u\/25578052\">here<\/a>. And follow the first step of my tutorial there.<\/em>\n<p>\nAfter the installation of ESP8266,<br> go to the <b>Tools<\/b> tab and change the board to <em>NodeMCU 1.0 (ESP-12E Module)<\/em><p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1516177346\/khn1srl1nqv4vlel6oav.png<\/center>\n<b>Step 2:<\/b><center><b><em>\"Programming your Board\"<\/em><\/b><\/center><hr>\n<p>When you have finished downloading and installing the necessary files to run ESP8266 boards like the NodeMCU devkit v1.0 board,<br> it would be required to close the Arduino IDE then,<br> open it after a minute. It is good practice to do,<br> so as to allow the new libraries to be loaded for setup when you open the Arduino IDE again,<br> in some instances to avoid errors.<p>After,<br> click on <b>File<\/b>> <b>New<\/b>,<br> to create a new sketch in Arduino IDE.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517654403\/cwuhosstukxjsb8iowyt.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center>\n<p>On your new sketch in Arduino IDE,<br> input this program:<p>\n<pre><code>#include <<a href=\"\">ESP8266WiFi.h<\/a>>\n\/\/how many clients should be able to telnet to this ESP8266\n#define MAX_SRV_CLIENTS 1\nconst char* MY_WIFI_SSID = \"HUAWEI Y5 2017\";\nconst char* MY_WIF_PASSWORD = \"12345678\";\nWiFiServer server(23);\nWiFiClient serverClients[MAX_SRV_CLIENTS ;\nvoid setup() \nSerial1.begin(115200);\nWiFi.begin(MY_WIFI_SSID,<br> MY_WIF_PASSWORD);\nSerial1.print(\"\\nConnecting to \"); \nSerial1.println(MY_WIFI_SSID);\nuint8_t i = 0;\nwhile (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);\nif(i == 21) \nSerial1.print(\"Could not connect to\"); Serial1.println(MY_WIFI_SSID);\nwhile(1) \ndelay(500);\n \n\/\/start UART and the server\nSerial.begin(115200);\nserver.begin();\nserver.setNoDelay(true);\nSerial1.print(\"Ready! Use 'telnet \");\nSerial1.print(WiFi.localIP());\nSerial1.println(\" 23' to connect\");\n \nvoid loop() \nuint8_t i;\n\/\/check if there are any new upcoming clients\nif (server.hasClient()) \nfor(i = 0; i < MAX_SRV_CLIENTS; i++) \n\/\/find those free\/disconnected spot\n if (!serverClients[i || !serverClients[i .connected()) \nif(serverClients[i ) serverClients[i .stop();\nserverClients[i = server.available();\nSerial1.print(\"New client: \"); Serial1.print(i);\ncontinue;\n \n \n\/\/no free\/disconnected spot so reject\nWiFiClient serverClient = server.available();\nserverClient.stop();\n \n\/\/check clients for data\nfor(i = 0; i < MAX_SRV_CLIENTS; i++) \nif (serverClients[i && serverClients[i .connected()) \nif(serverClients[i .available()) \n\/\/get data from the telnet client and push it to the UART\nwhile(serverClients[i .available()) Serial.write(serverClients[i .read());\n \n \n \n\/\/check UART for data\nif(Serial.available()) \nsize_t len = Serial.available();\nuint8_t sbuf[len ;\nSerial.readBytes(sbuf,<br> len);\n\/\/push UART data to all connected telnet clients\nfor(i = 0; i < MAX_SRV_CLIENTS; i++) \nif (serverClients[i && serverClients[i .connected()) \nserverClients[i .write(sbuf,<br> len);\ndelay(1);\n \n \n \n <\/code><\/pre> \n<p><blockquote> The program simply create a Wi-Fi server at port 23 which is\nthe default port assigned to Telnet by the code <code>WiFiServer server(23);<\/code>.\nThe number of maximum clients that could access the server at a time too is determined \nby the code <code>#define MAX_SRV_CLIENTS 1<\/code>. This could be changed afterwards.<br>\nThe IF condition on the code <code>if (server.hasClient())<\/code> simply check for the presence \nupcoming clients. I a client sends a data to the server,<br> these data will be displayed thru the \nSerial Monitor thru the code <code>Serial.write(serverClients[i .read());<\/code>. <br>On the \nother hand,<br> if a data is sent from the serial monitor to all the connected clients,<br> it will\nbe broadcasted to the connected clients thru the code <code>serverClients[i .write(sbuf,<br> len);<\/code>. <br>In order for the chat server to have wireless connection to the clients,<br> the board must connect to a wireless access point or to a hotspot. The SSID and the password of the access point it would connect is defined by the code <code>const char* MY_WIFI_SSID = \"HUAWEI Y5 2017\";<\/code> and <code>const char* MY_WIF_PASSWORD = \"12345678\";<\/code>.\nThis should be changed based on the configuration of the wireless access point,<br> you are using.<\/blockquote><\/p>\n\nNow,<br> connect your NodeMCU devkit v1.0 to your computer using the USB cable (Type A to Mini B). <p>\n<center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517860077\/dwymctxfcsa5ugrqzwsz.jpg<br><sup><sub>Actual Photo<\/sub><\/sup><\/center>\n<p>Go to the <b>device manager<\/b> then,<br> identify its port number if it is your first time to use this board. Now,<br> go the Arduino IDE and click <b>Tools<\/b> > <b>Port<\/b> and look for the port of your NodeMCU devkit v1.0. <p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517654530\/pfjwohi4opz3bruzas95.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center><p>Input the program above properly. And click <b>Verify\/Compile<\/b> when you are done with the program to check for errors.<em>I have already compiled this program and it has no errors based on my screenshot.<\/em> If compiling your code is unsuccessful,<br> try comparing your program to my program in this tutorial. You may have missed something.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517860366\/earlk7pxmzwfkxb8xt4s.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center>\n<p>If your program has no errors after you compiled,<br> click on <b>Upload<\/b>. If uploading your code is unsuccessful,<br> check if you are using the right port.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517860486\/jcslpxkngvvjl1jervu6.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center><p>\n<p>Now,<br> click on the Serial Monitor to get ready for testing,<br> as shown below.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517860651\/sdwv79jaj8gti7golao2.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center><p>\n<b>Step 4:<\/b> <center><b><em>\"Testing your System\"<\/em><\/b><\/center><hr>\n<p><b>1.<\/b> Before testing,<br> make sure that you have already turned on the Wi-Fi hotspot which the NodeMCU board connects as specified on the program above. I am using mobile tethering or portable hotspot from my phone as a wireless access point so it would be easier for me to find the IP address of my board. <p>Click on the connected devices and look for the NodeMCU board. Normally,<br> it is usually preceded by a prefix of \"ESP\" or \"THINKER\". And take note of its IP address.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517863380\/xqhx0owpfqohdsoax23e.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center><p>\n<p><div class='pull-left'><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517864024\/fxlqe8tn29ekqr6rjcid.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center><\/div><b>2.<\/b> Open your telnet client application. In my case,<br> I am using <em>Simple Telnet Client<\/em> app by Eddie Cheung. \nI downloaded it from the playstore. Any telnet client application will do since all of them\nhas a similar process of connecting to telnet. Now,<br> input the IP address of the NodeMCU board to <em> \"host\"<\/em> and let the <em>\"port\"<\/em> be <b>23<\/b>. Then,<br> click on <b>Connect<\/b> button.<p><pre><pre><pre><pre><pre><b>3.<\/b> Type a message and send it by clicking <b>GO<\/b> button. And check the serial monitor of your Arduino IDE,<br> your message should be there already.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517865657\/hobvz0h6voktp3ifdj3z.png<br><sup><sub>Actual Photo<\/sub><\/sup><p><\/p><\/center><p>\n<b>4.<\/b> Now,<br> you can send your reply by typing on your serial monitor and click on <b>SEND<\/b>\nbutton when you are done with your message. Then,<br> go back to your telnet client app and the \nmessage you have sent through your serial monitor should be there now.<p><center>https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1517866332\/gbwbf2jm6ruxuyn2wt9d.png<br><sup><sub>Actual Photo<\/sub><\/sup><\/center><p>Now,<br> we have successfully created a local chat server using NodeMCU devkit v1.0 via telnet.<p>\n<h3> Curriculum<\/h3><hr> <br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/25578052\">Auxiliary Wireless TV Power Remote Control using NodeMCU devkit v1.0<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/26198599\">Make Your Own Web Server using NodeMCU devkit v1.0<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/26718005\">External GPIO Pin State Monitoring using HTTP Client Request for NodeMCU Devkit v1.0 Boards<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/27254457\">Web-controlled Servomotor using NodeMCU devkit v1.0 board<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/27813598\">Intruder Alarm System with Automatic Online Updates using NodeMCU devkit v1.0<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/28656117\">Online Temperature Monitor using NodeMCU devkit v1.0<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/29501150\">Water Overflow Alarm with Online Updates using NodeMCU devkit v1.0<\/a><br>\n\u2022\t<a href=\"https:\/\/utopian.io\/u\/30123832\">Set up Your Own Wireless Access Point using NodeMCU devkit v1.0<\/a>\n\n<p><\/p>This tutorial is very useful when you want to implement a simple text-oriented wireless communication,<br> thru Wi-Fi technology,<br> on the physical topology of your local area network,<br> at a lesser cost of setting up a local chat server.<p>\nYour contributor,<br> @japh\n\n<br \/><hr\/><em>Posted on <a href=\"https:\/\/utopian.io\/utopian-io\/@japh\/create-a-local-chat-server-using-nodemcu-devkit-v1-0-board-via-telnet\">Utopian.io - Rewarding Open Source Contributors<\/a><\/em><hr\/>",<br>"json_metadata":" \"community\":\"utopian\",<br>\"app\":\"utopian\/1.0.0\",<br>\"format\":\"markdown\",<br>\"repository\"<br>\"id\":35590819,<br>\"name\":\"nodemcu-devkit-v1.0\",<br>\"full_name\":\"nodemcu\/nodemcu-devkit-v1.0\",<br>\"html_url\":\"https:\/\/github.com\/nodemcu\/nodemcu-devkit-v1.0\",<br>\"fork\":false,<br>\"owner\"<br>\"login\":\"nodemcu\" ,<br>\"pullRequests\":[ ,<br>\"platform\":\"github\",<br>\"type\":\"tutorials\",<br>\"tags\":[\"utopian-io\",<br>\"technology\",<br>\"howto\",<br>\"philippines\",<br>\"cebu\" ,<br>\"users\":[\"japh\" " | comment_options | "author":"japh", "permlink":"create-a-local-chat-server-using-nodemcu-devkit-v1-0-board-via-telnet", "max_accepted_payout":"1000000.000 SBD", "percent_steem_dollars":10000, "allow_votes":true, "allow_curation_rewards":true, "extensions":[[0, "beneficiaries":[ "account":"utopian.pay", "weight":2500 |
|