代写 android AN1509 ATK-ESP8266 WIFI Ä£¿éʹÓÃ˵Ã÷

AN1509 ATK-ESP8266 WIFI Ä£¿éʹÓÃ˵Ã÷
±¾Ó¦ÓÃÎĵµ(AN1509C£¬¶ÔÓ¦Mini STM32F103¿ª·¢°åÀ©Õ¹ÊµÑé13)½«½Ì´ó¼ÒÈçºÎÔÚ Mini STM32F103 ¿ª·¢°åÉÏʹÓà ATK-ESP8266 WIFI Ä£¿é¡£
±¾Îĵµ·ÖΪÈçϼ¸²¿·Ö: 1£¬ATK-ESP8266 WIFI Ä£¿é¼ò½é 2£¬Ó²¼þÁ¬½Ó
3£¬Èí¼þʵÏÖ
4£¬ÑéÖ¤
1¡¢ATK-ESP8266 WIFI Ä£¿é¼ò½é
ATK-ESP8266 ÊÇ ALIENTEK ÍƳöµÄÒ»¿î¸ßÐÔÄÜµÄ UART-WiFi(´®¿Ú-ÎÞÏß)Ä£¿é£¬ ATK-ESP8266°åÔØÕýµãÔ­×ÓÍŶÓ×ÔÖ÷¿ª·¢µÄATK-ESP-01Ä£¿é£¬¸ÃÄ£¿éͨ¹ýFCC£¬CEÈÏÖ¤£¬ ¿ÉÖ±½ÓÓÃÓÚ²úÆ·³ö¿ÚÅ·ÃÀµØÇø¡£
ATK-ESP8266 Ä£¿é²ÉÓô®¿Ú(LVTTL)Óë MCU(»òÆäËû´®¿ÚÉ豸)ͨÐÅ£¬ÄÚÖà TCP/IP ЭÒéÕ»£¬Äܹ»ÊµÏÖ´®¿ÚÓë WIFI Ö®¼äµÄת»»¡£
ͨ¹ý ATK-ESP8266 Ä£¿é£¬´«Í³µÄ´®¿ÚÉ豸ֻÊÇÐèÒª¼òµ¥µÄ´®¿ÚÅäÖ㬼´¿Éͨ¹ýÍøÂç (WIFI)´«Êä×Ô¼ºµÄÊý¾Ý¡£
ATK-ESP8266 Ä£¿éÖ§³Ö LVTTL ´®¿Ú£¬¼æÈÝ 3.3V ºÍ 5V µ¥Æ¬»úϵͳ£¬¿ÉÒԺܷ½±ãµÄÓëÄ㠵IJúÆ·½øÐÐÁ¬½Ó¡£Ä£¿éÖ§³Ö´®¿Úת WIFI STA¡¢´®¿Úת AP ºÍ WIFI STA+WIFI AP µÄģʽ£¬´Ó ¶ø¿ìËÙ¹¹½¨´®¿Ú-WIFI Êý¾Ý´«Êä·½°¸£¬·½±ãÄãµÄÉ豸ʹÓû¥ÁªÍø´«ÊäÊý¾Ý¡£
ATK-ESP8266 Ä£¿é·Ç³£Ð¡ÇÉ(29mm*19mm)£¬Ä£¿éͨ¹ý 6 ¸ö 2.54mm ¼ä¾àµÄÅÅÕëÓëÍâ ²¿Á¬½Ó£¬Ä£¿éÍâ¹ÛÈçͼ 1.1 Ëùʾ:
ͼ 1.1 ATK-ESP8266 Ä£¿éÍâ¹Ûͼ ͼ 1.1 ÖУ¬¸÷Òý½ÅµÄÏêϸÃèÊöÈç±í 1.1 Ëùʾ:

ÐòºÅ
Ãû³Æ
˵Ã÷
1
VCC
µçÔ´(3.3V~5V)
2
GND
µçÔ´µØ
3
TXD
Ä£¿é´®¿Ú·¢ËͽÅ(TTL µçƽ£¬²»ÄÜÖ±½Ó½Ó RS232 µçƽ!)£¬¿É½Óµ¥Æ¬»úµÄ RXD
4
TXD
Ä£¿é´®¿Ú½ÓÊÕ½Å(TTL µçƽ£¬²»ÄÜÖ±½Ó½Ó RS232 µçƽ!)£¬¿É½Óµ¥Æ¬»úµÄ TXD
5
RST
¸´Î»(µÍµçƽÓÐЧ)
6
IO_0
ÓÃÓÚ½øÈë¹Ì¼þÉÕдģʽ£¬µÍµçƽÊÇÉÕдģʽ£¬¸ßµçƽÊÇÔËÐÐģʽ(ĬÈÏ״̬)
±í 1.1 ATK-ESP8266 Ä£¿é¸÷Òý½Å¹¦ÄÜÃèÊö ATK-ESP8266 WIFI Ä£¿éµÄÔ­ÀíͼÈçͼ 1.2 Ëùʾ:
ͼ 1.2 ATK-ESP8266 WIFI Ä£¿éÔ­Àíͼ
1.1 Ä£¿éʹÓÃ
±¾Îĵµ£¬ÎÒÃǽ«½éÉÜ´ó¼ÒÈçºÎͨ¹ý ALIENTEK Mini STM32F103 ¿ª·¢°åÁ¬½Óµ½ ATK-ESP8266 WIFI Ä£¿é£¬ÊµÏÖ:´®¿ÚÎÞÏß AP(COM-AP)¡¢´®¿ÚÎÞÏß STA(COM-STA)ºÍ ´®¿ÚÎÞÏß AP+STA(COM-AP+STA)Õâ 3 ¸öģʽµÄ²âÊÔ£¬Ã¿¸öģʽÓÖ°üº¬ TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶ËºÍ UDP Õâ 3 ¸ö×Óģʽ£¬±¾½ÚÎÒÃǽ«Ïêϸ½éÉÜÕâЩģʽµÄʹÓá£
Ä£¿éÅäÖÿÉÒÔͨ¹ý´®¿ÚÅäÖã¬ÕâÀïÎÒÃÇͨ¹ý¿ª·¢°å´®¿ÚÅäÖ㬲¢ÊµÏÖͨÐÅ¡£
1.1.1 AT Ö¸Áî¼ò½é
ÔÚ AT ģʽÏ¿ÉÒÔͨ¹ý´®¿ÚµÄ AT Ö¸Áî¶Ôϵͳ²ÎÊý×öÅäÖá£Ö¸Áî¸ñʽÈçÏÂ: AT+=\r\n
¸ù¾Ý²»Í¬Ö¸Áģ¿é½«·µ»Ø²»Í¬µÄ·µ»ØÖµ¡£ÆäÖÐ\r\n Ϊ»Ø³µ»»Ðзû£¬Óà 16 ½øÖƱíʾ£¬ ¾ÍÊÇ 0X0D£¬0X0A¡£

ÀýÈç:¡°AT+CWMODE?\r\n¡±²éѯµ±Ç°Ä£¿éµÄ WIFI ģʽ¡£ ÀýÈç:¡°AT+CWMODE=3\r\n¡±ÉèÖÃÄ£¿é WIFI ģʽΪ AP+STA ģʽ¡£ ATK-ESP8266 Ä£¿éÖ§³ÖµÄÖ¸ÁîÁбíÈç±í 1.1.1.1 Ëùʾ:
RST
ÖØÆôÄ£¿é
GMR
²é¿´Ä£¿é°æ±¾ÐÅÏ¢
CWMODE
ÉèÖÃÄ£¿é WIFI ģʽ
CWJAP
ÉèÖÃÄ£¿é¼ÓÈë AP Èȵã
CWLAP
ÁÐ±íµ±Ç°¿ÉÓà AP Èȵã
CWQAP
Í˳öµ±Ç°Á¬½ÓµÄ AP Èȵã
CWSAP
ÉèÖà AP ģʽÏ嵀 WIFI ²ÎÊý
CWLIF
²é¿´ÒѽÓÈëÉ豸µÄ IP
CIPSTATUS
»ñµÃÁ¬½Ó״̬
CIPSTART
½¨Á¢ TCP Á¬½Ó»ò×¢²á UDP ¶Ë¿ÚºÅ
CIPSEND
·¢ËÍÊý¾Ý
CIPCLOSE
¹Ø±ÕTCP»òUDP
CIFSR
»ñÈ¡±¾µØ IP µØÖ·
CIPMUX
Æô¶¯¶àÁ¬½Ó
CIPSERVER
ÅäÖÃΪ·þÎñÆ÷
CIPMODE
ÉèÖÃÄ£¿é´«Ê䷽ʽ
CIPSTO
ÉèÖ÷þÎñÆ÷³¬Ê±Ê±¼ä
CIUPDATE
ÍøÂç¹Ì¼þÉý¼¶
±í 1.1.1.1ATK-ESP8266 Ä£¿é AT Ö¸Áî±í 1.1.2 ´®¿ÚÎÞÏß WIFI(COM-AP)
´®¿ÚÎÞÏß WIFI(COM-AP)ģʽ£¬Ä£¿é×÷ΪÎÞÏß WIFI Èȵ㣬ÔÊÐíÆäËû WIFI É豸Á¬½Ó µ½±¾Ä£¿é£¬ÊµÏÖ´®¿ÚÓëÆäËûÉ豸֮¼äµÄÎÞÏß(WIFI)Êý¾Ýת»»»¥´«¡£¸ÃģʽÏ£¬¸ù¾ÝÓ¦Óà ³¡¾°µÄ²»Í¬£¬¿ÉÒÔÉèÖà 3 ¸ö×Óģʽ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë£¬UDP¡£
½ÓÏÂÀ´¿´¿´ÈçºÎÌý¹ý AT Ö¸ÁîÅäÖÃÄ£¿é£¬´ïµ½ÎÒÃÇËùÒªµÄ¹¦ÄÜ£¬ÕâÀï½öÁгö±ØÒªÅäÖ㬠ÅäÖÃ×¼±¸:1£¬Ä£¿é´¦ÓÚĬÈÏÉèÖÃ(¼´³ö³§ÉèÖÃ);2£¬×¼±¸Ò»¸ö´ø WIFI ¹¦ÄܵÄÉ豸£¬ÈçÖÇ ÄÜÊÖ»ú¡¢PAD¡¢±Ê¼Ç±¾µçÄԵȡ£
´®¿ÚÎÞÏß WIFI AP ģʽ£¬TCP ·þÎñÆ÷ÅäÖã¬Èç±í 1.1.2.1 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=2
ÉèÖÃÄ£¿é WIFI ģʽΪ AP ģʽ
AT+RST
ÖØÆôÉúЧ
AT+CWSAP=¡±ATK-ESP8266¡±,¡± 12345678¡±,1,4
ÉèÖÃÄ£¿éµÄ AP ²ÎÊý:SSID Ϊ ATK-ESP8266£¬ÃÜÂëΪ 12345678£¬Í¨µÀºÅΪ 1£¬¼ÓÃÜ·½Ê½Îª:WPA_WPA2_PSK
AT+CIPMUX=1
¿ªÆô¶àÁ¬½Ó
AT+CIPSERVER=1,8086
¿ªÆô SERVER ģʽ£¬ÉèÖö˿ÚΪ 8086
AT+CIPSEND=0,25
Ïò ID0 ·¢ËÍ 25 ×Ö½ÚÊý¾Ý°ü
±í 1.1.2.1 ´®¿ÚÎÞÏß WIFI AP TCP ·þÎñÆ÷ÅäÖà ´®¿ÚÎÞÏß WIFI AP ģʽ£¬TCP ¿Í»§¶ËÅäÖã¬Èç±í 1.1.2.2 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=2
ÉèÖÃÄ£¿é WIFI ģʽΪ AP ģʽ

AT+RST
ÖØÆôÉúЧ
AT+CWSAP=¡±ATK-ESP8266¡±,¡± 12345678¡±,1,4
ÉèÖÃÄ£¿éµÄ AP ²ÎÊý:SSID Ϊ ATK-ESP8266£¬ÃÜÂëΪ 12345678£¬Í¨µÀºÅΪ 1£¬¼ÓÃÜ·½Ê½Îª:WPA_WPA2_PSK
AT+CIPMUX=0
¿ªÆôµ¥Á¬½Ó
AT+CIPSTART=”TCP”,”192.168 .4.XXX¡±,8086
½¨Á¢ TCP Á¬½Óµ½¡± 192.168.4.XXX¡±,8086
AT+CIPMODE=1
¿ªÆô͸´«Ä£Ê½(½öµ¥Á¬½Ó client ʱ֧³Ö)
AT+CIPSEND
¿ªÊ¼·¢ËÍÊý¾Ý
±í 1.1.2.2 ´®¿ÚÎÞÏß WIFI AP ģʽ TCP ¿Í»§¶ËÅäÖà ´®¿ÚÎÞÏß WIFI AP ģʽ£¬UDP ÅäÖã¬Èç±í 1.1.2.3 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=2
ÉèÖÃÄ£¿é WIFI ģʽΪ AP ģʽ
AT+RST
ÖØÆôÉúЧ
AT+CWSAP=¡±ATK-ESP8266¡±,¡± 12345678¡±,1,4
ÉèÖÃÄ£¿éµÄ AP ²ÎÊý:SSID Ϊ ATK-ESP8266£¬ÃÜÂëΪ 12345678£¬Í¨µÀºÅΪ 1£¬¼ÓÃÜ·½Ê½Îª:WPA_WPA2_PSK
AT+CIPMUX=0
¿ªÆôµ¥Á¬½Ó
AT+CIPSTART=”UDP”,”192.168 .4.XXX”,8086
½¨Á¢ UDP Á¬½Óµ½¡±192.168.4.XXX¡±,8086
AT+CIPSEND=25
ÏòÄ¿±ê UDP ·¢ËÍ 25 ×Ö½ÚÊý¾Ý
±í 1.1.2.3 ´®¿ÚÎÞÏß WIFI AP ģʽ UDP ÅäÖà 1.1.3 ´®¿ÚÎÞÏß STA(COM-STA)
´®¿ÚÎÞÏß STA(COM-STA)ģʽ£¬Ä£¿é×÷ΪÎÞÏß WIFI STA£¬ÓÃÓÚÁ¬½Óµ½ÎÞÏßÍøÂ磬ʵ ÏÖ´®¿ÚÓëÆäËûÉ豸֮¼äµÄÎÞÏß(WIFI)Êý¾Ýת»»»¥´«¡£¸ÃģʽÏ£¬¸ù¾ÝÓ¦Óó¡¾°µÄ²»Í¬£¬ ¿ÉÒÔÉèÖà 3 ¸ö×Óģʽ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë£¬UDP¡£
½ÓÏÂÀ´¿´¿´ÈçºÎÌý¹ý AT Ö¸ÁîÅäÖÃÄ£¿é£¬´ïµ½ÎÒÃÇËùÒªµÄ¹¦ÄÜ£¬ÕâÀï½öÁгö±ØÒªÅäÖ㬠ÅäÖÃ×¼±¸:1£¬Ä£¿é´¦ÓÚĬÈÏÉèÖÃ(¼´³ö³§ÉèÖÃ);2£¬×¼±¸Ò»¸öÎÞÏß·ÓÉÆ÷£¬ÇÒ·ÓÉÆ÷¿ªÆô DHCP ·þÎñ¡£
´®¿ÚÎÞÏß STA ģʽ£¬TCP ·þÎñÆ÷ÅäÖã¬Èç±í 1.1.3.1 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=1
ÉèÖÃÄ£¿é WIFI ģʽΪ STA ģʽ
AT+RST
ÖØÆôÄ£¿é²¢ÉúЧ
AT+CWJAP=”ALIENTEK”, “15902020353”
¼ÓÈë WIFI Èȵã:ALIENTEK£¬ÃÜÂëΪ:15902020353
AT+CIPMUX=1
¿ªÆô¶àÁ¬½Ó
AT+CIPSERVER=1,8086
¿ªÆô·þÎñÆ÷£¬¶Ë¿ÚºÅΪ 8086
AT+CIPSEND=0,25
Ïò ID0 ·¢ËÍ 25 ×Ö½ÚµÄÊý¾Ý
±í 1.1.3.1 ´®¿ÚÎÞÏß STA ģʽ TCP ·þÎñÆ÷ÉèÖà ´®¿ÚÎÞÏß STA ģʽ£¬TCP ¿Í»§¶ËÅäÖã¬Èç±í 1.1.3.2 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=1
ÉèÖÃÄ£¿é WIFI ģʽΪ STA ģʽ
AT+RST
ÖØÆôÄ£¿é²¢ÉúЧ
AT+CWJAP=”ALIENTEK”,
¼ÓÈë WIFI Èȵã:ALIENTEK£¬ÃÜÂëΪ:15902020353

