Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3.  
  4. int port = 8888;
  5. WiFiServer server(port);
  6.  
  7.  
  8. const char *ssid = "---------";  
  9. const char *password = "--------";  
  10.  
  11.  
  12.  
  13. void setup()
  14. {
  15.   Serial.begin(115200);
  16.   Serial.println();
  17.  
  18.   WiFi.mode(WIFI_STA);
  19.   WiFi.begin(ssid, password); //Connect to wifi
  20.  
  21.   // Wait for connection  
  22.   Serial.println("Connecting to Wifi");
  23.   while (WiFi.status() != WL_CONNECTED) {  
  24.     delay(500);
  25.     Serial.print(".");
  26.     delay(500);
  27.   }
  28.  
  29.   Serial.println("");
  30.   Serial.print("Connected to ");
  31.   Serial.println(ssid);
  32.  
  33.   Serial.print("IP address: ");
  34.   Serial.println(WiFi.localIP());  
  35.   server.begin();
  36.   Serial.print("Open Telnet and connect to IP:");
  37.   Serial.print(WiFi.localIP());
  38.   Serial.print(" on port ");
  39.   Serial.println(port);
  40. }
  41. //=======================================================================
  42. //                    Loop
  43. //=======================================================================
  44.  
  45. void loop()
  46. {
  47.   WiFiClient client = server.available();
  48.  
  49.   if (client) {
  50.     if(client.connected())
  51.     {
  52.       Serial.println("Client Connected");
  53.     }
  54.    
  55.     while(client.connected()){      
  56.       while(client.available()>0){
  57.         // read data from the connected client
  58.         Serial.write(client.read());
  59.       }
  60.       //Send Data to connected client
  61.       while(Serial.available()>0)
  62.       {
  63.         client.write(Serial.read());
  64.       }
  65.     }
  66.     client.stop();
  67.     Serial.println("Client disconnected");    
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement