初中生
最后登录1970-1-1
在线时间 小时
注册时间2016-2-15
|
通过指南者学习ES8266时,发现移植火哥的代码,ESP8266在AP模式下,上位机发送指令,ESP8266返回数据时会有2-3S的延时,STA模式下收到指令就会立马返回数据,不知道这个是什么原因,哪位大神能帮忙解决下。/**
* @brief ESP8266 (AP Server )工作
* @param 无
* @retval 无
*/
void ESP8266_ApTcpServer_Worktest ( void )
{
uint8_t ucId, ucLen;
uint8_t ucLed1Status = 0, ucLed2Status = 0, ucLed3Status = 0, ucBuzzerStatus = 0;
char cStr [ 100 ] = { 0 }, cCh;
char * pCh, * pCh1;
if ( strEsp8266_Fram_Record .InfBit .FramFinishFlag )
{
USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, DISABLE ); //禁用串口接收中断
strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ] = '\0';
USART1_printf("%s\r\n",strEsp8266_Fram_Record .Data_RX_BUF);
if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_LED_" ) ) != 0 )
{
cCh = * ( pCh + 8 );
switch ( cCh )
{
case '1':
cCh = * ( pCh + 10 );
switch ( cCh )
{
case '0':
macLED1_OFF ();
ESP8266_SendString ( DISABLE, LED_State[1], strlen ( LED_State[0]), Multiple_ID_0 );
break;
case '1':
macLED1_ON ();
ESP8266_SendString ( DISABLE, LED_State[0], strlen ( LED_State[0]), Multiple_ID_0 );
break;
default :
break;
}
break;
case '2':
cCh = * ( pCh + 10 );
switch ( cCh )
{
case '0':
macLED2_OFF ();
break;
case '1':
macLED2_ON ();
ESP8266_SendString ( ENABLE, LED_State[2], 0, Single_ID_0 );
break;
default :
break;
}
break;
case '3':
cCh = * ( pCh + 10 );
switch ( cCh )
{
case '0':
macLED3_OFF ();
ESP8266_SendString ( ENABLE, LED_State[5], 0, Single_ID_0 );
break;
case '1':
macLED3_ON ();
ESP8266_SendString ( ENABLE, LED_State[4], 0, Single_ID_0 );
break;
default :
break;
}
break;
default :
break;
}
}
/*sprintf ( cStr, "CMD_LED_END_%d_%d_%dDHT11_BUZZER_%d_ENDBUZZER_END",
ucLed1Status, ucLed2Status, ucLed3Status,
ucBuzzerStatus );
if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "+IPD," ) ) != 0 )
{
ucId = * ( pCh + strlen ( "+IPD," ) ) - '0';
ESP8266_SendString ( DISABLE, cStr, strlen ( cStr ), ( ENUM_ID_NO_TypeDef ) ucId );
}*/
strEsp8266_Fram_Record .InfBit .FramLength = 0;
strEsp8266_Fram_Record .InfBit .FramFinishFlag = 0;
USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, ENABLE ); //使能串口接收中断
}
}
/*
* 函数名:ESP8266_SendString
* 描述 :WF-ESP8266模块发送字符串
* 输入 :enumEnUnvarnishTx,声明是否已使能了透传模式
* :pStr,要发送的字符串
* :ulStrLength,要发送的字符串的字节数
* :ucId,哪个ID发送的字符串
* 返回 : 1,发送成功
* 0,发送失败
* 调用 :被外部调用
*/
bool ESP8266_SendString ( FunctionalState enumEnUnvarnishTx, char * pStr, u32 ulStrLength, ENUM_ID_NO_TypeDef ucId )
{
char cStr [20];
bool bRet = false;
if ( enumEnUnvarnishTx )
{
ESP8266_Usart ( "%s", pStr );
bRet = true;
}
else
{
if ( ucId < 5 )
sprintf ( cStr, "AT+CIPSEND=%d,%d", ucId, ulStrLength + 2 );
else
sprintf ( cStr, "AT+CIPSEND=%d", ulStrLength + 2 );
ESP8266_Cmd ( cStr, "> ", 0, 1000 );
bRet = ESP8266_Cmd ( pStr, "SEND OK", 0, 1000 );
}
return bRet;
}
|
|