cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting stm32F7 Disco board to WIFI network using esp8266

NB1
Associate II

Hello everyone,

I'm currently attempting to connect the STM32F769I-DISCO to a WiFi network using an ESP8266-01 module. I've enabled UART5 and assigned it to the ESP's RX and TX pins, as specified in the STM32F7 datasheet, and I've supplied power to the CH_PD pin on the ESP8266. However, I'm encountering an issue where I'm not receiving any responses from the ESP8266 in the debugger console.

So my questions are:

1. Am I using the correct code to activate and connect the ESP8266 to WiFi?
2. How can I determine if the ESP8266 is sending responses once it's successfully connected?

Here's the program that I've used:

 [

void ESP8266_Init(void)
{
  // Enable ESP8266 module
    GPIO_ctrl_ESP8266(GPIO_ON); // Stm32 PH7 pin (output) is connected to ESP8266 enable pin CH_PD
 
  // Wait for ESP8266 to initialize (adjust delay as needed)
  HAL_Delay(1000);
}

void ESP8266_Setup(void)
{
  // Send AT command to reset ESP8266
  char resetCommand[] = "AT+RST\r\n";
  HAL_UART_Transmit(&huart5, (uint8_t*)resetCommand, strlen(resetCommand), HAL_MAX_DELAY);
 
  // Wait for ESP8266 to reset (adjust delay as needed)
  HAL_Delay(2000);
 
  // Connect to WiFi network (replace "SSID" and "password" with your WiFi credentials)
  char connectCommand[50];
  sprintf(connectCommand, "AT+CWJAP=\"Dali\",\"123456789\"\r\n"); 
  HAL_UART_Transmit(&huart5, (uint8_t*)connectCommand, strlen(connectCommand), HAL_MAX_DELAY);

  // Send AT command to query WiFi connection status
  char queryCommand[] = "AT+CWJAP?\r\n";
  HAL_UART_Transmit(&huart5, (uint8_t*)queryCommand, strlen(queryCommand), HAL_MAX_DELAY);

  // Receive response from ESP8266
  char rxData[100];
  HAL_UART_Receive(&huart5, (uint8_t*)rxData, sizeof(rxData), HAL_MAX_DELAY);


  // Print received response
  printf("Received response: %s\n", rxData); // Add this line to print the received response

   // Parse response to check WiFi connection status
   if (strstr(rxData, "OK") != NULL) {
     // WiFi connection successful
     printf("WiFi connected successfully!\n");
   } else {
     // WiFi connection failed
     printf("WiFi connection failed!\n");
   }
}
int main(void)
{
// Initialize ESP8266 module
  ESP8266_Init();
 
  // Setup ESP8266 (set mode and connect to WiFi network)
  ESP8266_Setup();
while (1)
  {
}
}
]

Any insights or suggestions would be greatly appreciated.

Thank you,

BR,

Nourhene.

3 REPLIES 3
INaee.1
Senior

hi

 

IDK , why my previous message to you deleted ..

:face_with_rolling_eyes:

 

I.N

Please use this button to properly post source code:

AndrewNeil_1-1716210469829.png

 

Before trying to do this in embedded code, are you able to communicate with the ESP using a terminal app on a PC?

You should use this first to gain understanding of the commands you need, and the responses to expect.

With your STM32 code, have you connected it to a terminal app on a PC, and verified that it is actually sending the correct commands, and accepts expected responses? Be sure to check it with ERROR responses, too!

 

Some tips here on debugging serial comms:

https://www.avrfreaks.net/s/topic/a5C3l000000UaO0EAK/t153662?comment=P-1375047

 

 


@NB1 wrote:
  // Wait for ESP8266 to initialize (adjust delay as needed)
  HAL_Delay(1000);

 


It's best to avoid the use of arbitrary delays - does the ESP not provide some positive indication when it's ready?

This is especially true with AT commands: do not rely upon arbitrary, "blind" delays - always handle the reply from the module.

This is probably the commonest mistake in AT Command interfaces; eg,

https://www.avrfreaks.net/s/topic/a5C3l000000UYp7EAG/t147655?comment=P-1409865

 

EDIT:

 


@NB1 wrote:

I'm not receiving any responses from the ESP8266 in the debugger console.


Are you talking about these:


@NB1 wrote:
  // Print received response
  printf("Received response: %s\n", rxData); // Add this line to print the received response
.

Are you sure your printf implementation is working? How have you proved it?

 

INaee.1
Senior

Hi

I have comprehensive esp8266 config utility made by me in vb.net long back.

Contact privately coz my message in forum getting deleted several times.

Regards

I.N