“15902020353”
AT+CIPMUX=0
¿ªÆôµ¥Á¬½Ó
AT+CIPSTART=”TCP”,”19 2.168.1.XXX”,8086
½¨Á¢ TCP Á¬½Óµ½¡± 192.168.1.XXX¡±,8086
AT+CIPMODE=1
¿ªÆô͸´«Ä£Ê½
AT+CIPSEND
¿ªÊ¼´«Êä
±í 1.1.3.2 ´®¿ÚÎÞÏß STA ģʽ TCP ¿Í»§¶ËÅäÖà ´®¿ÚÎÞÏß STA ģʽ£¬UDP ÅäÖã¬Èç±í 1.1.3.3 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=1
ÉèÖÃÄ£¿é WIFI ģʽΪ STA ģʽ
AT+RST
ÖØÆôÄ£¿é²¢ÉúЧ
AT+CWJAP=”ALIENTEK”, “15902020353”
½¨¼ÓÈë WIFI Èȵã:ALIENTEK£¬ÃÜÂëΪ:15902020353
AT+CIPMUX=0
¿ªÆôµ¥Á¬½Ó
AT+CIPSTART=”UDP”,”19 2.168.1.XXX”,8086
½¨Á¢ UDP Á¬½Óµ½¡± 192.168.4.XXX¡±,8086
AT+CIPSEND=25
ÏòÄ¿±ê UDP ·¢ËÍ 25 ×Ö½ÚÊý¾Ý
±í 1.1.3.3 ´®¿ÚÎÞÏß STA ģʽ UDP ÅäÖà 1.1.4 ´®¿ÚÎÞÏß AP+STA(COM-AP+STA)
´®¿ÚÎÞÏßAP+STA(COM-AP+STA)ģʽ£¬Ä£¿é¼È×÷ÎÞÏßWIFI AP£¬ÓÖ×÷ÎÞÏßSTA£¬ ÆäËû WIFI É豸¿ÉÒÔÁ¬½Óµ½¸ÃÄ£¿é£¬Ä£¿éÒ²¿ÉÒÔÁ¬½Óµ½ÆäËûÎÞÏßÍøÂ磬ʵÏÖ´®¿ÚÓëÆäËûÉ豸 Ö®¼äµÄÎÞÏß(WIFI)Êý¾Ýת»»»¥´«¡£¸ÃģʽÏ£¬¸ù¾ÝÓ¦Óó¡¾°µÄ²»Í¬£¬¿ÉÒÔÉèÖà 9 ¸ö×ÓÄ£ ʽ:(TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë£¬UDP)||(TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë£¬UDP)¡£
½ÓÏÂÀ´¿´¿´ÈçºÎÌý¹ý AT Ö¸ÁîÅäÖÃÄ£¿é£¬´ïµ½ÎÒÃÇËùÒªµÄ¹¦ÄÜ£¬ÕâÀï½öÁгö±ØÒªÅäÖ㬠ÅäÖÃ×¼±¸:1£¬Ä£¿é´¦ÓÚĬÈÏÉèÖÃ(¼´³ö³§ÉèÖÃ);2£¬×¼±¸Ò»¸ö´ø WIFI ¹¦ÄܵÄÉ豸£¬ÈçÖÇ ÄÜÊÖ»ú¡¢PAD¡¢±Ê¼Ç±¾µçÄÔµÈ;3£¬×¼±¸Ò»¸öÎÞÏß·ÓÉÆ÷£¬ÇÒ·ÓÉÆ÷¿ªÆô DHCP ·þÎñ¡£
ÏÂÃæ½ö½éÉÜ 3 ÖÖģʽ¡£AP ÏÂ×÷·þÎñÆ÷£¬STA µÄÈýÖÖģʽ¡£
´®¿ÚÎÞÏß AP+STA ģʽ£¬AP ×÷ TCP ·þÎñÆ÷£¬STA ×ö TCP ·þÎñÆ÷µÄÅäÖã¬Èç±í 1.1.4.1 Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=3
ÉèÖÃÄ£¿é WIFI ģʽΪ AP+STA
AT+RST
ÖØÆôÄ£¿é²¢ÉúЧ
AT+CWSAP=”ATK-ESP8266″,” 12345678″,1,4
¼ÓÈë WIFI Èȵã:ALIENTEK£¬ÃÜÂëΪ:15902020353
AT+CWJAP=”ALIENTEK”,”159 02020353″
ÉèÖÃÄ£¿éµÄ AP ²ÎÊý:SSID Ϊ ATK-ESP8266£¬ÃÜÂëΪ 12345678£¬Í¨µÀºÅΪ 1£¬¼ÓÃÜ·½Ê½Îª:WPA_WPA2_PSK
AT+CIPMUX=1
¿ªÆô¶àÁ¬½Ó
AT+CIPSERVER=1,8086
¿ªÆô·þÎñÆ÷£¬¶Ë¿ÚºÅ 8086
AT+CIPSTO=1200
ÉèÖ÷þÎñÆ÷³¬Ê±Ê±¼ä 1200s
AT+CIPSEND=0,25
Ïò ID0 ·¢ËÍÊý¾Ý
AT+CIPSEND=1,25
Ïò ID1 ·¢ËÍÊý¾Ý
±í 1.1.4.1 ´®¿ÚÎÞÏß AP+STA ģʽ AP ×÷ TCP ·þÎñÆ÷ STA ×÷ TCP ·þÎñÆ÷ÅäÖà ´®¿ÚÎÞÏß AP+STA ģʽ£¬AP ×÷ TCP ·þÎñÆ÷£¬STA ×÷ TCP ¿Í»§¶ËµÄÅäÖã¬Èç±í 1.1.4.2

Ëùʾ:
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=3
ÉèÖÃÄ£¿é WIFI ģʽΪ AP+STA
AT+RST
ÖØÆôÄ£¿é²¢ÉúЧ
AT+CWSAP=”ATK-ESP8266″,” 12345678″,1,4
¼ÓÈë WIFI Èȵã:ALIENTEK£¬ÃÜÂëΪ:15902020353
AT+CWJAP=”ALIENTEK”,”159 02020353″
ÉèÖÃÄ£¿éµÄ AP ²ÎÊý:SSID Ϊ ATK-ESP8266£¬ÃÜÂëΪ 12345678£¬Í¨µÀºÅΪ 1£¬¼ÓÃÜ·½Ê½Îª:WPA_WPA2_PSK
AT+CIPMUX=1
¿ªÆô¶àÁ¬½Ó
AT+CIPSERVER=1,8086
¿ªÆô·þÎñÆ÷£¬¶Ë¿ÚºÅ 8086
AT+CIPSTO=1200
ÉèÖ÷þÎñÆ÷³¬Ê±Ê±¼ä 1200s
AT+CIPSTART=0,”TCP”,”192.1 68.1.XXX”,8086
STA ×÷Ϊ ID0 Á¬½Óµ½ 192.168.1.XXX£¬8086
AT+CIPSEND=0,25
Ïò ID0 ·¢ËÍÊý¾Ý
AT+CIPSEND=1,25
Ïò ID1 ·¢ËÍÊý¾Ý
±í 1.1.4.2 ´®¿ÚÎÞÏß AP+STA ģʽ AP ×÷ TCP ·þÎñÆ÷ STA ×÷ TCP ¿Í»§¶ËÅäÖà ´®¿ÚÎÞÏß AP+STA ģʽ£¬AP ×÷ TCP ·þÎñÆ÷£¬STA ×÷ UDP µÄÅäÖã¬Èç±í 1.1.4.3 Ëùʾ
·¢ËÍÖ¸Áî
×÷ÓÃ
AT+CWMODE=3
ÉèÖÃÄ£¿é WIFI ģʽΪ AP+STA
AT+RST
ÖØÆôÄ£¿é²¢ÉúЧ
AT+CWSAP=”ATK-ESP8266″,” 12345678″,1,4
¼ÓÈë WIFI Èȵã:ALIENTEK£¬ÃÜÂëΪ:15902020353
AT+CWJAP=”ALIENTEK”,”159 02020353″
ÉèÖÃÄ£¿éµÄ AP ²ÎÊý:SSID Ϊ ATK-ESP8266£¬ÃÜÂëΪ 12345678£¬Í¨µÀºÅΪ 1£¬¼ÓÃÜ·½Ê½Îª:WPA_WPA2_PSK
AT+CIPMUX=1
¿ªÆô¶àÁ¬½Ó
AT+CIPSERVER=1,8086
¿ªÆô·þÎñÆ÷£¬¶Ë¿ÚºÅ 8086
AT+CIPSTO=1200
ÉèÖ÷þÎñÆ÷³¬Ê±Ê±¼ä 1200s
AT+CIPSTART=0,”UDP”,”192.1 68.1.XXX”,8086
STA ×÷Ϊ ID0 Á¬½Óµ½ 192.168.1.XXX£¬8086
AT+CIPSEND=0,25
Ïò ID0 ·¢ËÍÊý¾Ý
AT+CIPSEND=1,25
Ïò ID1 ·¢ËÍÊý¾Ý
±í 1.1.4.3 ´®¿ÚÎÞÏß AP+STA ģʽ AP ×÷ TCP ·þÎñÆ÷ STA ×÷ UDP ÅäÖà 2¡¢Ó²¼þÁ¬½Ó
2.1 ¹¦Äܼò½é
±¾ÊµÑ鹦Äܼò½é:±¾ÊµÑéÓÃÓÚ²âÊÔ ATK-ESP8266 Ä£¿é£¬×ܹ²°üÀ¨ 3 ´óÏî²âÊÔ£¬Ã¿´óÏî
ÓÖ°üÀ¨ 3 ¸ö×ÓģʽµÄ²âÊÔ£¬ÏÂÃæ·Ö±ð½éÉÜ¡£ 2.1.1 ´®¿ÚÎÞÏß WIFI(COM-AP)²âÊÔ
¸ÃÏî²âÊÔÍøÂçÁ¬½Ó·½Ê½:WIFI É豸<-------->1ATK-ESP8266 Ä£¿é
×¢1 :——–£¬±íʾͨ¹ýÎÞÏßÁ¬½Ó(WIFI)£¬ÏÂͬ
ͨ¹ý°´ KEY_UP ¼üÑ¡Ôñ´Ëģʽ£¬½øÈë´Ëģʽºó£¬Ê×ÏÈ»á½øÈëµ½´®¿Ú WIFI AP ¹¤×÷ģʽ

Ñ¡Ôñ½çÃ棬×ܹ²ÓÐ 3 ÖÖģʽ¿É¹©Ñ¡Ôñ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP¡£Í¨¹ý KEY0/KEY1 Ñ¡Ôñģʽ£¬Í¨¹ý KEY_UP È·¶¨¡£µã»÷È·¶¨ºó£¬·þÎñÆ÷ģʽ(TCP ·þÎñÆ÷)²»ÐèÒªÊÖ¶¯ÊäÈë IP µØÖ·£¬Ö±½Ó½øÈëÏÂÒ»²½£¬¿ªÊ¼ÅäÖÃÄ£¿é¡£µ«ÊǶÔÓÚ TCP ¿Í»§¶Ë/UDP ģʽ£¬»¹»áÐèÒªÊÖ¶¯ ÊäÈëÔ¶¶Ë IP µØÖ·£¬´Ëʱ½çÃæ»áÌáʾ:Ô¶¶Ë IP ÉèÖã¬Í¨¹ýÆÁÄ»ÏÔʾµÄÐéÄâ¼üÅÌ£¬ÊäÈëÔ¶¶Ë IP µØÖ·£¬ÊäÈëÍêºó£¬¿ÉÒÔµã»÷ÐéÄâ¼üÅ̵ġ°Á¬½Ó¡±°´¼ü£¬½øÈëÏÂÒ»²½£¬¿ªÊ¼ÅäÖÃÄ£¿é£¬´Ëʱ£¬ ¿ª·¢°å½«¶ÔÄ£¿é½øÐÐÅäÖã¬ÅäÖóɹ¦ºó£¬½øÈëÊý¾ÝÊÕ·¢²âÊÔ¡£
½øÈë²âÊԺ󣬿ª·¢°åÒº¾§»áÏÔʾÏà¹ØÌáʾÐÅÏ¢£¬·½±ã´ó¼Ò²âÊÔ£¬ÐÅÏ¢°üÀ¨:
IP µØÖ·:Èç¹ûÊÇ·þÎñÆ÷ģʽ£¬ÄÇô IP µØÖ·±íʾ ATK-ESP8266 Ä£¿éµÄ IP µØÖ·¡£Èç¹ûÊÇ ¿Í»§¶Ëģʽ£¬Ôò±íʾģ¿é½«ÒªÁ¬½Óµ½µÄÄ¿±ê IP µØÖ·¡£
¶Ë¿Ú:Ϊ·½±ã²âÊÔ£¬ËùÓÐģʽµÄ¶Ë¿Ú¶¼¹Ì¶¨Îª 8086¡£ ״̬:±íʾÁ¬½Ó״̬£¬Èç¹ûÁ¬½Ó½¨Á¢£¬ÔòÏÔʾÁ¬½Ó³É¹¦£¬Èç¹û¶Ï¿ª£¬ÔòÏÔʾÁ¬½Óʧ°Ü¡£ ģʽ:ÏÔʾµ±Ç°µÄ¹¤×÷ģʽ(TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP)¡£ ·¢ËÍÊý¾Ý:ÏÔʾµ±ÐèÒª·¢Ë͵ÄÊý¾Ý£¬Ã¿°´Ò»´Î KEY0£¬·¢ËÍÒ»´ÎÊý¾Ý£¬»áÔÚÕâ¸öÇøÓòÏÔ
ʾ·¢Ë͵ÄÄÚÈÝ£¬µ±·¢ËÍÍêÒԺ󣬹ýÒ»¶Îʱ¼ä£¬¸ÃÇøÓò×Ô¶¯Çå¿Õ¡£
½ÓÊÕÊý¾Ý:ÏÔʾ ATK-ESP8266 Ä£¿é½ÓÊÕµ½µÄÊý¾Ý£¬¶Ô·½·¢¹ýÀ´µÄÊý¾Ý£¬½«ÏÔʾÔÚÕâÀ
ÿ´ÎÊÕµ½ÐÂÄÚÈÝ£¬»á½«¾ÉÄÚÈÝÇå¿Õ£¬È»ºóÏÔʾÐÂÄÚÈÝ£¬·ñÔò¾ÉÄÚÈݽ«Ò»Ö±ÏÔʾ¡£
°´ KEY_UP£¬¿ÉÒÔÍ˳ö´ËÏî²âÊÔ£¬»Øµ½Ö÷½çÃæ¡£
¶ÔÓÚ 3 ÖÖ×Óģʽ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP£¬ËûÃǵÄÊý¾ÝÊÕ·¢²âÊÔ½çÃ漸ºõÊÇ
Ò»ÑùµÄ£¬²âÊÔ·½·¨Ò²¼¸ºõһģһÑù£¬´óͬСÒ죬ÎÒÃǾͲ»Ò»Ò»½éÉÜÁË£¬ÔÚµÚ 4 ²¿·Ö£¬ÎÒÃÇ»á Ïêϸ½éÉܲâÊÔ²½Öè¡£
2.1.2 ´®¿ÚÎÞÏß STA(COM-STA)²âÊÔ
¸ÃÏî²âÊÔÍøÂçÁ¬½Ó·½Ê½:WIFI É豸<------>ÎÞÏß·ÓÉÆ÷<------>ATK-ESP8266 Ä£¿é(WIFI STA)
ͨ¹ý°´ KEY1 ¼üÑ¡Ôñ´Ëģʽ£¬½øÈë´Ëģʽºó£¬Ê×ÏÈ»á½øÈëµ½ WIFI-STA ¹¤×÷ģʽѡÔñ½ç Ã棬ʣϵIJÙ×÷£¬Í¬ 2.1.1 ½ÚһģһÑù¡£
2.1.3 ´®¿ÚÎÞÏß AP+STA(COM-AP+STA)²âÊÔ
¸ÃÏî²âÊÔÍøÂçÁ¬½Ó·½Ê½:WIFI É豸<------> ATK-ESP8266 Ä£¿é(WIFI AP+STA)<------> ÎÞÏß·ÓÉÆ÷<------>WIFI É豸
ͨ¹ý°´ KEY0 ¼üÑ¡Ôñ´Ëģʽ£¬½øÈë´Ëģʽºó£¬Ê×ÏÈ»á½øÈëµ½Ìáʾ½çÃæ(ÇëÓÃÊÖ»úÁ¬½Ó µ½ ATK-ESP8266),È»ºó°´ÈÎÒâ¼ü¼ÌÐø£¬½Ó×Å»á½øÈëµ½ WIFI AP ģʽϵÄģʽѡÔñ£¬½Ó×Ų٠×÷Óë 2.1.1 ½ÚһģһÑù£¬Íê³É AP ģʽµÄÉèÖ㬽Ó×ÅÉèÖà STA ģʽ£¬Óë AP ģʽÏàËÆ¡£ÅäÖà ³É¹¦ºó£¬½øÈëÊý¾ÝÊÕ·¢²âÊÔ¡£
½øÈë²âÊԺ󣬿ª·¢°åÒº¾§»áÏÔʾÏà¹ØÌáʾÐÅÏ¢£¬ÐÅÏ¢Óë AP ģʽºÍ STA ģʽÓÐËù²î±ð¡£ ¶Ë¿Ú:Ϊ·½±ã²âÊÔ£¬ËùÓÐģʽµÄ¶Ë¿Ú¶¼¹Ì¶¨Îª 8086¡£ ״̬:±íʾÁ¬½Ó״̬£¬Èç¹ûÁ¬½Ó½¨Á¢£¬ÔòÏÔʾÁ¬½Ó³É¹¦£¬Èç¹û¶Ï¿ª£¬ÔòÏÔʾÁ¬½Óʧ°Ü¡£ ģʽ:ÏÔʾµ±Ç°µÄ¹¤×÷ģʽ(¹Ì¶¨ÏÔʾ:STA+AP ģʽ)¡£
AP IP:AP ģʽÏ嵀 IP µØÖ·¡£
STA IP:STA ģʽÏ嵀 IP µØÖ·¡£
·¢ËÍÊý¾Ý:ÏÔʾµ±ÐèÒª·¢Ë͵ÄÊý¾Ý£¬Ã¿°´Ò»´Î KEY0£¬·¢ËÍÒ»´ÎÊý¾Ý£¬»áÔÚÕâ¸öÇøÓòÏÔ
ʾ·¢Ë͵ÄÄÚÈÝ£¬µ±·¢ËÍÍêÒԺ󣬹ýÒ»¶Îʱ¼ä£¬¸ÃÇøÓò×Ô¶¯Çå¿Õ¡£
½ÓÊÕÊý¾Ý:ÏÔʾ ATK-ESP8266 Ä£¿é½ÓÊÕµ½µÄÊý¾Ý£¬¶Ô·½·¢¹ýÀ´µÄÊý¾Ý£¬½«ÏÔʾÔÚÕâÀ
ÿ´ÎÊÕµ½ÐÂÄÚÈÝ£¬»á½«¾ÉÄÚÈÝÇå¿Õ£¬È»ºóÏÔʾÐÂÄÚÈÝ£¬·ñÔò¾ÉÄÚÈݽ«Ò»Ö±ÏÔʾ¡£
°´ KEY_UP£¬¿ÉÒÔÍ˳ö´ËÏî²âÊÔ£¬»Øµ½Ö÷½çÃæ¡£°´ KEY0 Ïò ID0 ·¢ËÍÊý¾Ý£¬°´ KEY1

