1

I am working on a project about send PWM values and time values(with RTC) from stm32 to wifi module and bluetooth module at the same time.I wrote a code for esp8266 and esp8266 connected to my phone.But didnt send any value to bluetooth module or thingspeak.What did I wrong?(I cant use HAL Library for this project)

static void Clear_ESPBuffer(void)
{
    uint16_t i;

    for(i=0;i<ESP8266BUFFER_LENGHT;i++)
        g_arrui8ESP8266Buf[i] = 0;

    ESPWriteIndex=0;
}
//esp8266 configuration
 USART_InitStruct.USART_BaudRate = 115200;
 USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
 USART_InitStruct.USART_Parity = USART_Parity_No;
 USART_InitStruct.USART_StopBits = USART_StopBits_1;
 USART_InitStruct.USART_WordLength = USART_WordLength_8b;
 USART_Init(USART1, &USART_InitStruct);
//bluetooth modulu configuration
USART_InitStruct.USART_BaudRate = 115200;
 USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 USART_InitStruct.USART_Mode = USART_Mode_Tx;
 USART_InitStruct.USART_Parity = USART_Parity_No;
 USART_InitStruct.USART_StopBits = USART_StopBits_1;
 USART_InitStruct.USART_WordLength = USART_WordLength_8b;
 USART_Init(USART3, &USART_InitStruct);
 USART_Cmd(USART3, ENABLE); // USART3 aktif edilir.


 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
 NVIC_Init(&NVIC_InitStructure);

USART_Cmd(USART1, ENABLE); 
}

static void ESP8266_Init(void)
{
 static uint8_t ESPInitCase=0;

 switch(ESPInitCase)
 {
 case 0:
 // Standart AT Komutu gonderilir , Cevabi OK olmalidir.
 USART_puts(USART1,"AT\r\n");

 Delay(1000000L);
 ESPInitCase = 1;
 break;

case 1:

 if (strstr(g_arrui8ESP8266Buf,"OK") != NULL)
 {
 Clear_ESPBuffer();
 USART_puts(USART3,"Module Erisildi\n");
 ESPInitCase = 2;
 }
 else
 {
 Clear_ESPBuffer();
 USART_puts(USART3,"Not Founded");
 ESPInitCase = 0;
 }
 break;

case 2:

 USART_puts(USART1,"AT+CWMODE?\r\n");

 Delay(1000000L);
 ESPInitCase = 3;
 break;

case 3:
 // Gelen cevap mode 1 'mi
 if (strstr(g_arrui8ESP8266Buf,"+CWMODE:1") != NULL)
 {
 Clear_ESPBuffer();
 USART_puts(USART3,"Config okey\n");
 ESPInitCase = 4;
 }
 else
 {
 .
 USART_puts(USART1,"AT+CWMODE=1\r\n");
 USART_puts(USART1,"AT+RST\r\n");
 Delay(1000000L);

Clear_ESPBuffer();
 USART_puts(USART3,"Changed Mode.\n");
 ESPInitCase = 2;
 }
 break;

case 4:

 USART_puts(USART1,"AT+CWJAP=\"Wifi\",\"Password\"\r\n");
 Delay(2000000L);
 ESPInitCase = 5;
 break;

case 5:
 if (strstr(g_arrui8ESP8266Buf,"OK") != NULL)
 {
 Clear_ESPBuffer();
 USART_puts(USART3,"Wifi Connected\n");
 ESPInitCase = 6;
 }
 else
 {
 Delay(1000000L);
 USART_puts(USART3,"waiting for wifi\n");
 Delay(5000000L);
 say2++;
 if(say2==3)
 {
 USART_puts(USART3,"Not Connected\n");
 ESPInitCase=8;
 say2=0;
 }
 }
 break;

case 6:
 // For ıp adress
 USART_puts(USART1,"AT+CIFSR\r\n");
 Delay(1000000L);
 ESPInitCase = 7;
 break;

case 7:

 if (strstr(g_arrui8ESP8266Buf,"ERROR") == NULL)
 {
 USART_puts(USART3," IP = \n");

 USART_puts(USART3,&g_arrui8ESP8266Buf[11]);
 Clear_ESPBuffer();
 ESPInitCase=8;
 }
 else
 {
 Delay(1000000L);
 USART_puts(USART3,"Try again.\n");
 Clear_ESPBuffer();
 ESPInitCase=6;
 }

break;

case 8:

 USART_puts(USART1,"AT+CIPSTART=\"TCP\",\"IP\",80\r\n");
 // 1 saniye gecikme koyuyoruz.
 Delay(1000000L);
 ESPInitCase = 9;
 break;

case 9:
 if (strstr(g_arrui8ESP8266Buf,"CONNECT") != NULL)
 {
 Clear_ESPBuffer();
 USART_puts(USART3,"connected to website\n");
 ESPInitCase = 10;
 }
 else
 {
 Delay(1000000L);
 USART_puts(USART3,"waiting for Website connection\n");
 Delay(50000000L);
 say++;
 if(say==3)
 {
 USART_puts(USART3," Website didnt work .\n");
 ESPInitCase=8;
 say=0;
 }

 }
 break;

case 10:
 Value=Read_ADC(); // adc okunuyor 


 sprintf(transmitdata, "GET /update?key=9KT9JQA1PJXPTFJJ&field2=%d\r\n",value);

 length=strlen(transmitdata); 
 length=length+2;
 sprintf(transmitconf,"AT+CIPSEND=%d\r\n",length);

 USART_puts(USART1,transmitconf);
 Delay(10000000L);

 if (strstr(g_arrui8ESP8266Buf,">") != NULL)
 {
 Clear_ESPBuffer();
 USART_puts(USART1,transmitdata);
 USART_puts(USART3,"transmitted data\n");
 Delay(2000000L);
 ESPInitCase=10;
 }
 else
 {
 Delay(3000000L);
 USART_puts(USART3,"data length not okey\n");
 ESPInitCase=8;
 USART_puts(USART3,"trying to connect website again\n");
 say3++;
 if(say3==3)
 {
 USART_puts(USART3,"didnt connect.\n check config\n");
 ESPInitCase=0;
 say3=0;
 }
 }


 break;

}
}
void USART1_IRQHandler(void)
{

  if( USART_GetITStatus(USART1, USART_IT_RXNE) )
  {
    uint8_t Received_Byte = USART1->DR; 
    USART2->DR = Received_Byte;


    if(Received_Byte != 0)
    {
      g_arrui8ESP8266Buf[ESPWriteIndex] = Received_Byte;
      ESPWriteIndex++;
    }
  }
}

0 Answers0