当前位置:网站首页>Teach you how to configure S2E as the working mode of TCP client through MCU
Teach you how to configure S2E as the working mode of TCP client through MCU
2022-07-25 11:42:00 【WIZnet】



01 /****************************************************
02 Function name :TCP_Client_Mode
03 Shape parameter : nothing
04 Return value : nothing
05 The functionality : Send through serial port AT Command configuration S2E modular
06 ****************************************************/
07 volatileuint8_t SendFlag=0;
08
09 void TCP_Client_Mode(void)
10 {
11 uint8_t RecvFlag=1;
12 char *state;
13 switch (SendFlag) {
14 case 0: {
15 Usart_Send(USART2,"AT\r\n"); // Terminal detection command
16 while (RecvFlag) {
17 if (RX2_Point & FRAME_LEN) {
18 // If data is received
19 state=strstr((char *)RecvBuff,"OK");
20 // Judge whether there is “OK”
21 if (state!=NULL) { // Yes
22 RX2_Point=0;
23 // The receive buffer pointer is set to zero
24 RecvFlag=0;
25 // Receive Peugeot position zero
26 SendFlag=1; // Send flag position zero
27 printf("Recv:%s\r\n",RecvBuff);
28 memset(RecvBuff,0,RECV_LEN);
29 // Receive cache reset
30 } else { // nothing
31 SendFlag=100; // Configuration failed
32 RecvFlag=0;
33 }
34 }
35 }
36 }
37 break;
38 case 1: {
39 Usart_Send(USART2,"AT+ECHO=0\r\n");
40 // Turn on (1)/ close (0) Echo command
41 RecvFlag=1;
42 while (RecvFlag) {
43 if (RX2_Point & FRAME_LEN) {
44 state=strstr((char *)RecvBuff,"OK");
45 if (state!=NULL) {
46 RX2_Point=0;
47 RecvFlag=0;
48 SendFlag=2;
49 printf("Recv:%s\r\n",RecvBuff);
50 memset(RecvBuff,0,RECV_LEN);
51 } else {
52 SendFlag=100;
53 RecvFlag=0;
54 }
55 }
56 }
57 }
58 break;
59 case 2: {
60 Usart_Send(USART2,"AT+C1_OP=1\r\n"); // Configure to TCP
61 Client Mode command
62 RecvFlag=1;
63 while (RecvFlag) {
64 if (RX2_Point & FRAME_LEN) {
65 state=strstr((char *)RecvBuff,"OK");
66 if (state!=NULL) {
67 RX2_Point=0;
68 RecvFlag=0;
69 SendFlag=3;
70 printf("Recv:%s\r\n",RecvBuff);
71 memset(RecvBuff,0,RECV_LEN);
72 } else {
73 SendFlag=100;
74 RecvFlag=0;
75 }
76 }
77 }
78 }
79 break;
80 case 3: {
81 Usart_Send(USART2,"AT+IP_MODE=1\r\n");
82 // To configure DHCP Mode command
83 RecvFlag=1;
84 while (RecvFlag) {
85 if (RX2_Point & FRAME_LEN) {
86 state=strstr((char *)RecvBuff,"OK");
87 if (state!=NULL) {
88 RX2_Point=0;
89 RecvFlag=0;
90 SendFlag=4;
91 printf("Recv:%s\r\n",RecvBuff);
92 memset(RecvBuff,0,RECV_LEN);
93 } else {
94 SendFlag=100;
95 RecvFlag=0;
96 }
97 }
98 }
99 }
100 break;
101 case 4: {
102 Usart_Send(USART2,"AT+C1_PORT=5000\r\n");
103 // To configure S2E The local port number of
104 RecvFlag=1;
105 while (RecvFlag) {
106 if (RX2_Point & FRAME_LEN) {
107 state=strstr((char *)RecvBuff,"OK");
108 if (state!=NULL) {
109 RX2_Point=0;
110 RecvFlag=0;
111 SendFlag=5;
112 printf("Recv:%s\r\n",RecvBuff);
113 memset(RecvBuff,0,RECV_LEN);
114 } else {
115 SendFlag=100;
116 RecvFlag=0;
117 }
118 }
119 }
120 }
121 break;
122 case 5: {
123 Usart_Send(USART2,"AT+C1_CLI_IP1=192.168.1.109\r\n");
124 // Configure the configuration of the remote server IP Address
125 RecvFlag=1;
126 while (RecvFlag) {
127 if (RX2_Point & FRAME_LEN) {
128 state=strstr((char *)RecvBuff,"OK");
129 if (state!=NULL) {
130 RX2_Point=0;
131 RecvFlag=0;
132 SendFlag=6;
133 printf("Recv:%s\r\n",RecvBuff);
134 memset(RecvBuff,0,RECV_LEN);
135 } else {
136 SendFlag=100;
137 RecvFlag=0;
138 }
139 }
140 }
141 }
142 break;
143 case 6: {
144 Usart_Send(USART2,"AT+C1_CLI_PP1=5000\r\n");
145 // Configure the port number of the remote server
146 RecvFlag=1;
147 while (RecvFlag) {
148 if (RX2_Point & FRAME_LEN) {
149 state=strstr((char *)RecvBuff,"OK");
150 if (state!=NULL) {
151 RX2_Point=0;
152 RecvFlag=0;
153 SendFlag=7;
154 printf("Recv:%s\r\n",RecvBuff);
155 memset(RecvBuff,0,RECV_LEN);
156 } else {
157 SendFlag=100;
158 RecvFlag=0;
159 }
160 }
161 }
162 }
163 break;
164 case 7: {
165 Usart_Send(USART2,"AT+START_MODE=0\r\n");
166 // Configure the next power on startup mode (0-AT Pattern ,1-
167 Data patterns )
168 RecvFlag=1;
169 while (RecvFlag) {
170 if (RX2_Point & FRAME_LEN) {
171 state=strstr((char *)RecvBuff,"OK");
172 if (state!=NULL) {
173 RX2_Point=0;
174 RecvFlag=0;
175 SendFlag=8;
176 printf("Recv:%s\r\n",RecvBuff);
177 memset(RecvBuff,0,RECV_LEN);
178 } else {
179 SendFlag=100;
180 RecvFlag=0;
181 }
182 }
183 }
184 }
185 break;
186 case 8: {
187 Usart_Send(USART2,"AT+EXIT\r\n");
188 // Save the configuration and enter data mode
189 RecvFlag=1;
190 while (RecvFlag) {
191 if (RX2_Point & FRAME_LEN) {
192 state=strstr((char *)RecvBuff,"OK");
193 if (state!=NULL) {
194 RX2_Point=0;
195 RecvFlag=0;
196 SendFlag=99;
197 printf("Recv:%s\r\n",RecvBuff);
198 memset(RecvBuff,0,RECV_LEN);
199 } else {
200 SendFlag=100;
201 RecvFlag=0;
202 }
203 }
204 }
205 }
206 break;
207 case 99: {
208 printf("TCP Client Config Success!\r\n");
209 Config_OK=1;
210 }
211 default:
212 RecvFlag=100;
213 break;
214 case 100: {
215 printf("TCP Client Config Fail!\r\n");
216 Config_OK=1;
217 }
218 break;
219 }
220 }
W5500S2E-S1 It is an industrial serial port to Ethernet module , Supports multiple baud rates , from 1.2Kbps to 1.152Mbps. Adopted WIZnet Company hardware TCP/IP Protocol Ethernet chip W5500. It's faster 、 A more stable 、 Safer Ethernet solutions .
WIZnet Official website :http://www.iwiznet.cn/
WIZnet Official technical service platform (Q Group ):595547972
More Internet of things applications , Focus on WIZnet Official wechat :