Ïò ID1 ·¢ËÍÊý¾Ý¡£
¶ÔÓÚ 9 ÖÖ×Óģʽ:(TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP)||(TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢
UDP)£¬ËûÃǵÄÊý¾ÝÊÕ·¢²âÊÔ½çÃ漸ºõÊÇÒ»ÑùµÄ£¬²âÊÔ·½·¨Ò²¼¸ºõһģһÑù£¬´óͬСÒ죬ÎÒ ÃǾͲ»Ò»Ò»½éÉÜÁË£¬ÔÚµÚ 4 ²¿·Ö£¬ÎÒÃÇ»áÏêϸ½éÉܲâÊÔ²½Öè¡£
2.2 Ó²¼þ×ÊÔ´×¼±¸
±¾ÊµÑéËùÐèÒªµÄÓ²¼þ×ÊÔ´ÈçÏÂ: 1£¬ Mini STM32F103 ¿ª·¢°å 1 ¸ö 2£¬ ATK-ESP8266 Ä£¿éÒ»¸ö
3£¬ ·ÓÉÆ÷Ò»¸ö
4£¬ WIFI É豸Á½¸ö(¿ÉÁ¬½Óµ½ WIFI Èȵã) 2.3 Ä£¿éÓ뿪·¢°æÁ¬½Ó
ATK-ESP8266 Ä£¿éµÄËùÓÐÊý¾Ý£¬¶¼ÊÇͨ¹ý´®¿ÚÀ´´«ÊäµÄ£¬ËùÒÔÎÒÃǵĿª·¢°åÓëÄ£¿éÁ¬ ½Ó£¬Ö»ÐèÒªÁ¬½Ó´®¿Ú¼´¿É(µ±È»Ò²Òª¹²µØ)£¬½ÓÏÂÀ´£¬ÎÒÃÇ¿´¿´Mini STM32F103¿ª·¢°åÓë ATK-ESP8266 Ä£¿éµÄÁ¬½Ó·½Ê½£¬±¾Àý³Ìͨ¹ý¿ª·¢°åµÄ´®¿Ú 2 Á¬½Ó AT-ESP8266 Ä£¿é¡£Á¬½ÓÈç ±í 2.3.1 Ëùʾ
±í 2.3.1 ATK-ESP8266 WIFI Ä£¿éͬ Mini STM32 ¿ª·¢°åÁ¬½Ó¹Øϵ±í ʹÓÃʱ£¬ÎÒÃÇÖ»ÐèÒª½«ATK-ESP8266 WIFIÄ£¿éͨ¹ý¶Å°îÏßÁ¬½Óµ½¿ª·¢°åµÄ´®¿Ú2¼´¿É£¬
Èçͼ 2.3.1 Ëùʾ:
ͼ 2.3.1ATK-ESP8266 WIFI Ä£¿éÓë Mini ¿ª·¢°æ¶Ô½ÓʵÎïͼ ×¢Ò⣬ RST ºÍ IO_0 ÔÚÕâÀïÎÒÃDz¢Ã»ÓÐÓõ½ÕâÁ½¸ö IO¡£
ATK-ESP8266 WIFI Ä£¿éÓ뿪·¢°åÁ¬½Ó¹Øϵ
ATK-ESP8266 WIFI Ä£¿é
VCC
GND
TXD
RXD
Mini STM32 ¿ª·¢°å
5V/3.3V
GND
PA3
PA2

3¡¢Èí¼þʵÏÖ
±¾ÊµÑéÔÚ Mini STM32 ¿ª·¢°åµÄÀ©Õ¹ÊµÑé 4(ATK-SIM900A GSM Ä£¿é²âÊÔʵÑé)»ù´¡ ÉϽøÐÐÐ޸ģ¬É¾³ýÔ­À´µÄ SIM900A Îļþ¼Ð£¬Ð½¨ ATK_ESP8266 Îļþ¼Ð£¬ÔÚÀïÃæн¨: common.c¡¢wifista¡¢wifiap¡¢apsta ºÍ common.h µÈÓÐÎļþ¡£
´ò¿ªÔ­¹¤³Ì£¬É¾³ý SIM900A ·Ö×飬²¢½« ATK_ESP8266 Îļþ¼ÐÀïÃæµÄ 4 ¸ö.c ÎļþÌí¼Ó µ½ ATK_ESP8266 ·Ö×飬²¢½« ATK_ESP8266 Îļþ¼Ð£¬¼ÓÈ뵽ͷÎļþ°üº¬Â·¾¶ÀïÃæ¡£
×îÖÕÈ¥µôÔ­¹¤³ÌµÄһЩδÓõ½µÄ.c Îļþ£¬×îÖÕ¹¤³ÌÈçͼ 3.1 Ëùʾ:
ͼ 3.1 ATK-ESP8266 Ä£¿é²âÊÔʵÑ鹤³Ì½Øͼ ±¾Àý³ÌÓÉÓÚ´úÂëÁ¿½Ï¶à£¬ÎÒÃǽö¶Ô ATK-ESP8266 Îļþ¼ÐÀïÃæµÄ²¿·Ö´úÂë(conmon.c¡¢ apsta.c¡¢wifista.c¡¢wifiap.c µÈ)£¬ÒÔ¼° main º¯Êý½øÐн²½â£¬ÆäËûµÄÇë´ó¼Ò²Î¿¼Ô´´úÂë×¢ÊÍ¡£ Ê×ÏÈ£¬common.c Îļþ£¬¸ÃÎļþÊÇÇý¶¯ ATK-ESP8266 Ä£¿éͨÐŵĵײã½Ó¿Úº¯Êý(AT Ö¸ ÁîµÄ·¢ËÍÓë½ÓÊÕ£¬Ä£¿é״̬¼ì²âµÈ)£¬ÒÔ¼°Ïà¹Øº¯ÊýÊäÈëÊä³öÏÔʾ(IP ÊäÈ롢ģʽѡÔñ¡¢Ä£
¿é״̬ÐÅÏ¢ÏÔʾµÈ)µÈ¡£½ÓÏÂÀ´£¬ÎÒÃǽéÉܼ¸¸öÖØÒªµÄº¯Êý¡£
µÚÒ»¸öÊÇ atk_8266_send_cmd º¯Êý£¬¸Ãº¯ÊýÓÃÓÚÏò ATK_ESP8266 Ä£¿é·¢ËÍ AT Ö¸Á
¸Ãº¯Êý´úÂëÈçÏÂ:

//Ïò ATK-ESP8266 ·¢ËÍÃüÁî
//cmd:·¢Ë͵ÄÃüÁî×Ö·û´® //ack:ÆÚ´ýµÄÓ¦´ð½á¹û,Èç¹ûΪ¿Õ,Ôò±íʾ²»ÐèÒªµÈ´ýÓ¦´ð //waittime:µÈ´ýʱ¼ä(µ¥Î»:10ms) //·µ»ØÖµ:0,·¢Ëͳɹ¦(µÃµ½ÁËÆÚ´ýµÄÓ¦´ð½á¹û)
// 1,·¢ËÍʧ°Ü
u8 atk_8266_send_cmd(u8 *cmd,u8 *ack,u16 waittime) {
u8 res=0;
USART2_RX_STA=0; u2_printf(“%s\r\n”,cmd); //·¢ËÍÃüÁî
if(ack&&waittime) //ÐèÒªµÈ´ýÓ¦´ð {
while(–waittime) //µÈ´ýµ¹¼Æʱ {
delay_ms(10); if(USART2_RX_STA&0X8000) {
if(atk_8266_check_cmd(ack)) {
printf(“ack:%s\r\n”,(u8*)ack); break;
}
USART2_RX_STA=0;
} }
if(waittime==0)res=1; }
return res;
//½ÓÊÕµ½ÆÚ´ýµÄÓ¦´ð½á¹û
//µÃµ½ÓÐЧÊý¾Ý
}
¸Ãº¯Êý´ø 3 ¸ö²ÎÊý£¬cmd ±íʾҪ·¢Ë͵ÄÖ¸Áî×Ö·û´®£¬ack ±íʾ·¢ËÍÖ¸ÁîºóÆÚ´ýµÃµ½µÄÓ¦ ´ð×Ö·û´®£¬waittime ±íʾµÈ´ýÓ¦´ðµÄʱ¼ä(µ¥Î»:10ms)£¬Èç:
atk_8288_send_cmd(“AT+RST”,”OK”,20);
±íʾ·¢ËÍÖ¸Áî:AT+RST µ½ WIFI Ä£¿é£¬ÖØÆôÄ£¿é;ÆÚ´ýµÄÓ¦´ðΪ:OK;µÈ´ýʱ¼äΪ 200ms¡£
µÚ¶þ¸öÊÇ atk_8266_quit_trans º¯Êý£¬¸Ãº¯ÊýÓÃÓÚ¿ØÖÆÄ£¿éÍ˳ö͸´«Ä£Ê½£¬½øÈë AT Ö¸Áî ģʽ¡£¸Ãº¯Êý´úÂëÈçÏÂ:
//ATK-ESP8266 Í˳ö͸´«Ä£Ê½ //·µ»ØÖµ:0,Í˳ö³É¹¦;
// 1,Í˳öʧ°Ü
u8 atk_8266_quit_trans(void)
{
USART2->DR=’+’;
//µÈ´ý·¢ËÍ¿Õ
while((USART2->SR&0X40)==0);

delay_ms(15);
while((USART2->SR&0X40)==0);
USART2->DR=’+’;
delay_ms(15);
while((USART2->SR&0X40)==0);
USART2->DR=’+’;
delay_ms(500);
return atk_8266_send_cmd(“AT”,”OK”,20);//Í˳ö͸´«ÅжÏ.
}
//´óÓÚ´®¿Ú×é֡ʱ¼ä(10ms) //µÈ´ý·¢ËÍ¿Õ
//´óÓÚ´®¿Ú×é֡ʱ¼ä(10ms) //µÈ´ý·¢ËÍ¿Õ
//µÈ´ý 500ms
Ä£¿éÍ˳ö͸´«Ä£Ê½Ö»ÓÐÒ»ÖÖ·½·¨£¬¾ÍÊÇÔÚ͸´«×´Ì¬Ï·¢ËÍ¡°+++¡±£¬¼´¿ÉÍ˳ö͸´«Ä£Ê½£¬ ½øÈë AT ģʽ¡£´ËʱµÄ AT ģʽÏÂÈç¹ûÉèÖÃÄ£¿éÖØÆô£¬Ä£¿éÓÖ»á×Ô¶¯½øÈë͸´«Ä£Ê½£¬ËùÒÔÔÚ ÖØÆôÄ£¿é֮ǰ£¬ÎÒÃÇÐèÒª·¢ËÍ¡°AT+CIPMODE=0¡±À´¹Ø±Õ͸´«Ä£Ê½£¬ÕâÑùÄ£¿éÖØÆôÖ®ºó¾Í ²»»á½øÈë AT ģʽÁË¡£
½ÓÏÂÀ´½éÉÜÈý¸ö²éѯº¯Êý:atk_8266_consta_check¡¢atk_8266_get_wanip ºÍ atk_8266_get_ip£¬ÕâÈý¸öº¯Êý´úÂëÈçÏÂ:
//»ñÈ¡ ATK-ESP8266 Ä£¿éµÄÁ¬½Ó״̬ //·µ»ØÖµ:0,δÁ¬½Ó;1,Á¬½Ó³É¹¦.
u8 atk_8266_consta_check(void)
{
u8 *p;
u8 res;
if(atk_8266_quit_trans())return 0; atk_8266_send_cmd(“AT+CIPSTATUS”,”:”,50); //·¢ËÍ AT+CIPSTATUS Ö¸Áî,²éѯÁ¬½Ó״̬ p=atk_8266_check_cmd(“+CIPSTATUS:”); res=*p;
return res;
}
//»ñÈ¡ STA »òÕß AP ģʽÏ嵀 ip µØÖ· //ipbuf:ip µØÖ·Êä³ö»º´æÇø
void atk_8266_get_wanip(u8* ipbuf)
{
//Í˳ö͸´«
//µÃµ½Á¬½Ó״̬
u8 *p,*p1; if(atk_8266_send_cmd(“AT+CIFSR”,”OK”,50)) {
ipbuf[0]=0;
return; }
p=atk_8266_check_cmd(“\””); p1=(u8*)strstr((const char*)(p+1),”\””); *p1=0;
sprintf((char*)ipbuf,”%s”,p+1);
}
//»ñÈ¡ AP+STA ip µØÖ·²¢ÔÚÖ¸¶¨Î»ÖÃÏÔʾ
//»ñÈ¡ WAN IP µØַʧ°Ü

