Reading AT command response
Hi,
I would like to read AT Command responses back from my ESP2866, as I want to check whether the response is "OK" or "Error". I made a function as below but it doesn't work properly.
The plan is to send AT commands on USART3 and right after that, receiving n expected bytes from USART3. Then, search into the received bytes for expected response ("OK" for example). If it was "OK", returning 'y' and if not 'n'.
It doesn't work properly, for example when I use "response = IMAN_USART_LookupForKeywordInReceivedDataInByteout(USART3 , buffer , sizeof(buffer) , keyword_to_search, byteout); " and the response is "OK", for the first time, the function returns 'y' and after that when I use " response = IMAN_USART_LookupForKeywordInReceivedDataInByteout(USART3 , buffer , sizeof(buffer) , keyword_to_search, byteout); " and the response is "ERROR", again the function returns 'y' while I expect 'n'.
It's making me crazy, I would really appreciate if someone help me with that.
char IMAN_USART_LookupForKeywordInReceivedDataInByteout(USART_TypeDef *USARTx , char *rx_buffer , int size_of_buffer , char *word, int byteout_cnt)
{
static char keyword[50];
static uint8_t char_counter;
static uint8_t keyword_num_of_letters;
static char *ret;
static char return_value;
if(!(LL_USART_IsEnabledIT_RXNE(USARTx)))
{
char_counter=0;
return_value = 'n';
keyword_num_of_letters = 0;
ret = NULL;
sprintf(keyword,word);
for(int i=0;i<sizeof(keyword);i++)
{
if(keyword[i] != 0)
{
keyword_num_of_letters++;
}
}
for(int i=0;i<size_of_buffer;i++)
{
rx_buffer[i]=0;
}
LL_USART_EnableIT_RXNE(USARTx);
}
else
{
if(char_counter <= byteout_cnt)
{
rx_buffer[char_counter++] = USARTx->DR;
}
else
{
ret = strstr(rx_buffer, keyword);
if (ret != NULL)
{
for(int i=0;i<size_of_buffer;i++)
{
rx_buffer[i]=0;
}
char_counter = 0;
return_value = 'y';
}
else
{
for(int i=0;i<size_of_buffer;i++)
{
rx_buffer[i]=0;
}
char_counter = 0;
return_value = 'n';
}
}
}
return return_value;
}