|
#include "public.h"#include "ESP8266.h"#include "usart.h"#include "delay.h"#include "stdio.h"#include "string.h"
/***********************************1:OK2:SEND OK3:CLOSE4:ò»Î»êyêy¾Y5:á½Î»êyêy¾Y6:èyλêyêy¾Y7:·tÎñÆ÷±»á¬½ó8:êÕμ½wifiÃû3ÆoíÃüÂë9:êÕμ½Ãû3ÆoíÃüÂë10:ERROR11;¸′λ12:·μ»Ø>13:í¸′«·μ»Ø14:í¸′«½óêÕíê3é************************************//************************************ ¶¨òåOLED*************************************/u8 Set_Mode[9]="Set Mode\0";u8 Connect_Wifi[13]="Connect Wifi\0";u8 Connect_TCP[12]="Connect TCP\0";u8 Connect_UDP[12]="Connect UDP\0";u8 State[3]="OK\0";u8 Wite[13]="Wite connect\0";u8 Client[7]="Client\0";u8 SSID_PASSWORD[14]="SSID PASSWORD\0";/************************************ APP¿ØÖÆWIFIᬽó*************************************/char CWJAP_APP[100]="AT+CWJAP=";/************************************ Ãüáî·μ»Ø×′ì¬*************************************/int ESP8266_state = 0;
/************************************ Ãüáî·¢Ëíoˉêy*************************************/void SEND_Order(char* order){ int i; for(i=0; i < strlen(order); i++) { USART_SendData(USART1,order[i]); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE) == Bit_RESET); }}/************************************ íË3öí¸′«*************************************/void SEND_EN_EXIT(void){ delay_ms(100); SEND_Order(CIPSEND_EXIT); delay_ms(100);}/************************************ í¸′«·¢Ëíoˉêy*************************************/void SEND_EN_Order(char *data){ SEND_Order(data); ESP8266_state = 0;}/************************************ ·Çí¸′«·¢Ëíoˉêy*************************************/void SEND_DIS_Order(char *data,char *len){ char buff[20]=""; strcat(buff,CIPSEND_Dis); strcat(buff,len); strcat(buff,EXIT); SEND_Order(buff); while(ESP8266_state !=1); ESP8266_state = 0; SEND_Order(data); while(ESP8266_state != 2); ESP8266_state = 0;}/************************************ êy¾Y·¢ËíÄ£ê½éèÖà 0:·Çí¸′«Ä£ê½ 1:í¸′«Ä£ê½*************************************/void Send_Mode(int S_Mode){ switch(S_Mode) { case 0: //·Çí¸′« SEND_Order(CIPMODE_Dis); while(ESP8266_state != 1); ESP8266_state = 0; break; case 1: //í¸′« SEND_Order(CIPMODE_EN); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPSEND_EN); delay_ms(10); break; default: break; }}/************************************ 1춨wifi3õê¼»ˉoˉêy*************************************/void esp8266_config(void) //ESP82663õê¼»ˉ{ SEND_Order(ATE); while(ESP8266_state != 1); ESP8266_state = 0; // OLED_ShowString(0,0,Set_Mode,12); Draw_Font16B(0,10,BLUE,Set_Mode); SEND_Order(mode); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,1,State,12); Draw_Font16B(0,30,BLUE,State); // OLED_ShowString(0,2,Connect_Wifi,12); Draw_Font16B(0,50,BLUE,Connect_Wifi); SEND_Order(CWJAP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,3,State,12); Draw_Font16B(0,70,BLUE,State);
// OLED_ShowString(0,4,Connect_TCP,12); Draw_Font16B(0,90,BLUE,Connect_TCP); SEND_Order(CIPSTART_TCP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,5,State,12); Draw_Font16B(0,110,BLUE,State);}/************************************ APP¿ØÖÆwifiᬽó3õê¼»ˉoˉêy*************************************/void esp8266_config_APP(void){ char symbol[7] = "\"\",\"\"\r\n"; int SSID_PASSWORD_COUNT=10; int data_count=0; SEND_Order(ATE); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(mode_APP); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPAP); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CWSAP); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPMUX_EN); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPSERVER_EN); //éèÖÃÎaTCP·tÎñÆ÷ while(ESP8266_state!=1); ESP8266_state=0; while(1) {// OLED_ShowString(0,0,Wite,12); if(ESP8266_state==7) { delay_ms(1000); ESP8266_state=0;// OLED_ShowString(0,1,Client,12); } if(ESP8266_state==9) { ESP8266_state=0;// OLED_ShowString(0,2,SSID_PASSWORD,12); break; } } CWJAP_APP[9]=symbol[0]; while(1) { CWJAP_APP[SSID_PASSWORD_COUNT] = json_data[data_count]; SSID_PASSWORD_COUNT++; data_count++; if(json_data[data_count]==',') { CWJAP_APP[SSID_PASSWORD_COUNT]=symbol[1]; CWJAP_APP[SSID_PASSWORD_COUNT+1]=symbol[2]; CWJAP_APP[SSID_PASSWORD_COUNT+2]=symbol[3]; data_count++; SSID_PASSWORD_COUNT+=3; } if(data_count == count_flag) { CWJAP_APP[SSID_PASSWORD_COUNT] = symbol[4]; CWJAP_APP[SSID_PASSWORD_COUNT+1] = symbol[5]; CWJAP_APP[SSID_PASSWORD_COUNT+2] = symbol[6]; CWJAP_APP[SSID_PASSWORD_COUNT+3] = '\0'; break; } } ESP8266_state=0; SSID_PASSWORD_COUNT=10; data_count=0; SEND_Order(CIPSERVER_DIS); //éèÖÃÎa·ÇTCP·tÎñÆ÷ while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(RST); //¸′λ while(ESP8266_state != 1); ESP8266_state = 0; delay_ms(1000); SEND_Order(CIPMUX_DIS); //éèÖ÷Ƕàᬽó while(ESP8266_state != 1) ESP8266_state = 0; SEND_Order(ATE); while(ESP8266_state != 1); ESP8266_state = 0; ESP8266_state = 0; SEND_Order(mode); while(ESP8266_state != 1); ESP8266_state = 0; // OLED_ShowString(0,3,Connect_Wifi,12); SEND_Order(CWJAP_APP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,4,State,12);
// OLED_ShowString(0,5,Connect_TCP,12); SEND_Order(CIPSTART_TCP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,6,State,12);}
|
|