边栏推荐
- Nowcodertop12-16 - continuous updating
- 使用Three.js实现炫酷的赛博朋克风格3D数字地球大屏
- What kind of product power does Hongguang miniev, the top seller of new energy, have?
- Similarity matrix, diagonalization condition
- Dynamic planning question 05_ Missile interception
- JDBC summary
- Dataframe print ellipsis problem
- 全网显示 IP 归属地,是怎么实现的?
- Small and micro enterprise smart business card management applet
- OneNET平台控制W5500开发板LED灯
猜你喜欢

Reptile foundation I

Breadth first traversal (problems related to sequence traversal of graphs and binary trees)

WIZnet嵌入式以太网技术培训公开课(免费!!!)

Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error

Similarity matrix, diagonalization condition

Common web attacks and defense

如何判断静态代码质量分析工具的性能?这五大因素必须考虑

如何解决“W5500芯片在TCP_Client模式下,断电重启之后无法立即连接到服务器”的问题

SQL injection less23 (filter comment)

Nowcodertop7-11 - continuous updating
随机推荐
Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
Linked list related (design linked list and ring linked list)
Shell Chapter 7 exercise
cookie and session
Greedy problem 01_ Activity arrangement problem
Nowcodertop12-16 - continuous updating
布局管理==PYQT5
Use three.js to realize the cool cyberpunk style 3D digital earth large screen
My colleague looked at my code and exclaimed: how can I use a singleton in unity
倍增Floyd「建议收藏」
The principle analysis of filter to solve the request parameter garbled code
【mysql学习09】
Filter过滤器解决request请求参数乱码的原理解析
信号与槽机制==PYQT5
Dynamic planning problem 03_ Maximum sub segment sum
There is a newline problem when passing shell script parameters \r
Smart cloud IOT platform STM32 esp8266-01s simple wireless light control
flinksql client 连接kafka select * from table没有数据报错,如何解决?
W5500在处于TCP_Server模式下,在交换机/路由器网络中无法ping通也无法通讯。
Summary of combination problems of Li Kou brush questions (backtracking)