//ipbuf:ip µØÖ·Êä³ö»º´æÇø void atk_8266_get_ip(u8 x,u8 y) {
u8 *p;
u8 *p1;
u8 *p2;
u8 *ipbuf;
u8 *buf; p=mymalloc(32); p1=mymalloc(32); p2=mymalloc(32);
//ÉêÇë 32 ×Ö½ÚÄÚ´æ //ÉêÇë 32 ×Ö½ÚÄÚ´æ //ÉêÇë 32 ×Ö½ÚÄÚ´æ
ipbuf=mymalloc(32);
buf=mymalloc(32); if(atk_8266_send_cmd(“AT+CIFSR”,”OK”,50)) {
*ipbuf=0; }
else {
//ÉêÇë 32 ×Ö½ÚÄÚ´æ //ÉêÇë 32 ×Ö½ÚÄÚ´æ //»ñÈ¡ WAN IP µØַʧ°Ü
p=atk_8266_check_cmd(“APIP,\””); p1=(u8*)strstr((const char*)(p+6),”\””); p2=p1;
*p1=0;
ipbuf=p+6;
sprintf((char*)buf,”AP IP:%s ¶Ë¿Ú:%s”,ipbuf,(u8*)portnum); Show_Str(x,y,200,12,buf,12,0);
//ÏÔʾ AP ģʽµÄ IP µØÖ·ºÍ¶Ë¿Ú
p=(u8*)strstr((const char*)(p2+1),”STAIP,\””); p1=(u8*)strstr((const char*)(p+7),”\””);
*p1=0;
ipbuf=p+7;
sprintf((char*)buf,”STA IP:%s ¶Ë¿Ú:%s”,ipbuf,(u8*)portnum);
} }
Show_Str(x,y+15,200,12,buf,12,0); //ÏÔʾ STA ģʽµÄ IP µØÖ·ºÍ¶Ë¿Ú
myfree(p); myfree(p1); myfree(p2); myfree(ipbuf); myfree(buf);
//ÊÍ·ÅÄÚ´æ //ÊÍ·ÅÄÚ´æ //ÊÍ·ÅÄÚ´æ //ÊÍ·ÅÄÚ´æ //ÊÍ·ÅÄÚ´æ
ÆäÖÐ atk_8266_consta_check º¯Êý£¬ÓÃÓÚ¼ì²éµ±Ç°Á¬½Ó(TCP/UDP)ÊÇ·ñ½¨Á¢(»ò´æÔÚ); atk_8266_get_wanip º¯Êý£¬ÓÃÓÚ»ñÈ¡Ä£¿é STA ģʽ»òÕß AP ģʽÏ嵀 IP µØÖ·¼° MAC µØÖ·; atk_8266_get_ip º¯Êý£¬ÓÃÓÚ»ñÈ¡Ä£¿é AP+STA ģʽÏ嵀 IP µØÖ·¼° MAC µØÖ·¡£

×îºóÎÒÃÇ¿´Ï atk_8266_test£¬¸Ãº¯Êý´úÂëÈçÏÂ:
//ATK-ESP8266 Ä£¿é²âÊÔÖ÷º¯Êý void atk_8266_test(void)
{
u8 key;
u8 timex;
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP8266 WIFI Ä£¿é²âÊÔ”,16,240); while(atk_8266_send_cmd(“AT”,”OK”,20)) //¼ì²é WIFI Ä£¿éÊÇ·ñÔÚÏß {
atk_8266_quit_trans();//Í˳ö͸´«
atk_8266_send_cmd(“AT+CIPMODE=0″,”OK”,200); Show_Str(40,55,200,16,”δ¼ì²âµ½Ä£¿é!!!”,16,0); delay_ms(800); LCD_Fill(40,55,200,55+16,WHITE); Show_Str(40,55,200,16,”³¢ÊÔÁ¬½ÓÄ£¿é…”,16,0);
}
atk_8266_mtest_ui(32,30); while(1)
{
delay_ms(10);
//¹Ø±Õ͸´«Ä£Ê½
//¹Ø±Õ»ØÏÔ
while(atk_8266_send_cmd(“ATE0″,”OK”,20));
atk_8266_at_response(1);
//¼ì²é ATK-ESP8266 Ä£¿é·¢Ë͹ýÀ´µÄÊý¾Ý,¼°Ê±ÉÏ´«¸øµçÄÔ key=KEY_Scan(0);
if(key)
{
LCD_Clear(WHITE); POINT_COLOR=RED; switch(key)
{
case 1://KEY0
Show_Str_Mid(0,30,”ATK-ESP WIFI-AP+STA ²âÊÔ”,16,240); Show_Str_Mid(0,50,”ÕýÔÚÅäÖà ATK-ESP8266 Ä£¿é£¬ÇëÉÔ µÈ…”,12,240);
atk_8266_apsta_test(); //AP+STA ²âÊÔ
break; case 2://KEY1
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str_Mid(0,50,”ÕýÔÚÅäÖà ATK-ESP8266 Ä£¿é£¬ÇëÉÔ µÈ…”,12,240);
atk_8266_wifista_test(); //WIFI STA ²âÊÔ break;
case 4://WK_UP

atk_8266_wifiap_test();
break; }
atk_8266_mtest_ui(32,30);
timex=0; }
if((timex%20)==0)LED0=!LED0;
timex++; }
}
//WIFI AP ²âÊÔ
//200ms ÉÁ˸
¸Ãº¯ÊýÊÇ ATK-ESP8266 Ä£¿é²âÊÔµÄÖ÷³ÌÐò£¬Ïȼì²éÄ£¿éÊÇ·ñ´æÔÚ£¬ÔÚ¼ì²âÄ£¿éÕý³£ºó£¬ È»ºó³õʼ»¯Ä£¿éΪ AP ģʽ£¬½Ó׎øÈëģʽѡÔñ½çÃ棬×îºóͨ¹ý°´¼üÑ¡Ôñ½øÈë¶ÔÓ¦µÄ×Ó¹¦ÄÜ ½øÐвâÊÔ£¬Í¨¹ýÈý¸ö×Ó¹¦ÄܲâÊÔº¯Êý:atk_8266_apsta_test¡¢atk_8266_wifista_test ºÍ atk_8266_wifiap_test ½øÐвâÊÔ¡£
common.c ÎÒÃǾͽéÉܵ½ÕâÀ½ÓÏÂÀ´£¬ÎÒÃÇ¿´¿´ apsta.c ÀïÃæµÄ´úÂ룬¸ÃÎļþÀïÃæ¾ÍÒ» ¸öº¯Êý:
//ATK-ESP8266 AP+STA ģʽ²âÊÔ //ÓÃÓÚ²âÊÔ TCP/UDP Á¬½Ó //·µ»ØÖµ:0,Õý³£
//ÆäËû,´íÎó´úÂë
u8 atk_8266_apsta_test(void) {
u8 netpro; u8 key=0;
u8 timex=0; u8 ipbuf[16]; u8 *p;
u16 t=999;
u8 res=0;
u16 rlen=0;
u8 constate=0; p=mymalloc(32);
//IP »º´æ //¼ÓËÙµÚÒ»´Î»ñÈ¡Á´½Ó״̬
//Á¬½Ó״̬
//ÉêÇë 32 ×Ö½ÚÄÚ´æ
atk_8266_send_cmd(“AT+CWMODE=3″,”OK”,50); //ÉèÖà WIFI AP+STA ģʽ //ÉèÖÃÄ£¿é AP ģʽµÄ WIFI ÍøÂçÃû³Æ/¼ÓÃÜ·½Ê½/ÃÜÂ룬Õ⼸¸ö²ÎÊý¿´×Ô¼ºÏ²ºÃÉèÖà sprintf((char*)p,”AT+CWSAP=\”%s\”,\”%s\”,1,4″,wifiap_ssid,wifiap_password); //ÉèÖÃÎÞÏß²ÎÊý:ssid,ÃÜÂë
atk_8266_send_cmd(p,”OK”,1000); //ÉèÖà AP ģʽ²ÎÊý
//ÉèÖÃÁ¬½Óµ½µÄ WIFI ÍøÂçÃû³Æ/¼ÓÃÜ·½Ê½/ÃÜÂë,Õ⼸¸ö²ÎÊýÐèÒª¸ù¾ÝÄú×Ô¼ºµÄ·ÓÉ Æ÷ÉèÖýøÐÐÐÞ¸Ä!!
sprintf((char*)p,”AT+CWJAP=\”%s\”,\”%s\””,wifista_ssid,wifista_password); //ÉèÖÃÎÞÏß²ÎÊý:ssid,ÃÜÂë
atk_8266_send_cmd(p,”WIFI GOT IP”,1000); //Á¬½ÓÄ¿±ê·ÓÉÆ÷£¬²¢»ñµÃ IP while(atk_8266_send_cmd(“AT+CIFSR”,”STAIP”,20)); //¼ì²âÊÇ·ñ»ñµÃ STA IP while(atk_8266_send_cmd(“AT+CIFSR”,”APIP”,20)); //¼ì²âÊÇ·ñ»ñµÃ AP IP

LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str(30,30,200,16,”ATK-ESP AP+STA ģʽ²âÊÔ”,16,0); atk_8266_send_cmd(“AT+CIPMUX=1″,”OK”,50); //0:µ¥Á¬½Ó£¬1:¶àÁ¬½Ó delay_ms(500);
sprintf((char*)p,”AT+CIPSERVER=1,%s”,(u8*)portnum); atk_8266_send_cmd(p,”OK”,50); //¿ªÆô Server ģʽ£¬¶Ë¿ÚºÅΪ 8086 delay_ms(500);
atk_8266_send_cmd(“AT+CIPSTO=1200″,”OK”,50); //ÉèÖ÷þÎñÆ÷³¬Ê±Ê±¼ä
PRESTA:
netpro=atk_8266_netpro_sel(50,30,(u8*)ATK_ESP8266_CWMODE_TBL[0]); //AP+STA ģʽÍøÂçģʽѡÔñ
if(netpro&0X02) //STA UDP
{
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); if(atk_8266_ip_set(“WIFI-STA Ô¶ ¶Ë UDP IP Éè Öà “,”UDP Ä£ ʽ
“,(u8*)portnum,ipbuf))goto PRESTA; //IP ÊäÈë sprintf((char*)p,”AT+CIPSTART=0,\”UDP\”,\”%s\”,%s”,ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±ê UDP ·þÎñÆ÷,¼° ID ºÅ£¬STA ģʽÏÂΪ 0
LCD_Clear(WHITE);
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); atk_8266_send_cmd(p,”OK”,200);
netpro=atk_8266_mode_cofig(netpro);
}
else //TCP {
if(netpro&0X01) //STA TCP Client
//AP ģʽÍøÂçģʽÅäÖÃ
{
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); if(atk_8266_ip_set(“WIFI-STA Ô¶¶Ë IP ÉèÖÃ
“,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],(u8*)portnum,ipbuf))goto PRESTA; //IP ÊäÈë
sprintf((char*)p,”AT+CIPSTART=0,\”TCP\”,\”%s\”,%s”,ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±ê TCP ·þÎñÆ÷,¼° ID ºÅ£¬STA ģʽÏÂΪ 0 while(atk_8266_send_cmd(p,”OK”,200))
{

LCD_Clear(WHITE);
POINT_COLOR=RED; Show_Str_Mid(0,40,”WK_UP:·µ»ØÖØÑ¡”,16,240); Show_Str(30,80,200,12,”ATK-ESP Á¬½Ó UDP ʧ°Ü”,12,0); //Á¬½Óʧ°Ü
key=KEY_Scan(0);
if(key==4)goto PRESTA; }
netpro=atk_8266_mode_cofig(netpro); else netpro=atk_8266_mode_cofig(netpro);
//AP ģʽÍøÂçģʽÅäÖà //TCP SERVER ²»ÓÃÅäÖÃ
}
}
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA+AP ²âÊÔ”,16,240); Show_Str(15,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); LCD_Fill(15,50,239,50+12,WHITE); //Çå³ý֮ǰµÄÏÔʾ Show_Str_Mid(0,50,”WK_UP:Í˳ö KEY0:ID0 ·¢ËÍ KEY1:ID1 ·¢ËÍ”,12,240); LCD_Fill(15,80,239,80+12,WHITE);
atk_8266_get_ip(15,65);//STA+AP ģʽ,»ñÈ¡ IP,²¢ÏÔʾ
Show_Str(15,95,200,12,”Á¬½Ó״̬:”,12,0);
Show_Str(15,110,200,12,”STA ģʽ:”,12,0);
Show_Str(120+15,110,200,12,”AP ģʽ:”,12,0); Show_Str(15,125,200,12,”·¢ËÍÊý¾Ý:”,12,0); Show_Str(15,140,200,12,”½ÓÊÕÊý¾Ý:”,12,0);
atk_8266_wificonf_show(15,195,” Çë Éè Öà · ÓÉ Æ÷ ÎÞ Ïß ²Î Êý
Ϊ:”,(u8*)wifista_ssid,(u8*)wifista_encryption,(u8*)wifista_password); POINT_COLOR=BLUE;
Show_Str(48+15,110,200,12,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro&0X03],12,0); //STA Á¬½Ó״̬
//Á¬½Ó״̬ //STA Á¬½Ó״̬ //AP Á¬½Ó״̬ //·¢ËÍÊý¾Ý //½ÓÊÕÊý¾Ý
Show_Str(162+15,110,200,12,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro>>4],12,0); //AP Á¬½Ó״̬
USART2_RX_STA=0; while(1)
{
key=KEY_Scan(0); if(key==4)
{
res=0;
break; }
else if(key==1)
//WK_UP Í˳ö²âÊÔ
/KEY0 Ïò ID0 ·¢ËÍÊý¾Ý

{
sprintf((char*)p,”ATK-8266 Ä£¿é ID0 ·¢Êý¾Ý%02d\r\n”,t/10); //²âÊÔÊý¾Ý
Show_Str(15+54,125,200,12,p,12,0); atk_8266_send_cmd(“AT+CIPSEND=0,25″,”OK”,200); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
delay_ms(200);
atk_8266_send_data(p,”OK”,100); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý timex=100;
}
else if(key==2) //KEY1 Ïò ID1 ·¢ËÍÊý¾Ý
{
{
sprintf((char*)p,”ATK-8266 Ä£¿é ID1 ·¢Êý¾Ý%02d\r\n”,t/10);//²âÊÔÊý¾Ý
Show_Str(15+54,125,200,12,p,12,0); atk_8266_send_cmd(“AT+CIPSEND=1,25″,”OK”,200); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
delay_ms(200);
atk_8266_send_data(p,”OK”,100);
timex=100; }
if(timex)timex–; if(timex==1)LCD_Fill(30+54,125,239,122,WHITE); t++;
delay_ms(10);
if(USART2_RX_STA&0X8000)
//·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
rlen=USART2_RX_STA&0X7FFF;
USART2_RX_BUF[rlen]=0;
printf(“%s”,USART2_RX_BUF);
sprintf((char*)p,”ÊÕµ½%d ×Ö½Ú,ÄÚÈÝÈçÏ”,rlen); //½ÓÊÕµ½µÄ×Ö½ÚÊý LCD_Fill(15+54,140,239,130,WHITE);
POINT_COLOR=BRED;
//½ÓÊÕµ½Ò»´ÎÊý¾ÝÁË
//µÃµ½±¾´Î½ÓÊÕµ½µÄÊý¾Ý³¤¶È //Ìí¼Ó½áÊø·û
//·¢Ë͵½´®¿Ú
//
Show_Str(15+54,140,156,12,p,12,0); //ÏÔʾ½ÓÊÕµ½µÄÊý¾Ý³¤¶È POINT_COLOR=BLUE;
LCD_Fill(15,155,239,319,WHITE); Show_Str(15,155,180,190,USART2_RX_BUF,12,0); //ÏÔʾ½ÓÊÕµ½µÄÊý¾Ý USART2_RX_STA=0;
if(constate!=’+’)t=1000; //״̬Ϊ»¹Î´Á¬½Ó,Á¢¼´¸üÐÂÁ¬½Ó״̬
else t=0; //״̬ΪÒѾ­Á¬½ÓÁË,10 ÃëºóÔÙ¼ì²é }
if(t==1000)//Á¬Ðø 10 ÃëÖÓûÓÐÊÕµ½ÈκÎÊý¾Ý,¼ì²éÁ¬½ÓÊDz»ÊÇ»¹´æÔÚ. {
LCD_Fill(15+54,125,239,138,WHITE); LCD_Fill(15+54,95,120,110,WHITE);

constate=atk_8266_consta_check();//µÃµ½Á¬½Ó״̬ if(constate==’+’)Show_Str(15+54,95,200,12,”Á¬½Ó³É¹¦”,12,0); else Show_Str(15+54,95,200,12,”Á¬½Óʧ°Ü”,12,0);
t=0;
//Á¬½Ó״̬
} if((t%20)==0)LED0=!LED0; atk_8266_at_response(1);
}
return res; }
myfree(p);
//ÊÍ·ÅÄÚ´æ
¸Ã´úÂ룬¾ÍʵÏÖÁ˶ÔÄ£¿é´®¿Ú AP+STA ģʽ¸÷¸ö×ÓģʽµÄ²âÊÔ(TCP ·þÎñÆ÷¡¢TCP ¿Í »§¶Ë¡¢UDP)¡£ÕâÀ¸Ãº¯Êý¸ù¾Ý²»Í¬µÄ×Óģʽ£¬°´ÕÕ 1.1.4 ½ÚµÄ 3 ¸ö±í¸ñÀïÃæµÄÖ¸ÁîÀ´¶Ô Ä£¿é½øÐÐÅäÖ㬴ӶøʵÏÖ 9 ÖÖ×ÓģʽÅäÖá£Ê×ÏÈÎÒÃǽøÐÐµÄ STA ģʽϵÄÅäÖ㬽Ó×Å²Å¶Ô AP ģʽ×÷ÅäÖ᣶ÔÓÚ TCP ¿Í»§¶Ë»òÕß UDP ģʽ£¬»¹»áÒªÇóÊäÈëÔ¶¶Ë IP µØÖ·£¬´Ëʱ£¬¿É ÒÔͨ¹ý´¥ÃþÆÁÊäÈëÔ¶¶Ë IP¡£
ÔÚÅäÖúÃÖ®ºó£¬½øÈëÊý¾ÝÊÕ·¢²âÊÔ£¬´ËʱÈç¹ûÁ¬½Ó³É¹¦½¨Á¢£¬ÎÒÃÇ¿ÉÒÔͨ¹ý°´ KEY0 ·¢ËÍÊý¾Ý¸ø ID0 µÄÉ豸£¬Í¨¹ý°´ KEY1 ·¢ËÍÊý¾Ý¸ø ID1£¬ÍⲿÉ豸·¢Ë͹ýÀ´µÄÊý¾Ý£¬½«ÏÔ Ê¾ÔÚ½ÓÊÕÊý¾ÝÇøÓò¡£Èç¹ûһֱûÓÐÊÕµ½Êý¾Ý£¬³ÌÐòÿ¸ô 10 Ãë»á¼ì²éÒ»´ÎÁ¬½ÓÊÇ·ñ´æÔÚ£¬²¢ ½«Á¬½Ó״̬ÏÔʾÔÚLCDÉÏ£¬Í¬Ê±DS0ÿ400msÉÁ˸һ´Î£¬Ìáʾ³ÌÐòÕýÔÚÔËÐС£°´KEY_UP °´¼ü£¬¿ÉÒÔÍ˳öµ±Ç°²âÊÔ£¬»Øµ½Ö÷½çÃæ¡£
apsta.c ÎÒÃǾͽéÉܵ½ÕâÀ½ÓÏÂÀ´£¬ÎÒÃÇ¿´ÄÇ¿´ÄÇ wifista.c ÀïÃæµÄ´úÂ룬¸ÃÎļþÀïÃæͬ ÑùÖ»ÓÐÒ»¸öº¯Êý:atk_8266_wifista_test£¬¸Ãº¯Êý´úÂëÈçÏÂ:
//ATK-ESP8266 WIFI STA ²âÊÔ //ÓÃÓÚ²âÊÔ TCP/UDP Á¬½Ó //·µ»ØÖµ:0,Õý³£ //ÆäËû,´íÎó´úÂë
u8 netpro=0; //ÍøÂçģʽ u8 atk_8266_wifista_test(void)
{
//u8 netpro=0; //ÍøÂçģʽ u8 key;
u8 timex=0;
u8 ipbuf[16];
u8 *p;
u16 t=999;
u8 res=0;
u16 rlen=0;
u8 constate=0;
p=mymalloc(32);
atk_8266_send_cmd(“AT+CWMODE=1″,”OK”,50); atk_8266_send_cmd(“AT+RST”,”OK”,20); //DHCP ·þÎñÆ÷¹Ø±Õ(½ö AP ģʽÓÐЧ) delay_ms(1000); //ÑÓʱ 3S µÈ´ýÖØÆô³É¹¦ delay_ms(1000);
//IP »º´æ //¼ÓËÙµÚÒ»´Î»ñÈ¡Á´½Ó״̬
//Á¬½Ó״̬
//ÉêÇë 32 ×Ö½ÚÄÚ´æ //ÉèÖà WIFI STA ģʽ

delay_ms(1000);
delay_ms(1000);
//ÉèÖÃÁ¬½Óµ½µÄ WIFI ÍøÂçÃû³Æ/¼ÓÃÜ·½Ê½/ÃÜÂë,Õ⼸¸ö²ÎÊýÐèÒª¸ù¾ÝÄú×Ô¼ºµÄ·ÓÉ
Æ÷ÉèÖýøÐÐÐÞ¸Ä!! sprintf((char*)p,”AT+CWJAP=\”%s\”,\”%s\””,wifista_ssid,wifista_password); //ÉèÖÃÎÞÏß²ÎÊý:ssid,ÃÜÂë
while(atk_8266_send_cmd(p,”WIFI GOT IP”,300)); //Á¬½ÓÄ¿±ê·ÓÉÆ÷,²¢ÇÒ»ñµÃ IP
PRESTA: netpro|=atk_8266_netpro_sel(50,30,(u8*)ATK_ESP8266_CWMODE_TBL[0]); //Ñ¡ÔñÍøÂçģʽ
if(netpro&0X02) //UDP {
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); if(atk_8266_ip_set(“WIFI-STA Ô¶ ¶Ë UDP IP Éè ÖÃ
“,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],(u8*)portnum,ipbuf))goto PRESTA; //IP ÊäÈë
} else {
delay_ms(200);
LCD_Clear(WHITE); while(atk_8266_send_cmd(p,”OK”,500));
//TCP
if(netpro&0X01) {
sprintf((char*)p,”AT+CIPSTART=\”UDP\”,\”%s\”,%s”,ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±ê UDP ·þÎñÆ÷
delay_ms(200);
atk_8266_send_cmd(“AT+CIPMUX=0″,”OK”,20);
//µ¥Á´½Óģʽ
//TCP Client ͸´«Ä£Ê½²âÊÔ
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); if(atk_8266_ip_set(“WIFI-STA Ô¶ ¶Ë IP Éè ÖÃ
“,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],(u8*)portnum,ipbuf))goto PRESTA; //IP ÊäÈë
atk_8266_send_cmd(“AT+CIPMUX=0″,”OK”,20); //0:µ¥Á¬½Ó£¬1:¶àÁ¬½Ó sprintf((char*)p,”AT+CIPSTART=\”TCP\”,\”%s\”,%s”,ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±ê TCP ·þÎñÆ÷
while(atk_8266_send_cmd(p,”OK”,200))

{
LCD_Clear(WHITE);
POINT_COLOR=RED; Show_Str_Mid(0,40,”WK_UP:·µ»ØÖØÑ¡”,16,240); Show_Str(30,80,200,12,”ATK-ESP Á¬½Ó TCP ʧ°Ü”,12,0); //Á¬½Óʧ°Ü
key=KEY_Scan(0);
if(key==4)goto PRESTA;
} atk_8266_send_cmd(“AT+CIPMODE=1″,”OK”,200); //´«ÊäģʽΪ:͸´«
} }
} else {
//TCP Server
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0); atk_8266_send_cmd(“AT+CIPMUX=1″,”OK”,20); //0:µ¥Á¬½Ó£¬1:¶àÁ¬½Ó sprintf((char*)p,”AT+CIPSERVER=1,%s”,(u8*)portnum);
//¿ªÆô Server ģʽ(0£¬¹Ø±Õ;1£¬´ò¿ª)£¬¶Ë¿ÚºÅΪ portnum atk_8266_send_cmd(p,”OK”,50);
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,”ATK-ESP WIFI-STA ²âÊÔ”,16,240); Show_Str(30,50,200,16,”ÕýÔÚÅäÖà ATK-ESP Ä£¿é,ÇëÉԵȅ”,12,0);
LCD_Fill(30,50,239,50+12,WHITE); //Çå³ý֮ǰµÄÏÔʾ Show_Str(30,50,200,16,”WK_UP:Í˳ö²âÊÔ KEY0:·¢ËÍÊý¾Ý”,12,0);
LCD_Fill(30,80,239,80+12,WHITE);
atk_8266_get_wanip(ipbuf); //·þÎñÆ÷ģʽ,»ñÈ¡ WAN IP sprintf((char*)p,”IP µØÖ·:%s ¶Ë¿Ú:%s”,ipbuf,(u8*)portnum);
Show_Str(30,65,200,12,p,12,0); Show_Str(30,80,200,12,”״̬:”,12,0); Show_Str(120,80,200,12,”ģʽ:”,12,0); Show_Str(30,100,200,12,”·¢ËÍÊý¾Ý:”,12,0); Show_Str(30,115,200,12,”½ÓÊÕÊý¾Ý:”,12,0); atk_8266_wificonf_show(30,180,” Çë Éè Öà · ÓÉ Æ÷
Ϊ:”,(u8*)wifista_ssid,(u8*)wifista_encryption,(u8*)wifista_password); POINT_COLOR=BLUE;
//ÏÔʾ IP µØÖ·ºÍ¶Ë¿Ú //Á¬½Ó״̬ //Á¬½Ó״̬ //·¢ËÍÊý¾Ý //½ÓÊÕÊý¾Ý
ÎÞ Ïß ²Î Êý

