STM32操作ESP8266(透传)

STM32操作ESP8266,自己可以根据AT执行,相应设置其他状态,完整程序下载

         //测试
       while(!ESP8266_AT_Test()){
           printf2("test error\r\n");
       }
        printf2("test OK\r\n");      
      HAL_Delay(1000);
       //配置STA+AP模式,连接手机server,进入透传模式
       if(ESP8266_Cmd("AT+CWMODE?","OK",0,1000))printf2("mode ok\r\n");
       else printf2("mode error\r\n");
       HAL_Delay(1000);
       if(ESP8266_Cmd("AT+CWSAP?","OK",0,1000))printf2("CWSAP ok\r\n");
       else printf2("CWSAP error\r\n");
       HAL_Delay(1000);
       if(ESP8266_Cmd("AT+CIPMUX?","OK",0,1000))printf2("CIPMUX ok\r\n");
       else printf2("CIPMUX error\r\n");
       HAL_Delay(1000);      
      
       if(ESP8266_Cmd("AT+CIPMODE=1","OK",0,1000))printf2("CIPMODE ok\r\n");
       else printf2("CIPMODE error\r\n");
       HAL_Delay(1000);
       if(ESP8266_Cmd("AT+CIPMUX=0","OK",0,1000))printf2("CIPMUX ok\r\n");
       else printf2("CIPMUX error\r\n");
       HAL_Delay(1000);
       
        while(!ESP8266_Cmd("AT+CWLIF","192",0,1000)){
           printf2("no phone\r\n");
       }
       HAL_Delay(1000);
       //sprintf ( linkTCP, "\"%s\",\"%s\",%s", "TCP", ip, port );
       while(!ESP8266_Cmd("AT+CIPSTART=\"TCP\",\"192.168.4.3\",8234","CONNECT","OK",1000)){
           printf2("no TCP CONNECT\r\n");
       }
       HAL_Delay(1000);
       while(!ESP8266_Cmd("AT+CIPSEND",">",0,1000)){
           printf2("CIPSEND error\r\n");
       }
       printf2("CIPSEND ok\r\n");
       HAL_Delay(1000);
       
       
  /* USER CODE END 2 */
 
 

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      
      LED_on;
      HAL_Delay(100);
      LED_off;
      HAL_Delay(100);
      //透传模式,用usart2输出收到的内容
       if(UsartType.RX_flag)    	// 接收到数据的标志
      {  
           UsartType.RX_flag=0;	//清除接收到标志
           HAL_UART_Transmit(&huart2, (uint8_t *)UsartType.RX_pData, UsartType.RX_Size, 0xFFFF);
      } 
      
     
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

你可能感兴趣的:(ESP8266,stm32,STM32cubemx)