在原子哥的例程上稍微改动了一下,建立STA TCP client 模式下与电脑的通信。接收数据没有问题,但是发送数据只有第一次成功,之后总是连接不上。不知道什么问题,还请大家赐教。
发送数据部分代码如下://WIFI STA ·¢ËÍÊý¾Ý
//length :·¢ËÍÊý¾Ý³¤¶È
//pointer:Ö¸Ïò·¢ËÍÊý¾Ý £¡£¡£¡£¡£¡£¡£¡£¡Ö¸ÕëÀàÐ͸ù¾ÝÊý¾Ý²»Í¬¿ÉÄÜÒª¸Ä£¡£¡£¡
void atk_8266_wifista_send(u8 length,char *pointer)
{
u8 *q;
u8 j;
q=mymalloc(32); //ÉêÇë32×Ö½ÚÄÚ´æ
atk_8266_quit_trans();
while(atk_8266_send_cmd("AT+CIPSEND","OK",20)); //¿ªÊ¼Í¸´«
{
if(!atk_8266_send_cmd("AT+CIPSEND","ERROR",20))//Èô¶Ï¿ª£¬ÔòÖØÐÂÁ¬½Ó
{
sprintf((char*)q,"AT+CIPSTART=\"TCP\",\"%s\",%s","192.168.43.186","8080"); //ÅäÖÃÄ¿±êTCP·þÎñÆ÷
while(atk_8266_send_cmd(q,"OK",200));
atk_8266_send_cmd("AT+CIPMODE=1","OK",200); //´«ÊäģʽΪ£ºÍ¸´«
USART2_RX_STA=0;
atk_8266_quit_trans();
}
}
for(j=0;j<length;j++) //Ñ»··¢ËÍÊý¾Ý
{
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET); //Ñ»··¢ËÍ,Ö±µ½·¢ËÍÍê±Ï
USART_SendData(USART2,*(pointer++));
}
myfree(q); //ÊÍ·ÅÄÚ´æ
}
仿真死在这一步: while(atk_8266_send_cmd("AT+CIPSEND","OK",20)); //¿ªÊ¼Í¸´«
{
if(!atk_8266_send_cmd("AT+CIPSEND","ERROR",20))//Èô¶Ï¿ª£¬ÔòÖØÐÂÁ¬½Ó
{
sprintf((char*)q,"AT+CIPSTART=\"TCP\",\"%s\",%s","192.168.43.186","8080"); //ÅäÖÃÄ¿±êTCP·þÎñÆ÷
while(atk_8266_send_cmd(q,"OK",200));
atk_8266_send_cmd("AT+CIPMODE=1","OK",200); //´«ÊäģʽΪ£ºÍ¸´«
USART2_RX_STA=0;
atk_8266_quit_trans();
}
}
电脑接收结果如下:【Receive from 192.168.43.254 : 25700】:
AT+CIPSEND
L0E+++
AT
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
AT+CIPSEND
|