Show_Str(120+30,80,200,12,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],12,0); //Á¬½Ó״̬
USART2_RX_STA=0; while(1)
{
key=KEY_Scan(0); if(key==4)
{
//WK_UP Í˳ö²âÊÔ
res=0;
atk_8266_quit_trans(); //Í˳ö͸´« atk_8266_send_cmd(“AT+CIPMODE=0″,”OK”,20);
//¹Ø±Õ͸´«Ä£Ê½
break; }
else if(key==1) //KEY0 ·¢ËÍÊý¾Ý {
if((netpro==3)||(netpro==2)) //UDP {
sprintf((char*)p,”ATK-8266%s ²â ÊÔ%02d\r\n”,ATK_ESP8266_WORKMODE_TBL[netpro],t/10);
//²âÊÔÊý¾Ý
Show_Str(30+54,100,200,12,p,12,0); atk_8266_send_cmd(“AT+CIPSEND=25″,”OK”,200); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
delay_ms(200);
atk_8266_send_data(p,”OK”,100); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
timex=100; }
else if((netpro==1)) //TCP Client {
atk_8266_quit_trans(); atk_8266_send_cmd(“AT+CIPSEND”,”OK”,20);
//¿ªÊ¼Í¸´«
sprintf((char*)p,”ATK-8266%s ²â ÊÔ%d\r\n”,ATK_ESP8266_WORKMODE_TBL[netpro],t/10);
//²âÊÔÊý¾Ý
//²âÊÔÊý¾Ý
} else {
Show_Str(30+54,100,200,12,p,12,0); u2_printf(“%s”,p);
timex=100;
//TCP Server
sprintf((char*)p,”ATK-8266%s ²â ÊÔ%02d\r\n”,ATK_ESP8266_WORKMODE_TBL[netpro],t/10);
Show_Str(30+54,100,200,12,p,12,0);

atk_8266_send_cmd(“AT+CIPSEND=0,25″,”OK”,200); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
delay_ms(200);
atk_8266_send_data(p,”OK”,100); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý timex=100;
} }else;
if(timex)timex–; if(timex==1)LCD_Fill(30+54,100,239,112,WHITE); t++;
delay_ms(10);
if(USART2_RX_STA&0X8000) //½ÓÊÕµ½Ò»´ÎÊý¾ÝÁË {
rlen=USART2_RX_STA&0X7FFF; ¡¢ //µÃµ½±¾´Î½ÓÊÕµ½µÄÊý¾Ý³¤¶È
USART2_RX_BUF[rlen]=0; //Ìí¼Ó½áÊø·û printf(“%s”,USART2_RX_BUF); //·¢Ë͵½´®¿Ú sprintf((char*)p,”ÊÕµ½%d ×Ö½Ú,ÄÚÈÝÈçÏ”,rlen);//½ÓÊÕµ½µÄ×Ö½ÚÊý LCD_Fill(30+54,115,239,130,WHITE);
POINT_COLOR=BRED; Show_Str(30+54,115,156,12,p,12,0); //ÏÔʾ½ÓÊÕµ½µÄÊý¾Ý³¤¶È POINT_COLOR=BLUE; LCD_Fill(30,130,239,319,WHITE); Show_Str(30,130,180,190,USART2_RX_BUF,12,0); //ÏÔʾ½ÓÊÕµ½µÄÊý¾Ý
USART2_RX_STA=0;
if(constate!=’+’)t=1000; //״̬Ϊ»¹Î´Á¬½Ó,Á¢¼´¸üÐÂÁ¬½Ó״̬ else t=0; //״̬ΪÒѾ­Á¬½ÓÁË,10 ÃëºóÔÙ¼ì²é
}
if(t==1000)//Á¬Ðø 10 ÃëÖÓûÓÐÊÕµ½ÈκÎÊý¾Ý,¼ì²éÁ¬½ÓÊDz»ÊÇ»¹´æÔÚ. {
myfree(p);
return res; }
//ÊÍ·ÅÄÚ´æ
constate=atk_8266_consta_check();//µÃµ½Á¬½Ó״̬ if(constate==’+’)Show_Str(30+30,80,200,12,”Á¬½Ó³É¹¦”,12,0); //Á¬½Ó״̬
else Show_Str(30+30,80,200,12,”Á¬½Óʧ°Ü”,12,0);
t=0; }
if((t%20)==0)LED0=!LED0;
atk_8266_at_response(1); }

