preparation

= = = = = = =

  1. Arduino IDE

  2. ESPDuino

  3. Arduino ESP8266 version file

The experimental requirements

The ESPDuino development board is set to TCP Client mode to achieve network communication

Overview of TCP Communication

TCP: Transmission Control Protocol. TCP is a connection-oriented communication protocol. Before transmitting data, a logical connection is established between the sender and receiver, and then data is transmitted. TCP provides reliable and error-free data transmission between two computers.

TCP is designed to accommodate layered protocol hierarchies that support multiple network applications. TCP is relied on to provide reliable communication services between pairs of processes in a host computer connected to different but interconnected computer communication networks. TCP assumes that it can get simple, possibly unreliable, datagram services from lower-level protocols. In principle, TCP should be able to operate over a variety of communication systems from hardwire connections to packet-switched or circuit-switched networks.

The specific methods

The loginTcp.doit. Am Gets the IP address and port to use:

The program

#include<ESP8266WiFi.h> const char*ssid ="STM32L476"; const char*password ="284122348"; Const char * serverIP = "115.29.109.104"; int serverPort =6558; WiFiClient client; bool bConnected =false; char buff[512]; int nm =0; void setup(){ Serial.begin(115200); delay(10); Serial.println(); Serial.println(); Serial.print("Connecting to"); Serial.println(ssid); WiFi.begin(ssid,password); while(WiFi.status()! =WL_CONNECTED){ delay(500); Serial.print("."); } Serial.println("WiFi connected"); Serial.println("IP address:"); Serial.println(WiFi.localIP()); } void loop(){ delay(1); if(bConnected ==false) { if(! client.connect(serverIP,serverPort)) { Serial.println("connection failed"); delay(5000); return; } bConnected=true; Serial.println("connection ok"); } else if(client.available()) { Serial.println("data is coming"); while(client.available()) { buff[nm++]=client.read(); if(nm>=511)break; } buff[nm]=0x00; nm=0; Serial.print(buff); client.print(buff); client.flush(); }}Copy the code
Copy the code

The experimental phenomena



subsequent

Click on it if you like

Writing is not easy, thank you for your support.

This article uses the article synchronization assistant to synchronize