Skip to main content
Associate
March 14, 2025
Question

Implement WebSocket Protocol on STM32?

  • March 14, 2025
  • 4 replies
  • 2865 views

Hello,

I am currently working on a project with an HTTP server, successfully implemented using FreeRTOS. In this setup, I handle client requests for opening and collecting data from the client side. However, since I need to display real-time data on a web page (for an IoT application), it has become necessary to implement the WebSocket protocol.

I am looking to implement a WebSocket server on my STM32f746G-DISCO. Unfortunately, I have not been able to find any working examples of WebSocket implementation on STM32.

Could you kindly point me in the direction of any relevant examples or provide some guidance on how to get started with this? Also, I would appreciate any insights regarding whether I need to modify my CubeMX configuration when implementing WebSocket, or if the standard initialization is sufficient — enabling ETH, activating lwIP (httpd) without DHCP, and activating FreeRTOS with the default task where the following initialization is done:

MX_LWIP_Init();
http_server_init();

Any help would be greatly appreciated.

Thank you in advance!

Best regards,

@AS5 

4 replies

mbarg.1
Senior III
March 15, 2025

We did work out a websockets solution for H7 that work great but using AZRTOS as OS.

We had before a solution with FreeRtos but it was not rugged enough and we dropped a couple of years ago.

Our designs require a very resilient and robust performance, with true real time interaction with multiple clients.

Should you think to move to AZRTOS, let me know.

Intector
Senior
April 10, 2025

Hello @mbarg.1,

I'm working on a project for which I designed a board with an STM32H7R3L8H6H MCU, an APS256XXN-OBR-BG 256MBit PSRAM on HEXASPI, an MX25UW25645GXDI00-T 256MBit flash on OCTOSPI, and an EMMC08G-MV28-01J10 SDMMC, among other peripherals.

Here are some pictures of it:

20250118_131125.jpg

20250118_162939.jpg

TagID-DCU_01.jpg

TagID-DCU_02.jpg

 

I worked out all the major kinks, and the system runs pretty well. However, there's something that bothers me quite a bit. I'm running AZRTOS and have an HTTP server for the web interface for settings and manual operations of the device. I would like to optimize the system by getting rid of the long-running HTTP requests that I use to get feedback from the HTTP server to the web interface. Trust me, I tried almost every trick in the book, but nothing worked out better than what I have.

I tried SSE, but the HTTP server mixed up the requests. In the next step, I created a second HTTP server just for SSE, but the response headers to the client connection attempt have "Connection: Close" in them, which triggers the closing of the connection after the first event. 

The WebSocket runs on the server side and requires Node.js, and I couldn't get something like this running on my system. In one of my last attempts to find answers, I accidentally stumbled over this post in which you state that you've worked out a solution for that. 

I would be happy to try this on my system. Can you share your solution or at least some information on how you solved this issue?

 

 

Thank you, and to everyone else out there:

The secret is to keep banging the rocks together, guys.

 

mbarg.1
Senior III
April 10, 2025

Yes, I will be happy to share it with you BUT I am actually out of office for a business trip.

I will reply Monday, once back in office.

Intector
Senior
April 10, 2025

Thank you very much. Have a safe trip and a great weekend.

Intector
Senior
April 14, 2025

Hey @mbarg.1,

Thank you for the answer. I do have several different boards available that I could utilize for something like this, here is a list:

  • NUCLEO-H723ZG
  • NUCLEO-H753ZI
  • NUCLEO-H7S3L8

I made and extension board with an eMMC and an extension board with an eMMC + OctoSPI PSRAM. These boards work with those NUCLEOs. Here are some pictures:

NUCLEO-EXT with eMMC chipNUCLEO-EXT with eMMC chip

NUCLEO-EXT with eMMC on NUCLEO-H7S3L8NUCLEO-EXT with eMMC on NUCLEO-H7S3L8

NUCLEO-EXT with eMMC + OctoSPI PSRAM after reflowNUCLEO-EXT with eMMC + OctoSPI PSRAM after reflow

NUCLEO-EXT with eMMC + OctoSPI on NUCLEO-H723ZGNUCLEO-EXT with eMMC + OctoSPI on NUCLEO-H723ZG

NUCLEO-EXT with eMMC + OctoSPI PSRAMNUCLEO-EXT with eMMC + OctoSPI PSRAM

NUCLEO-EXT with eMMC on NUCLEO-H753ZINUCLEO-EXT with eMMC on NUCLEO-H753ZI

To be frank, I was already playing with the idea of making my own Websocket-Server. Unfortunately, my day has only 24 hours and I have to work for a living. Nevertheless, I am very curious to see your approach on this.

 

Thank you, and keep in mind:

"Be brave and attack.
If the enemy retreats, pursue.
If you encounter resistance, run away."

 

 

mbarg.1
Senior III
April 16, 2025

Hi,

sorry for being late but in Italy (where I am based) we are facing 2 weeks of holiday and everybody has something to ask.

Here a project you can load on Nucleo-H743/753.

You should get the same result as you can see browsing HTTP://o6.mb-international.net (ipv6)

and HTTP://a.mb-international.net:8743/ (ipv4).

Don't be afraid of amount of code, this is a real design, already work in progress.

In MB_config/MB_lib_cfg.h you can turn on and off any part of the code; once turned off, you can remove all related code; but this will be later.

c5_az_h743orto.zip use our improved ethernet drivers.

I do include also c5_az_h743orto_stm,zip; is the same design but our drivers are disabled and uses STM package for ethernet.

For general discussion, we can keep on this forum; for more interaction, you can reach me @mikebargauan@mb-international.com.

 

Intector
Senior
May 3, 2025

Hello,

no problem, I was hung up with other projects myself. Thank you for sharing your code, I'll have a look as soon as I get a minute. 

Visitor II
January 13, 2026

Hi there! 

I hope you are doing good 

I am too working on this project where I need STM32 NUCLEO F767ZI working as a websocket server and esp32 as a websocket client. I am using Arduino IDE not CubeIDE of STM32

Did you complete your project? 

I was wondering if you could help me with it 

mbarg.1
Senior III
January 13, 2026

WebSockets is in production on many items and working fine.

We already moved to a new generation of network solutions with better reliability and flexibility, also this solution includes WebSockets server.

Only drawback, we never used F7 - all our customers are H7 focused, some are looking to H5 but not yet ready for that.

Waht kind of help are you looking for?

Mike

Visitor II
January 14, 2026
I am working on this project where I have to access real time updates
between STM32 (Nucleo-144 F767ZI) as websocket server and ESP32 (Wroom
Devkit V1) as webocket client. I am using Arduino IDE not CubeIDE. I have
installed various libraries and have done some coding as well but the
connection is not being established. Every time I solve one error new one
pops out of nowhere.

Any done examples or reference would be helpful.