´Ë²¿·Ö´úÂë±È apsta.c ÉÙÁ˺ܶ࣬Ö÷ÒªÉÙÁË AP ģʽµÄÅäÖã¬ÆäËû²¿·Ö²Ù×÷Óë apsta.c ²Ù ×÷²î²»¶à¡£ÔÚ´ËģʽÏÂÖ»ÓÐ 3 ÖÖ×Óģʽ(TCP ·þÎñÆ÷£¬TCP ¿Í»§¶ËºÍ UDP)£¬¸ÃģʽÏÂÄ£¿é ÐèÁ¬½Óµ½Ö¸¶¨ WIFI Èȵ㣬´úÂëÀïÃæÎÒÃÇÊÇÁ¬½Óµ½ÎÒÃǵÄ·ÓÉÆ÷£¬ÈçÐèÁ¬½Óµ½¿Í»§×Ô¼ºµÄ WIFI ÈȵãÖ»ÐèÐÞ¸ÄÈçÏ´úÂë¼´¿É¡£
ÕâÀïµÄÅäÖ㬸æËßÄ£¿é£¬ÎÒÃÇÒªÁ¬½ÓµÄ WIFI Èȵ㣬SSID Ϊ:ALIENTEK;¼ÓÃÜ·½Ê½ Ϊ:WPA/WPA2_AES;ÃÜÂëΪ:15902020353¡£Õ⼸¸öºìÉ«µÄ²ÎÊý£¬µÃ¸ù¾ÝÄúµÄ·ÓÉÆ÷Éè ÖÃÕýÈ·²ÅÐС£
wifista.c ÎÒÃǾͽéÉܵ½ÕâÀ½ÓÏÂÀ´£¬ÎÒÃÇ¿´¿´ wifiap.c ÀïÃæµÄ´úÂ룬¸ÃÎļþÀïÃæͬÑù Ö»ÓÐÒ»¸öº¯Êý:atk_8266_wifiap_test£¬¸Ãº¯Êý´úÂëÈçÏÂ:
//WIFI STA ģʽ,ÉèÖÃҪȥÁ¬½ÓµÄ·ÓÉÆ÷ÎÞÏß²ÎÊý,Çë¸ù¾ÝÄãµÄ·ÓÉÆ÷ÉèÖÃ,×ÔÐÐÐÞ¸Ä.
const u8* wifista_ssid=”ALIENTEK”;
const u8* wifista_encryption=”wpawpa2_aes”; const u8* wifista_password=”15902020353″;
//·ÓÉÆ÷ SSID ºÅ //wpa/wpa2 aes ¼ÓÃÜ·½Ê½ //Á¬½ÓÃÜÂë
//ATK-ESP8266 WIFI AP ²âÊÔ //ÓÃÓÚ²âÊÔ TCP/UDP Á¬½Ó //·µ»ØÖµ:0,Õý³£
// ÆäËû,´íÎó´úÂë
u8 atk_8266_wifiap_test(void) {
u8 netpro=0; u8 key;
u8 timex=0; u8 ipbuf[16]; u8 *p;
return res; }
//ÍøÂçģʽ
//IP »º´æ //¼ÓËÙµÚÒ»´Î»ñÈ¡Á´½Ó״̬
//ÉêÇë 32 ×Ö½ÚÄÚ´æ //Ê¡ÂÔ²¿·Ö´úÂë
u16 t=999;
u8 res=0;
u16 rlen=0;
u8 constate=0; p=mymalloc(SRAMIN,32); ……………
//Á¬½Ó״̬
ÒÔÉÏ´úÂ룬ÎÒÃÇÊ¡ÂÔÁ˴󲿷ÖÓë´®¿Ú STA ģʽÀàËƵĴúÂ룬½öÁгöÁ˹ؼüÇø±ð´úÂë¡£ ÆäÖÐ AT+CWSAP Ö¸ÁîµÄ²ÎÊý:wifiap_ssid,wifiap_encryption,wifiap_password µÈÊÇÔÚ common.c ÀïÃ涨ÒåµÄ×Ö·û´®£¬ÈçÏÂ:
//WIFI AP ģʽ,Ä£¿é¶ÔÍâµÄÎÞÏß²ÎÊý,¿É×ÔÐÐÐÞ¸Ä.
const u8* wifiap_ssid=”ATK-ESP8266″;
const u8* wifiap_encryption=”wpawpa2_aes”;
const u8* wifiap_password=”12345678″;
ÒÔÉÏÅäÖã¬ÉèÖÃÄ£¿éµÄ¶ÔÍâÎÞÏß²ÎÊý£¬ÆäÖÐ SSID Ϊ:ATK-ESP8266;¼ÓÃÜ·½Ê½Îª:
WPA/WPA2_AES;ÃÜÂëΪ:12345678¡£
Õû¸ö´úÂëʵÏÖÁ˶ÔÄ£¿é´®¿ÚÎÞÏß AP(COM-WIFI AP)ģʽ¸÷¸ö×ÓģʽµÄ²âÊÔ(TCP ·þ
ÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP)¡£ÕâÀ¸Ãº¯Êý¸ù¾Ý²»Í¬µÄ×Óģʽ£¬°´ÕÕ 1.1.2 ½ÚµÄ 3 ¸ö±í¸ñÀï ÃæµÄÖ¸ÁîÀ´¶ÔÄ£¿é½øÐÐÅäÖ㬴ӶøʵÏÖ×ÓģʽÅäÖ᣶ÔÓÚ¿Í»§¶Ëģʽ£¬»¹»áÒªÇóÊäÈëÔ¶¶Ë
//¶ÔÍâ SSID ºÅ //wpa/wpa2 aes ¼ÓÃÜ·½Ê½ //Á¬½ÓÃÜÂë

IP µØÖ·£¬´Ëʱ£¬¿ÉÒÔͨ¹ý´¥ÃþÆÁÊäÈëÔ¶¶Ë IP¡£
ʣϵĴ¦Àí£¬Í¬´®¿Ú STA(COM-STA)ģʽµÄ´¦Àí·½Ê½¡£
wifista.c ÎÒÃǾͽéÉܵ½ÕâÀ×îºóÔÙÀ´¿´¿´ test.c£¬¸ÃÎļþÀïÃæ¾ÍÒ»¸ö main º¯Êý£¬main
º¯Êý´úÂëÈçÏÂ:
int main(void) {
u8 key,fontok=0; Stm32_Clock_Init(9); delay_init(72); uart_init(72,115200); USART2_Init(36,115200);
//ϵͳʱÖÓÉèÖà //ÑÓʱ³õʼ»¯ //´®¿Ú 1 ³õʼ»¯
//´®¿Ú 3 ³õʼ»¯
LCD_Init(); LED_Init(); KEY_Init(); usmart_dev.init(72); TP_Init();
mem_init(); exfuns_init(); f_mount(fs[0],”0:”,1); f_mount(fs[1],”1:”,1); key=KEY_Scan(0); if(key==KEY0_PRES) {
LCD_Clear(WHITE); TP_Adjust(); TP_Save_Adjdata(); LCD_Clear(WHITE);
//³õʼ»¯Òº¾§
//LED ³õʼ»¯
//°´¼ü³õʼ»¯
//usmart ³õʼ»¯ //³õʼ»¯´¥ÃþÆÁ //³õʼ»¯ÄÚ´æ¹ÜÀí
//Ϊ fatfs Ïà¹Ø±äÁ¿ÉêÇëÄÚ´æ //¹ÒÔØ SD ¿¨
//¹ÒÔØ FLASH. //Ç¿ÖÆУ׼
//ÇåÆÁ //ÆÁĻУ׼
//ÇåÆÁ
//¼ì²é×Ö¿âÊÇ·ñ OK
//ÐèÒª¸üÐÂ×Ö¿â //ÇåÆÁ
}
fontok=font_init(); if(fontok||key==KEY1_PRES) {
LCD_Clear(WHITE);
POINT_COLOR=RED; //ÉèÖÃ×ÖÌåΪºìÉ« LCD_ShowString(60,50,200,16,16,”ALIENTEK STM32″); while(SD_Initialize()) //¼ì²â SD ¿¨
{
LCD_ShowString(60,70,200,16,16,”SD Card Failed!”); delay_ms(200); LCD_Fill(60,70,200+60,70+16,WHITE); delay_ms(200);
}
LCD_ShowString(60,70,200,16,16,”SD Card OK”); LCD_ShowString(60,90,200,16,16,”Font Updating…”); key=update_font(20,110,16); //¸üÐÂ×Ö¿â

while(key) //¸üÐÂʧ°Ü {
LCD_ShowString(60,110,200,16,16,”Font Update Failed!”); delay_ms(200);
LCD_Fill(20,110,200+20,110+16,WHITE);
delay_ms(200);
}
LCD_ShowString(60,110,200,16,16,”Font Update Success!”); delay_ms(1500);
LCD_Clear(WHITE); //ÇåÆÁ
}
atk_8266_test(); //½øÈë ATK_ESP8266 ²âÊÔ }
´Ë²¿·Ö´úÂë±È½Ï¼òµ¥£¬Ê×Ïȳõʼ»¯ÁË ATK-ESP8266 Ä£¿éÓõ½µÄ´®¿Ú 3(²¨ÌØÂÊ:115200)¡£ ÓÉÓÚ±¾Àý³ÌÎÒÃÇÓõ½ÁË´¥ÃþÆÁ¡¢12*12 ×ÖÌå¡¢16*16 ×ÖÌåÒÔ¼° UNICODE Óë GBK ת»»Âë±í£¬ ËùÒÔÎÒÃÇÔÚ main º¯ÊýÀïÃæ¼ÓÈëÁË´¥ÃþÆÁУ׼ÒÔ¼°×Ö¿â¸üеĴúÂë¡£ÔÚÆô¶¯µÄʱºò£¬°´Ï KEY0£¬¿ÉÒÔ½øÈë´¥ÃþÆÁÇ¿ÖÆУ׼;ÔÚÆô¶¯µÄʱºò£¬°´Ï KEY1£¬¿ÉÒÔÇ¿ÖƽøÐÐ×Ö¿â¸üС£
×îºó£¬µ÷Óà atk_8266_test º¯Êý£¬³õʼ»¯´®¿Ú 2(²¨ÌØÂÊ:115200)£¬È»ºóµ÷Óà atk_8266_test º¯Êý£¬½øÈëATK-ESP8266Ä£¿éµÄÖ÷²âÊÔ³ÌÐò£¬¿ªÊ¼¶ÔATK- ESP8266µÄ¸÷ÏÄÜ(´®¿ÚÎÞ Ïß STA(COM-WIFI STA)¡¢´®¿ÚÎÞÏß AP(COM-WIFI AP)¡¢´®¿ÚÎÞÏß AP+STA(COM-WIFI AP+STA))½øÐвâÊÔ¡£
ÁíÍ⣬ΪÁË·½±ã´ó¼Òµ÷ÊÔ£¬ÎÒÃÇÔÚ±¾Àý³ÌµÄ USMART Ìí¼ÓÁË atk_8266_send_cmd ºÍ atk_8266_quit_trans ÕâÁ½¸öº¯Êý¡£ÕâÑù£¬µçÄԾͿÉÒÔͨ¹ý´®¿Ú 1£¬¼ä½Ó¿ØÖÆ ATK-ESP8266 Ä£ ¿é¡£
±ÈÈç(¼ÙÉèÓ²¼þÒѾ­×¼±¸ºÃ)£¬ÎÒÃÇͨ¹ý´®¿Úµ÷ÊÔÖúÊÖ¿ÉÒÔ½«Ä£¿éĬÈ쵀 WIFI ÅäÖýø ÐÐÐ޸ġ£Í¨¹ý:atk_8266_send_cmd(“AT+CWSAP?”,”OK”,20)£¬¿ÉÒÔ²éѯģ¿é AP ģʽµÄ WIFI ÅäÖã¬Í¨¹ý:atk_8266_send_cmd(“AT+CIFSR”,”OK”,20),¿ÉÒÔ²éѯģ¿éµÄ±¾µØ IP£¬Èçͼ 3.2 Ëùʾ:

4¡¢ÑéÖ¤²âÊÔ
ͼ 3.2 ͨ¹ý USMART ÉèÖà ATK-ESP8266 Ä£¿é
Õë¶ÔÄ£¿éµÄ 3 ÖÖģʽ£¬ÕâÀïÎÒÃDzâÊÔÒ²·ÖΪ 3 ²¿·Ö:´®¿ÚÎÞÏß WIFI(COM-AP)²âÊÔ¡¢ ´®¿ÚÎÞÏß STA(COM-STA)²âÊԺʹ®¿ÚÎÞÏß AP+STA(COM-AP+STA)²âÊÔ¡£
Ä£¿éÓë Mini STM32F103 ¿ª·¢°åÁ¬½Ó·½Ê½:¼ûͼ 2.3.1¡£
Á¬½ÓºÃÖ®ºó£¬·Ö±ð¸øÄ£¿éºÍ¿ª·¢°å¹©µç£¬È»ºóµÈ´ý 10s ×óÓÒ(Ä£¿é³õʼ»¯ÐèÒªÕâô¶àʱ ¼ä)£¬¿ª·¢°å±ã¿ÉÒÔÁ¬½ÓÉÏÄ£¿é£¬ÔÚ LCD ÉÏÃæÏÔʾģ¿éµÄһЩÐÅÏ¢¡£ÔÚ¼ì²âµ½Ä£¿éºó£¬Ö÷½ç ÃæÈçͼ 4.1 Ëùʾ:

ͼ 4.1 WIFI ²âÊÔÖ÷½çÃæ
ÔÚÖ÷½çÃæÏ£¬ÎÒÃÇ°´ KEY0£¬¼´¿É½øÈë´®¿ÚÎÞÏß AP+STA(COM-AP+STA)²âÊÔ£¬°´ KEY1£¬¼´¿É½øÈë´®¿ÚÎÞÏß STA(COM-STA)²âÊÔ£¬°´ KEY_UP£¬¼´¿É½øÈë´®¿ÚÎÞÏß AP (COM-AP)²âÊÔ¡£
4.1 ´®¿Ú STA(COM-STA)²âÊÔ
´®¿ÚÎÞÏßSTAģʽ£¬Ä£¿é¹¤×÷ÔÚWIFI STA״̬£¬ÒªÇó±ØÐëÓÐÒ»¸öÎÞÏßÈȵ㣬²¢¿ªÆô WIFI DHCP ¹¦ÄÜ£¬È»ºóÄ£¿é»áͨ¹ý WIFI Á¬½Óµ½¸ÃÈȵ㣬µçÄÔ»òÆäËû WIFI ¿ÉÒÔͨ¹ýÓÐÏß(±¾ Àý£¬ÎÒÃDzÉÓÃÓÐÏß)/ÎÞÏßÁ¬½Ó·ÓÉÆ÷£¬ÊµÏÖµçÄÔÓëÄ£¿éµÄÁ¬½Ó¡£
´®¿ÚÎÞÏß STA Á¬½Ó·½Ê½:µçÄÔ WIFI É豸<ÓÐÏß»òÎÞÏß>ÎÞÏß WIFI ÈȵãATK-ESP8266 Ä£¿é(WIFI STA)¡£
±¾´Î²âÊÔ£¬µçÄÔͨ¹ýÍøÏßÁ¬½ÓÎÞÏß·ÓÉÆ÷£¬È»ºóÄ£¿éͨ¹ý WIFI ÓëÎÞÏß·ÓÉÆ÷Á¬½Ó£¬Â· ÓÉÆ÷×÷ΪÖÐתÌṩģ¿éºÍµçÄÔµÄÁ¬½ÓͨµÀ¡£
ÔÚ WIFI ²âÊÔÖ÷½çÃæ(¼ûͼ 4.1)Ï£¬°´ KEY1£¬¼´¿É½øÈë´®¿ÚÎÞÏß STA(COM- STA) ¹¤×÷ģʽѡÔñ½çÃ棬¹² 3 ¸ö¹¤×÷ģʽ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP¡£Í¨¹ý°´ KEY0/KEY1 °´¼ü£¬Ñ¡Ôñģʽ£¬°´ KEY_UP °´¼üÈ·¶¨¡£Èçͼ 4.1.1

