First: Material preparation
stm32f103vet6, tft color screen, esp8266
II: Preparations for ESP8266
- esp8266 uses AT firmware
- Configure 8266 as STA mode with serial assistant in advance, connect to wifi, refer to website https://www.cnblogs.com/lifan3a/articles/7070028.html
3: stm32 configuration
- Using serial port 3 (PB10,PB11) configuration as follows:
<usart3.c> //Serial Receive Buffer u8 USART3_RX_BUF[USART3_MAX_RECV_LEN]; //Receive buffer, maximum USART3_MAX_RECV_LEN bytes. u8 USART3_TX_BUF[USART3_MAX_SEND_LEN]; //Send buffer, maximum USART3_MAX_SEND_LEN bytes vu16 USART3_RX_STA=0; void USART3_IRQHandler(void) { u8 res; if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//Received data { res =USART_ReceiveData(USART3); if((USART3_RX_STA&(1<<15))==0)//If a batch of data has not been processed, no other data will be received. { if(USART3_RX_STA<USART3_MAX_RECV_LEN) //You can also receive data. { if(USART3_RX_STA==0) { } USART3_RX_BUF[USART3_RX_STA++]=res; //Record the received value }else { USART3_RX_STA|=1<<15; //Mandatory Markup Receiving Completion } } } } <usart3.h> #define USART3_MAX_RECV_LEN 1500// Maximum number of received cache bytes #define USART3_MAX_SEND_LEN 600 // / Maximum number of sending buffer bytes #define USART3_RX_EN 1//0, not receive; 1, receive. extern u8 USART3_RX_BUF[USART3_MAX_RECV_LEN]; //Receive buffer, maximum USART3_MAX_RECV_LEN bytes extern u8 USART3_TX_BUF[USART3_MAX_SEND_LEN]; //Send buffer, maximum USART3_MAX_SEND_LEN bytes
Send using at command, code as follows
//Weather Connection Port Number: 80 #define WEATHER_PORTNUM "80" //Weather server IP #define WEATHER_SERVERIP "api.seniverse.com" //Time Port Number #define TIME_PORTNUM "80" //Time Server IP #define TIME_SERVERIP "www.beijing-time.org" void get_time() { resp=mymalloc(SRAMIN,10); p_end=mymalloc(SRAMIN,40); p=mymalloc(SRAMIN,40); //Request 40 bytes of memory sprintf((char*)p,"AT+CIPSTART=\"TCP\",\"%s\",%s",TIME_SERVERIP,TIME_PORTNUM); //Configure the target TCP server u3_printf("%s\r\n",p); delay_ms(1000); u3_printf("AT+CIPMODE=1\r\n"); delay_ms(1000); USART3_RX_STA=0; u3_printf("AT+CIPSEND\r\n"); delay_ms(1000); myfree(SRAMIN,p); //Free memory p=mymalloc(SRAMIN,40); USART3_RX_STA=0; USART3_RX_BUF[0]='\0'; //empty u3_printf("GET /time15.asp HTTP/1.1\r\nHost:www.beijing-time.org\n\n"); delay_ms(1000); //If (USART3_RX_STA&0X8000) // / At this time, another data is received, which is weather data. { USART3_RX_BUF[USART3_RX_STA&0X7FFF]=0;//Adding an End Character resp="Date"; USART3_RX_BUF[USART3_RX_STA & 0x7ff] = 0; //printf("get_tim_srt: %s\r\n",USART3_RX_BUF); if(strstr((char*)USART3_RX_BUF,(char*)resp)) { resp="GMT"; p_end = (u8*)strstr((char*)USART3_RX_BUF,(char*)resp); p = p_end - 9; //printf("get_net_str %s\r\n",p); nwt.hour = ((*p - 0x30)*10 + (*(p+1) - 0x30) + 8) % 24; //GMT0-->GMT8 nwt.min = ((*(p+3) - 0x30)*10 + (*(p+4) - 0x30)) % 60; nwt.sec = ((*(p+6) - 0x30)*10 + (*(p+7) - 0x30)) % 60; nwt.year = ((*(p-5) - 0x30)*1000 + (*(p-4) - 0x30)*100+ (*(p-3) - 0x30)*10+ (*(p-2) - 0x30)); nwt.date = ((*(p-12) - 0x30)*10 + (*(p-11) - 0x30)); if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Jan")) nwt.month=1; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Feb")) nwt.month=2; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Mar")) nwt.month=3; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Apr")) nwt.month=4; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "May")) nwt.month=5; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Jun")) nwt.month=6; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Jul")) nwt.month=7; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Aug")) nwt.month=8; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Sep")) nwt.month=9; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Oct")) nwt.month=10; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Nov")) nwt.month=11; else if ((u8*)strstr((char*)USART3_RX_BUF,(char*) "Dec")) nwt.month=12; printf("nwt.year = %d\r\n",nwt.year); printf("nwt.month = %d\r\n",nwt.month); printf("nwt.date = %d\r\n",nwt.date); //Get data 28 LCD_ShowxNum(78,50,nwt.year,4,16,0); LCD_ShowChar(112,50,'-',16,0); LCD_ShowxNum(120,50,nwt.month/10,1,16,0); LCD_ShowxNum(128,50,nwt.month%10,1,16,0); LCD_ShowChar(136,50,'-',16,0); LCD_ShowxNum(144,50,nwt.date/10,1,16,0); LCD_ShowxNum(152,50,nwt.date%10,1,16,0); printf("nwt.hour = %d\r\n",nwt.hour); printf("nwt.min = %d\r\n",nwt.min); printf("nwt.sec = %d\r\n",nwt.sec); if(nwt.hour >12) { nwt.hour = nwt.hour - 12; LCD_ShowString(112,70,200,16,16,"PM"); } else LCD_ShowString(112,70,200,16,16,"AM"); LCD_ShowxNum(88,90,nwt.hour/10,1,16,0); LCD_ShowxNum(96,90,nwt.hour%10,1,16,0); LCD_ShowChar(104,90,':',16,0); LCD_ShowxNum(112,90,nwt.min/10,1,16,0); LCD_ShowxNum(120,90,nwt.min%10,1,16,0); LCD_ShowChar(128,90,':',16,0); LCD_ShowxNum(136,90,nwt.sec/10,1,16,0); LCD_ShowxNum(144,90,nwt.sec%10,1,16,0); //printf("uddate:nettime!!!"); myfree(SRAMIN,resp); myfree(SRAMIN,p_end); } } USART3_RX_STA=0; USART3_RX_BUF[0]='\0'; //empty //Printf ("% s r n", USART3_RX_BUF);// Print BUF data u3_printf("+++"); //Withdrawal of Pass-through Mode delay_ms(1000); myfree(SRAMIN,p); //Free memory printf("ALL end ....................\r\n"); //End of analysis } void get_weather() { printf("ALL start .......................\r\n"); p=mymalloc(SRAMIN,40); //Request 40 bytes of memory sprintf((char*)p,"AT+CIPSTART=\"TCP\",\"%s\",%s",WEATHER_SERVERIP,WEATHER_PORTNUM); //Configure the target TCP server u3_printf("%s\r\n",p); delay_ms(1000); u3_printf("AT+CIPMODE=1\r\n"); delay_ms(1000); USART3_RX_STA=0; u3_printf("AT+CIPSEND\r\n"); delay_ms(1000); USART3_RX_STA=0; USART3_RX_BUF[0]='\0'; //empty u3_printf("GET https://api.seniverse.com/v3/weather/daily.json?key=pqe1fgv45lrdruq7&location=zhengzhou&language=zh-Hans&unit=c&start=0&days=5\n\n"); delay_ms(1000); if(USART3_RX_STA&0X8000) //At this point, the data is received again, for the weather data. { USART3_RX_BUF[USART3_RX_STA&0X7FFF]=0;//Adding an End Character } parse_3days_weather(); //Analysis of weather //Printf ("% s r n", USART3_RX_BUF);// Print BUF data u3_printf("+++"); //Withdrawal of Pass-through Mode delay_ms(1000); myfree(SRAMIN,p); //Free memory printf("ALL end ....................\r\n"); //End of analysis }
JSON data parsing refers to God from the Internet. Readers can learn it systematically.
Don't talk too much nonsense.