I used this Kalman Filter by TKJ Electronics.
I based it on this.
The original is for Arduino IDE.
Arduino IDE is a single-tasking development environment, so you can call functions periodically.
On the other hand, ESP-IDF is a multi-tasking development environment and cannot call functions periodically.
There will always be a slight time lag.
For this filter, the sampling period (time difference from the previous execution) is very important.
The original is fixed at 1.0 second, but I changed this to a parameter.
I used this I2Cdev library collection by Jeff Rowberg.
However, I2Cdev has been rewritten for ESP-IDF.
I used this ESP-IDF WebSocket Component.