ͼ 4.1.1 ¹¤×÷ģʽѡÔñ½çÃæ 4.1.1 ´®¿Ú STA TCP ·þÎñÆ÷²âÊÔ
Ñ¡Ôñ TCP ·þÎñÆ÷£¬°´ KEY_UP£¬½øÈë TCP ·þÎñÆ÷²âÊÔ£¬Èçͼ 4.1.1.1 Ëùʾ:
ͼ 4.1.1.1 STA TCP ·þÎñÆ÷²âÊÔ½çÃæ
ͼ 4.1.1.1 ÖУ¬¿ÉÒÔ¿´µ½£¬Ä£¿éµÄ IP µØÖ·:192.168.1.125£¬¶Ë¿ÚΪ:8086£¬¹¤×÷ģʽΪ TCP·þÎñÆ÷£¬×´Ì¬ÏÔʾΪ:Á¬½Óʧ°Ü¡£ÍⲿTCP ClientÁ¬½Óµ½192.168.1.125£¬¶Ë¿Ú:8086 ¼´¿ÉÁ¬½Óµ½±¾Ä£¿é¡£
״̬ÏÔʾÁ¬½Óʧ°Ü£¬ËµÃ÷TCPÁ¬½Ó»¹Ã»½¨Á¢£¬ÒòΪ»¹Ã»ÓÐTCP ClientÁ¬½Óµ½Ä£¿é¡£²â ÊÔÎÒÃÇÑ¡Ôñͬһ¸ö¾ÖÓòÍøÏÂÃæµÄµçÄÔ×÷ TCP Client¡£ÎÒÃÇÔÚµçÄÔÉÏÔËÐÐ:Ä£¿é×ÊÁÏ\3£¬ÅäÌ× Èí¼þ\ÍøÂçµ÷ÊÔÖúÊÖ.exe£¬È»ºóÉèÖÃЭÒéÀàÐÍΪ:TCP Client;·þÎñÆ÷ IP µØַΪ:192.168.1.125;

·þÎñÆ÷¶Ë¿ÚºÅΪ:8086£¬ÉèÖúÃÖ®ºó£¬µã»÷Á¬½Ó£¬¼´¿ÉÁ¬½Óµ½ ATK-ESP8266 Ä£¿é£¬Èçͼ 4.1.1.2 Ëùʾ:
ͼ 4.1.1.2 ÍøÂçµ÷ÊÔÖúÊÖÉèÖýçÃæ
ͼ 4.1.1.2 ÖУ¬ÏÔʾÍøÂçµ÷ÊÔÖúÊÖÒѾ­Á¬½Óµ½ÁË ATK-ESP8266 Ä£¿é£¬´ËʱÁ½ÕßÖ®¼ä±ã¿É ÒÔ»¥Ïà·¢ËÍÊý¾ÝÁË¡£°´¿ª·¢°åµÄ KEY0 °´¼ü£¬¼´¿Éͨ¹ýÄ£¿éÏòµçÄÔ·¢ËÍÊý¾Ý£¬ÔÚÍøÂçµ÷ÊÔ ÖúÊÖÉÏÏÔʾ³öÀ´£¬Èçͼ 4.1.1.3 Ëùʾ:

ͼ 4.1.1.3 ÍøÂçµ÷ÊÔÖúÊÖ½ÓÊÕµ½À´×ÔÄ£¿é TCP ·þÎñÆ÷µÄÊý¾Ý
ÔÚÍøÂçµ÷ÊÔÖúÊÖÊäÈëÊý¾ÝÒ²¿ÉÒÔ·¢Ë͸øÄ£¿é£¬Èçͼ 4.1.1.4 Ëùʾ:
ͼ 4.1.1.4 Ä£¿éÊÕµ½ÍøÂçµ÷ÊÔÖúÊÖµÄÊý¾Ý

4.1.2 ´®¿Ú STA TCP ¿Í»§¶Ë²âÊÔ
ÔÚ¹¤×÷ģʽѡÔñ½çÃ棬ѡÔñ TCP ¿Í»§¶Ë£¬ÔÙ°´ KEY_UP °´¼ü£¬¼´¿É½øÈë TCP ¿Í»§¶Ë²â ÊÔ¡£²»¹ýͬ TCP ·þÎñÆ÷²âÊÔ²»Í¬£¬¿Í»§¶Ëģʽ£¬ÐèÒªÊäÈëÔ¶¶Ë IP µØÖ·£¬¼´Ä£¿é½«ÒªÁ¬½Óµ½ µÄ IP µØÖ·£¬ÇÒÁ¬½Ó¶Ë¿ÚºÅ¹Ì¶¨Îª:8086¡£±ÈÈçÎÒÃÇÒªÁ¬½ÓÎÒÃǵĵçÄÔ£¬ËùÒÔÐèÒªÏÈÖªµÀµç Ä﵀ IP µØÖ·£¬¿ÉÒÔÔÚ±¾µØÁ¬½Ó״̬¡úÖ§³Ö£¬²é¿´µ½ÎÒÃǵçÄ﵀ IP µØÖ·£¬Èçͼ 4.1.2.1 ËùÒÔ:
ͼ 4.1.2.1 µçÄÔ IP µØÖ·²é¿´
ÉÏͼÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½µçÄÔ IP µØַΪ:192.168.1.127£¬ËùÒÔ£¬ÎÒÃÇÔÚÔ¶¶Ë IP ÉèÖÃÀïÃæ
ÊäÈë:192.168.1.127£¬¼´¿ÉÁ¬½Óµ½ÎÒÃǵĵçÄÔ¡£Èçͼ 4.1.2.2 Ëùʾ:

ͼ 4.1.2.2 Ô¶¶Ë IP ÉèÖÃ
ͼ 4.1.2.2 ÖУ¬ÊÇÎÒÃÇͨ¹ýÆÁÄ»ÐéÄâ¼üÅÌÊäÈëµÄÔ¶¶Ë IP µØÖ·£¬¼´ÎÒÃǵçÄ﵀ IP µØÖ·¡£Êä
ÈëÍê³Éºó£¬µã»÷Á¬½Ó£¬¿ª·¢°å¾Í»á¶ÔÄ£¿é½øÐÐÅäÖã¬ÅäÖúÃÖ®ºó(´ó¸ÅÒª 5s)£¬½øÈë TCP ·þÎñÆ÷Á¬½Ó½çÃ棬²¢ÇÒÌáʾÁ¬½Óʧ°Ü£¬Èçͼ 4.1.2.3 Ëùʾ:
ͼ 4.1.2.3 TCP ¿Í»§¶ËÁ¬½Óʧ°ÜºÍ²âÊÔ½çÃæ
ÉÏͼΪ TCP Á¬½Ó佨Á¢Ê±µÄÏÔʾ״̬£¬Òª³É¹¦Á¬½Ó£¬±ØÐë´ò¿ªÍøÂçµ÷ÊÔÖúÊÖ£¬ÉèÖÃЭ
ÒéÀàÐÍΪ:TCP Server;·þÎñÆ÷ IP µØַΪ:192.168.1.127(¼´ÄãµçÄ﵀ IP£¬µÃ¸ù¾Ýʵ¼ÊÇé¿ö ÐÞ¸Ä);·þÎñÆ÷¶Ë¿ÚΪ:8086;È»ºóµã»÷Á¬½Ó°´Å¥£¬¿ªÆô TCP ·þÎñ£¬Èçͼ 4.1.2.4 Ëùʾ:

ͼ 4.1.2.4 ÍøÂçµ÷ÊÔÖúÊÖÉèÖýçÃæ
ÍøÂçµ÷ÊÔÖúÊÖ¿ªÆô TCP ·þÎñºó£¬¾Í¿ÉÒÔ¿´µ½¿ª·¢°åÒº¾§ÏÔʾ½øÈë TCP ¿Í»§¶Ë²âÊÔ½çÃæ¡£
²âÊÔ½çÃæÈçÏÂͼ 4.1.2.5 Ëùʾ£¬´Ëʱ°´¿ª·¢°åµÄ KEY0 ¼´¿ÉÏòÍøÂçµ÷ÊÔÖúÊÖ·¢ËÍÊý¾Ý
ͼ 4.1.2.5 TCP ¿Í»§¶ËÊÕµ½Êý¾Ý
ͼ 4.1.2.5 ÍøÂçµ÷ÊÔÖúÊÖ½ÓÊÕµ½À´×ÔÄ£¿é TCP ¿Í»§¶ËµÄÊý¾Ý
ÔÚÍøÂçµ÷ÊÔÖúÊÖÊäÈëÊý¾ÝÒ²¿ÉÒÔ·¢Ë͸øÄ£¿é£¬Èçͼ 4.1.2.6 Ëùʾ:
ͼ 4.1.2.6 TCP ¿Í»§¶ËÊý¾ÝµÄ·¢ËÍÓë½ÓÊÕ

4.1.3 ´®¿Ú STA UDP ²âÊÔ
ÔÚ¹¤×÷ģʽѡÔñ½çÃ棬ѡÔñ UDP£¬ÔÙ°´ KEY_UP °´¼ü£¬¼´¿É½øÈë UDP ²âÊÔ¡£UDP Óë TCP ¿Í»§¶Ë²âÊÔ»ù±¾Ò»Ñù£¬ËùÒÔ²½ÖèÎÒÃǾͲ»Ïêϸ½éÉÜÁË£¬´ýÅäÖúÃÖ®ºó£¬½øÈë UDP ²âÊÔ ½çÃ棬Èçͼ 4.1.3.1 Ëùʾ:
ͼ 4.1.3.1 UDP ²âÊÔ½çÃæ 4.2 ´®¿Ú AP(COM-AP)²âÊÔ
´®¿ÚÎÞÏß AP£¬Ä£¿é¹¤×÷ÔÚ WIFI AP ״̬£¬²¢¿ªÆô DHCP ¹¦ÄÜ£¬Íⲿ WIFI É豸(ÊÖ»ú¡¢ ƽ°å¡¢µçÄÔµÈ)£¬¿ÉÒÔͨ¹ý WIFI Á¬½Óµ½Ä£¿é£¬±¾Àý£¬ÎÒÃÇÑ¡Ôñ´ø WIFI µÄ android ÖÇÄÜÊÖ»ú ²âÊÔ¡£
´®¿ÚÎÞÏß½ÓÈëµã ÍøÂçÁ¬½Ó·½Ê½:ATK-ESP8266 Ä£¿é(WIFI AP)ÖÇÄÜÊÖ»ú(WIFI STA)¡£¼´£¬Ä£¿éͨ¹ý WIFI Á¬½ÓÖÇÄÜÊÖ»ú£¬Ä£¿é×÷Ϊ WIFI AP£¬ÖÇÄÜÊÖ»ú×ö WIFI STA¡£
ÔÚ WIFI ²âÊÔÖ÷½çÃæ(¼ûͼ 4.1)Ï£¬°´ KEY_UP£¬¼´¿É½øÈë´®¿ÚÎÞÏß AP(COM- AP) ¹¤×÷ģʽѡÔñ½çÃ棬¹² 3 ¸ö¹¤×÷ģʽ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢UDP¡£Í¬Í¼ 4.1.1 Ëùʾ½ç Ãæ»ù±¾Ò»Ñù£¬²Ù×÷·½·¨Ò²ÍêÈ«Ò»Ñù¡£
4.2.1 ´®¿Ú AP TCP ·þÎñÆ÷²âÊÔ
Ñ¡Ôñ TCP ·þÎñÆ÷£¬°´ KEY_UP °´¼ü£¬½øÈë TCP ·þÎñÆ÷²âÊÔ£¬´Ëʱ£¬³ÌÐò»áÅäÖÃÄ£¿éΪ WIFI AP ģʽ£¬SSID Ϊ:ATK-ESP8266;¼ÓÃÜ·½Ê½Îª:wpawpa2_aes;ÃÜÂëΪ:12345678¡£ Ä£¿é IP µØÖ·(TCP ·þÎñÆ÷ IP µØÖ·)Ϊ:192.168.4.1;¶Ë¿ÚΪ:8086;´ýÅäÖúú󣬽øÈë TCP ·þÎñÆ÷²âÊÔ½çÃ棬Èçͼ 4.2.1.1 Ëùʾ:

ͼ 4.2.1.1 TCP ·þÎñÆ÷²âÊÔ½çÃæ
´Ëʱ£¬Ä£¿éµÄ TCP ·þÎñÆ÷ÒѾ­¿ªÆô£¬IP µØַΪ:192.168.4.1£¬¶Ë¿ÚºÅ:8086¡£µ«ÊÇ£¬ ÓÉÓÚûÓÐ TCP Client À´Á¬½Ó£¬ËùÒÔ״̬ÏÔʾ:Á¬½Óʧ°Ü¡£ÎÒÃÇÏÈ´ò¿ªÖÇÄÜÊÖ»úµÄ WIFI ¹¦ÄÜ£¬ È»ºó¡úÉèÖáúÎÞÏߺÍÍøÂç¡úWLAN ÉèÖ㬼´¿ÉÔÚ WLAN ÍøÂçÀïÃæ¿´µ½ÓÐ:ATK-ESP8266 µÄÍøÂç SSID£¬È»ºóµã»÷¸ÃÍøÂ磬ÊäÈëÃÜÂë:12345678£¬ÔÙµã»÷Á¬½Ó£¬¼´¿ÉÁ¬½Óµ½ÎÒÃǵÄÄ£ ¿é£¬Èçͼ 4.3.1.2 Ëùʾ:
ͼ 4.2.1.2 ÊÖ»úÁ¬½Ó ATK-ESP8266 WIFI ÍøÂç ÉÔµÈƬ¿Ì£¬ÊÖ»ú±ã»áÁ¬½Óµ½ ATK-ESP8266 Ä£¿é£¬Èçͼ 4.2.1.3 Ëùʾ:

ͼ 4.2.1.3 ÊÖ»ú³É¹¦Á¬½Óµ½Ä£¿é
´ÓÉÏͼ¿ÉÒÔ¿´³ö£¬Ä£¿é¸øÊÖ»ú·ÖÅäµÄ IP µØַΪ:192.168.4.2¡£
È»ºó£¬ÎÒÃÇÔÚÊÖ»ú°²×°:3£¬ÅäÌ×Èí¼þ\ÊÖ»ú¶ËÍøÂçµ÷ÊÔÖúÊÖ\ÍøÂçµ÷ÊÔÖúÊÖ(°²×¿ÊÖ»ú °æ).apk Õâ¸öÈí¼þ£¬Ö®ºó£¬ÔÚÊÖ»úÉÏÔËÐиóÌÐò£¬È»ºóÒÀ´ÎÉèÖÃ:1.tcp client¡ú2.µã»÷Ôö¼Ó ͼ±ê¡ú3.ÊäÈë·þÎñÆ÷ IP ºÍ¶Ë¿ÚºÅ¡ú4.°´Ôö¼Ó°´Å¥¡ú5.Á¬½Ó½¨Á¢£¬Èçͼ 4.2.1.4 Ëùʾ:
ͼ 4.2.1.4 ÊÖ»úÍøÂçµ÷ÊÔÖúÊÖ TCP Client ÉèÖà ¾­¹ýÈçÉÏÉèÖÃÒÔºó£¬ÊÖ»úºÍÄ£¿é¾Í½¨Á¢ÁË TCP Á¬½ÓÁË£¬´Ëʱ¿ª·¢°åÒº¾§ÏÔʾ״̬½«»á ±äΪ:Á¬½Ó³É¹¦¡£×¢Ò⣬ͼ 4.2.1.4 ÖУ¬Èç¹ûÊäÈëÁË´íÎóµÄ IP/¶Ë¿ÚºÅ£¬ÓÒ²àµÄͼƬ½«²»»áÏÔ
ʾ port:8086£¬¶ø»ØÏÔʾ disconnect¡£

