This is the 13th day of my participation in the Genwen Challenge

Introduction to the

This design uses Arduino IDE development environment to establish TCPserver for data transparent transmission.

The program

#include < esp8266wifi. h> #define MAX_SRV_CLIENTS 1 const char* SSID = "Doit"; const char* password = "doit3305"; WiFiServer server(23); WiFiClient serverClients[MAX_SRV_CLIENTS]; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.print("\nConnecting to "); Serial.println(ssid); uint8_t i = 0; while (WiFi.status() ! = WL_CONNECTED && i++ < 20) delay(500); Serial. Print ("Could not connect to"); Serial. Print ("Could not connect to"); Serial.println(ssid); while(1) delay(500); } // Start UART transport and server server.begin(); server.setNoDelay(true); Serial.print("Ready! Use 'telnet "); Serial.print(WiFi.localIP()); Serial.println(" 23' to connect"); } void loop() { uint8_t i; If (server.hasClient()){for(I = 0; i < MAX_SRV_CLIENTS; I++){// find idle or disconnected clients and set them to available if (! serverClients[i] || ! serverClients[i].connected()){ if(serverClients[i]) serverClients[i].stop(); serverClients[i] = server.available(); Serial.print("New client: "); Serial.println(i); continue; WiFiClient serverClient = server.available(); WiFiClient serverClient = server.available(); serverClient.stop(); } for(I = 0; i < MAX_SRV_CLIENTS; I ++){if(serverClients[I] && serverClients[I].connected()){if(serverClients[I].available()){// Obtain data from Telnet client, While (serverClients[I].available()) serial.write (serverClients[I].read()); If (serial.available ()){size_t len = serial.available (); uint8_t sbuf[len]; Serial.readBytes(sbuf, len); // Push UART port data to all connected Telnet clients for bidirectional communication i < MAX_SRV_CLIENTS; i++){ if (serverClients[i] && serverClients[i].connected()){ serverClients[i].write(sbuf, len); delay(1); }}}}Copy the code

subsequent

If you want to know more about the Internet of things and smart home projects, you can pay attention to my project practice column.

Pay attention to the public number, like a little bit in see it.

Writing is not easy, thank you for your support.

This article uses the article synchronization assistant to synchronize