ÔÚÁ¬½Ó³É¹¦½¨Á¢ºó£¬¾Í¿ÉÒÔ»¥Ïà·¢ËÍÊý¾ÝÁË£¬Èçͼ 4.2.1.5 ºÍ 4.2.1.6 Ëùʾ
ͼ 4.2.1.5 Ä£¿éÊÕµ½À´×ÔÊÖ»ú TCP ¿Í»§¶ËµÄÊý¾Ý
ͼ 4.2.1.6 ÊÖ»úÊÕµ½Ä£¿é TCP ·þÎñÆ÷·¢Ë͹ýÀ´µÄÊý¾Ý 4.2.2 ´®¿Ú AP TCP ¿Í»§¶Ë²âÊÔ
ÔÚWIFI APµÄ¹¤×÷ģʽѡÔñ½çÃ棬ѡÔñTCP¿Í»§¶Ë£¬ÔÙ°´KEY_UP°´¼ü£¬¼´¿É½øÈë TCP ¿Í»§¶Ë²âÊÔ¡£´Ëʱ£¬ÓÉÓÚÄ£¿éÖØÆô£¬ÊÖ»ú¿ÉÄÜÁ¬½Óµ½ÆäËû WIFI ÍøÂ磬ËùÒÔ£¬ÎÒÃÇÔÚÊÖ »úÉÏÒªÖØÐÂÑ¡Ôñ WLAN Á¬½Óµ½ ATK-ESP8266£¬È»ºó´ò¿ªÍøÂçµ÷ÊÔÖúÊÖ£¬ÉèÖÃ:1.tcp server¡ú2. µã»÷ÅäÖÃͼ±ê ¡ú3. ÉèÖö˿Ú:8086£¬µã»÷¼¤»î¡ú4.Á¬½Ó³É¹¦£¬Èçͼ 4.2.2.1 Ëùʾ:

ͼ 4.2.2.1 ÊÖ»úÍøÂçµ÷ÊÔÖúÊÖ TCP Server ÉèÖà ÕâÀïҪעÒâ:ÎÒÃÇҪģ¿éÁ¬½Óµ½ÊÖ»ú½¨Á¢µÄTCP Server£¬ÎÒÃÇÐèÒªÖªµÀÊÖ»úµÄIPµØÖ·
(192.168.4.2)£¬¸ÃµØÖ·½«Óõ½±¾½Ú×÷Ϊ TCP ·þÎñÆ÷¶ËµÄ IP µØÖ·¡£ÔÚÔ¶¶Ë IP ÉèÖýçÃ棬Êä ÈëÔ¶¶ËIPµØÖ·:192.168. 4.2£¬ÉèÖúÃIPÖ®ºó£¬µã»÷Á¬½ÓÌá½»ÅäÖã¬ÅäÖóɹ¦ºó(Ô¼5s)£¬ ½øÈëµ½ TCP ¿Í»§¶Ë²âÊÔ½çÃ棬Èçͼ 4.2.2.1 Ëùʾ:
ͼ 4.2.2.2 TCP ¿Í»§¶Ë IP ÉèÖü°²âÊÔ½çÃæ ÊÖ»ú¶ËÍøÂçµ÷ÊÔÖúÊÖÉèÖúã¬Á¬½Ó³É¹¦Ö®ºó£¬ÊÖ»ú¼´¿ÉÓëÄ£¿é»¥Ïà·¢ËÍÊý¾ÝÁË£¬Èçͼ
4.2.2.2 ÓÒ²àͼƬ£¬ÒÔ¼°Í¼ 4.2.2.3 Ëùʾ:

ͼ 4.2.2.3 Ä£¿éÊÕµ½À´×ÔÊÖ»ú TCP ·þÎñÆ÷µÄÊý¾Ý 4.2.3 ´®¿Ú AP UDP ²âÊÔ
ÔÚ¹¤×÷ģʽѡÔñ½çÃ棬ѡÔñ UDP£¬ÔÙ°´ KEY_UP °´¼ü£¬¼´¿É½øÈë UDP ²âÊÔ¡£UDP Óë TCP ¿Í»§¶Ë²âÊÔ»ù±¾Ò»Ñù£¬ËùÒÔ²½ÖèÎÒÃǾͲ»Ïêϸ½éÉÜÁË£¬´ýÅäÖúÃÖ®ºó£¬½øÈë UDP ²âÊÔ ½çÃ棬Èçͼ 4.1.3.1 Ëùʾ:
ͼ 4.2.3.1 UDP Á¬½Óµ½Ô¶¶Ë IP ¼°²âÊÔ½çÃæ 4.3 ´®¿Ú AP+STA(COM-AP+STA)²âÊÔ
¸ÃģʽÏÂÄ£¿é AP ºÍ STA ͬʱ¿ªÆô£¬´Ë״̬ÏÂÄ£¿é¼È×÷ÎÞÏß AP(ÆäËû WIFI É豸¿ÉÒÔ Á¬½Óµ½ ATK_ESP8288 Ä£¿é)£¬Ò²¿É×÷ STA Á¬½Óµ½ÆäËûµÄ wifi Èȵ㡣ÏÂÃæµÄ²âÊÔÖÐÎÒÃǽ«½é Éܸù¤×÷ģʽ£¬Ä£¿é¹¤×÷ÓÚ¸Ã״̬Ï£¬AP ÓÐÈýÖÖ¹¤×÷ģʽ£¬STA ÓÐÈýÖÖ¹¤×÷ģʽ£¬ÕâÑù¾Í Ò»¹²ÓÐ 9 Öй¤×÷ģʽ£¬»ù±¾µÄ²âÊÔ¸úÇ°Ã涼²î²»¶à£¬ÕâÀïÎÒÃǽö½éÉÜ 3 ÖÖģʽµÄ²âÊÔ¡£
ÔÚ WIFI ²âÊÔÖ÷½çÃæ(¼ûͼ 4.1)Ï£¬°´ KEY0£¬¼´¿É½øÈë´®¿ÚÎÞÏß AP+STA(COM- AP+STA)¹¤×÷ģʽÖÐµÄ STA ģʽѡÔñ½çÃ棬¹² 3 ¸ö¹¤×÷ģʽ:TCP ·þÎñÆ÷¡¢TCP ¿Í»§¶Ë¡¢

UDP£¬ÕâÀïÎÒÃÇÑ¡Ôñ TCP ·þÎñÆ÷£¬ÏÂÃæµÄ½éÉÜÎĵµÖÐÎÒÃǽö½éÉÜ STA ×÷·þÎñÆ÷£¬AP ģʽ ϵÄÈýÖÖ¹¤×÷ģʽ½éÉÜ¡£Èçͼ 4.3.1
ͼ 4.3.1 STA ģʽÏÂĬÈÏÑ¡Ôñ TCP ·þÎñÆ÷ 4.3.1 ´®¿Ú AP TCP ·þÎñÆ÷£¬STA TCP ·þÎñÆ÷²âÊÔ
STA ģʽÏÂÑ¡ÔñÁË TCP ·þÎñÆ÷£¬½Ó×ųöÏÖ AP ģʽÏµĹ¤×÷״̬£¬ÕâÀïÎÒÃÇÑ¡Ôñ TCP ·þÎñÆ÷¡£½ÓמÍÊÇÎÒÃǵĴ®¿ÚÎÞÏß AP TCP ·þÎñÆ÷+STA TCP ·þÎñÆ÷²âÊÔ½çÃ档ͨ¹ý²âÊÔ½ç ÃæÎÒÃÇ¿´µ½ AP IP:192.168.4.1;STA IP:192.168.1.xxxxx¡£ÎÒÃÇͨ¹ýÊÖ»úÁ´½Óµ½ SSID Ϊ ATK_ESP8266 µÄ wifi ÎÞÏß½ÓÈëµã£¬²¢ÇÒͨ¹ýÍøÂçµ÷ÊÔÖúÊÖÁ¬½Óµ½ 192.168.4.1£¬8086£¬Èç¹û Á¬½Ó³É¹¦²âÊÔ½çÃæ»áÏÔʾ:0,CONNECT;Õâ˵Ã÷Ä£¿é·ÖÅä¸øÊÖ»úµÄ ID ºÅÊÇ 0¡£Í¬ÑùµÄ·½Ê½ ͨ¹ýµçÄÔÁ´½Óµ½ 192.168.1.xxxxx£¬8086£¬ÈôÁ¬½Ó³É¹¦£¬²âÊÔ½çÃæ»áͬÑùÏÔʾ:1,CONNECT; Ä£¿é·ÖÅä¸ø¸ÕÀ´Äã½Óµ½Ä£¿éµÄµçÄÔ ID ÊÇ 1¡£AP+STA ģʽÏ嵀 ID ºÅ·ÖÅäÊÇ°´ÕÕÁ¬½Óµ½Ä£¿é µÄ˳ÐòÀ´·ÖÅäµÄ¡£ÈçÏÂͼËùʾ:
ͼ 4.3.1.1 AP ģʽÏÂÑ¡Ôñ TCP ·þÎñÆ÷

ͼ 4.3.1.2 ²âÊÔ½çÃæͼƬ
ͼ 4.3.1.3 ÊÖ»úºÍµçÄÔ·Ö±ðÁ¬½Óµ½Ä£¿é Á¬½Ó³É¹¦ºóÎÒÃÇ¿ÉÒÔͨ¹ý°´°´¼ü KEY0 ºÍ KEY1 ·Ö±ð·¢ËÍÊý¾Ýµ½ÊÖ»úºÍµçÄÔ£¬Èçͼ
4.3.1.4.1 ºÍͼ 4.3.1.4.2:

ͼ 4.3.1.4.1 ÊÖ»úÊÕµ½Êý¾Ý
ͼ 4.3.1.4.1 µçÄÔÊÕµ½Êý¾Ý

ÎÒÃÇÒ²¿ÉÒÔͨ¹ýÊÖ»úµÄÍøÂçµ÷ÊÔÖúÊֺ͵çÄÔµÄÍøÂçµ÷ÊÔÖúÊÖ·¢ËÍÊý¾Ýµ½Ä£¿é£¬²¢ÇÒÊÖ»ú ¶Ë·¢ËÍÊý¾ÝÓÐÊÕµ½¡®+IPD,0¡¯Êý¾ÝÍ·µÄÊý¾Ý£¬Õâ˵Ã÷Êý¾ÝÀ´×Ô ID0£¬µçÄԶ˷¢ËÍÊý¾ÝÓÐÊÕµ½ +IPD,1¡¯Êý¾ÝÍ·µÄÊý¾Ý£¬Õâ˵Ã÷Êý¾ÝÀ´×Ô ID1¡£Èçͼ 4.3.1.5:
ͼ 4.3.1.5 Ä£¿éÊÕµ½ÊÖ»úºÍµçÄÔµÄÊý¾Ý. 4.3.2 ´®¿Ú AP TCP ¿Í»§¶Ë£¬STA TCP ·þÎñÆ÷²âÊÔ
STA ģʽÏÂÎÒÃÇÑ¡Ôñ TCP ·þÎñÆ÷£¬½Ó×ÅÉèÖà AP ģʽÏµĹ¤×÷·½Ê½£¬ÎÒÃÇÑ¡Ôñ TCP ¿Í »§¶Ëģʽ£¬¸ÃģʽÏÂÐèÒªÊäÈëTCP ServerµÄIPµØÖ·£¬´ËʱÎÒÃÇÏÈÔÚÊÖ»ú¶ËÁ¬½Óµ½SSIDΪ ATK_ESP8266 µÄÎÞÏß wifi Èȵ㣬ȻºóÔÚÊÖ»úÉÏͨ¹ýÍøÂçµ÷ÊÔÖúÊÖ½¨Á¢ TCP Server£¬·½·¨Í¬ 4.2.2¡£ÎÒÃÇÈ»ºóÔÚÆÁÄ»ÉÏÊäÈëÊÖ»ú¶Ë½¨Á¢µÄ TCP Server IP:192.168.4.2¡£ Èçͼ 4.3.2.1 Ëùʾ:
ͼ 4.3.2.1 Ä£¿é AP ģʽ×÷ TCP Client Á¬½Óµ½ TCP Server

Á¬½Ó³É¹¦ºó¾Í³öÏÖÁ˲âÊÔ½çÃ棬´ËʱÎÒÃÇÐèÒªÔÚµçÄÔ¶ËÁ¬½Óµ½ STA IP: 192.168.1.XXXXX;¶Ë¿Ú:8086¡£½ÓÏÂÀ´µÄ²âÊÔͬ 4.3.1£¬ÕâÀïÎÒÃǾͲ»ÔÚ˵ÁË£¬ÈçÏÂͼËù ʾ:
ͼ 4.3.2.2 Ä£¿é·¢ËÍÊý¾Ýµ½ ID1
ͼ 4.3.2.3 ÊÖ»úÊÕµ½Êý¾ÝºÍµçÄÔÊÕµ½Êý¾Ý½Øͼ 4.3.3 ´®¿Ú AP UDP ²âÊÔ£¬STA TCP ·þÎñÆ÷²âÊÔ
STA ģʽÏÂÎÒÃÇÑ¡Ôñ TCP ·þÎñÆ÷£¬½Ó×ÅÉèÖà AP ģʽÏµĹ¤×÷·½Ê½£¬ÎÒÃÇÑ¡Ôñ UDP Ä£ ʽ£¬¸ÃģʽÏÂÐèÒªÊäÈë TCP Server µÄ IP µØÖ·£¬´ËʱÎÒÃÇÏÈÔÚÊÖ»ú¶ËÁ¬½Óµ½ SSID Ϊ ATK_ESP8266 µÄÎÞÏß wifi Èȵ㣬ȻºóÔÚÊÖ»úÉÏͨ¹ýÍøÂçµ÷ÊÔÖúÊÖ½¨Á¢ UDP Server£¬·½·¨Í¬ 4.2.2¡£ÎÒÃÇÈ»ºóÔÚÆÁÄ»ÉÏÊäÈëÊÖ»ú¶Ë½¨Á¢µÄ UDP Server IP:192.168.4.2¡£ Èçͼ 4.3.2.1 Ëùʾ

ͼ 4.3.2.1 ÊÖ»ú¶Ë½¨Á¢ UDP Server ºÍÒº¾§¶ËÊäÈë IP
UDP Á¬½Ó³É¹¦ºó£¬³öÏÖÈçÏÂͼ 4.3.2.2 µÄ²âÊÔ½çÃæ¡£ÎÒÃÇÔÚµçÄԶ˴ò¿ªÍøÂçµ÷ÊÔÖúÊÖÁ¬ ½Óµ½STA IP:192.168.1.XXX¡¢¶Ë¿Ú:8086¡£Á¬½Ó³É¹¦ÎÒÃÇ¿ÉÒÔ°´KEY0ºÍKEY1·¢ËÍÊý
¾Ýµ½ÊÖ»ú¶ËºÍµçÄԶˣ¬Èçͼ 4.3.2.3:
ͼ 4.3.2.3 µçÄÔ¶ËÊÕµ½Êý¾Ý

ÎÒÃÇÒ²¿ÉÒÔÊÖ»úºÍµçÄÔ·¢ËÍÊý¾Ýµ½Ä£¿é£¬Èçͼ 4.3.2.4:
ͼ 4.3.2.4 Ä£¿éÊÕµ½ÊÖ»úºÍµçÄÔµÄÊý¾Ý

5¡¢ÁªÏµÎÒÃÇ ¹ÙÍøµØÖ·:http://www.alientek.com
¹Ù·½ÂÛ̳:http://www.openedv.com ÑùÆ·¹ºÂò:https://openedv.taobao.com ÉÌÎñºÏ×÷:liujun6037@foxmail.com ¼¼ÊõÖ§³Ö:login-mail@foxmail.com ¹«Ë¾µØÖ·:¹ã¶«Ê¡¹ãÖÝÊа×ÔÆÇø¹ãÖÝÃñÓª¿Æ¼¼Ô°ºëʵÉÌÎñ´óÏà 906 ÁªÏµµç»°:020-38271790