-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lws]: Add initial support for libwebsockets #718
base: master
Are you sure you want to change the base?
Conversation
91c836c
to
b900029
Compare
05aca45
to
860ee1e
Compare
@@ -3,6 +3,9 @@ idf_component_register() | |||
option(LWS_WITH_EXPORT_LWSTARGETS "Export libwebsockets CMake targets. Disable if they conflict with an outer cmake project." OFF) | |||
set(LWS_WITH_EXPORT_LWSTARGETS OFF) | |||
|
|||
option(LWS_PLAT_FREERTOS "Build for FreeRTOS" ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more common to have options set through Kconfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will try to remove the option lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,6 @@ | |||
# The following lines of boilerplate have to be in your project's CMakeLists | |||
# in this exact order for cmake to work correctly | |||
cmake_minimum_required(VERSION 3.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can require a more recent version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to 3.16
@@ -0,0 +1,5 @@ | |||
version: "2.0.28~0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the version match the libwebsockets release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will bump to lws version
url: https://github.com/espressif/esp-protocols/tree/master/components/libwebsockets | ||
description: TODO:glmfe | ||
dependencies: | ||
idf: '>=5.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idf: '>=5.1' | |
idf: '>=5.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,7 @@ | |||
# Changelog | |||
|
|||
## [0.1.0](https://github.com/espressif/esp-protocols/commits/libwebsockets-v0.1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version to match libwebsocket version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will bump to lws version
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. | ||
|
||
## Example Output | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing expected output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
LWS_PROTOCOL_LIST_TERM | ||
}; | ||
|
||
int app_main(int argc, const char **argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int app_main(int argc, const char **argv) | |
int app_main(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ESP_ERROR_CHECK(example_connect()); | ||
|
||
/* Configure WDT. */ | ||
esp_task_wdt_config_t esp_task_wdt_config = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you had watchdog issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was getting this error message constantly:
E (x) task_wdt: esp_task_wdt_reset(705): task not found
This was being raised by the wdt funtion "esp_task_wdt_reset". So basically, the LWS was kicking the watchdog but hadn't actually registered the task to begin with. So the solution was to add:
TaskHandle_t handle = xTaskGetCurrentTaskHandle();
esp_task_wdt_add(handle);
The code snippet above fixed this error message. However, a new issue might show up, where a timeout occurs if the task hangs for some reason. To avoid an unnecessary system reset, portMAX_DELAY is set, especially in these two scenarios:
- Client: The task stops to wait for the STDIN input. If this is manually done, it will reset the target.
- Server: If the task is waiting for a request, the system may hang if no request is received in time. One potential fix would be to set a shorter LWS timeout than the watchdog timer, ensuring that the timeout triggers before the watchdog and can reset it again. However, I encountered some connection instability when implementing this solution. If necessary, I can further investigate and refine this fix to improve stability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm positive that there might be a better solution for both cases than setting the WDT timer to max, but I don’t think it’s crucial for the outcome of this example. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-cermak Just tagging you since you also showed interest in this section. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E (x) task_wdt: esp_task_wdt_reset(705): task not found
This error message? even if you removed everything related to the task watchdog? this is weird. I'd expect something like
... Task watchdog triggered. The following tasks did not reset the watchdog in time...
@@ -0,0 +1,12 @@ | |||
set(SRC_FILES "lws-client-echo.c") # Define source files | |||
set(INCLUDE_DIRS ".") # Define include directories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually make examples as projects not components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the project is in the cmake one level up (client-echo/CmakeList.txt). It's based on esp_websocket_client/examples/target/
extern int __real_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); | ||
extern int __wrap_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); | ||
|
||
int __wrap_mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you had to use wrap here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
mbedtls_ssl_handshake_step wrap: The issue here was that Libwebsockets wasn't properly handling the asynchronous responses MBEDTLS_ERR_SSL_WANT_READ and MBEDTLS_ERR_SSL_WANT_WRITE. Without this wrap, the handshake process would fail when it shouldn't, so we added the wrap to correctly handle these responses and prevent unnecessary failures.
-
lws_adopt_descriptor_vhost wrap: In this case, the problem was that the struct member info.fi_wsi_name was never being set. On Linux, this didn't cause issues because the vsnprintf function simply printed a (null) string when given a null argument. However, for embedded systems, this behavior resulted in a panic because there was no filtering for null arguments. The wrap was added to address this issue by ensuring the fi_wsi_name was set to a dummy value and preventing the panic.
components/libwebsockets/LICENSE
Outdated
@@ -0,0 +1,202 @@ | |||
|
|||
Apache License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the lws is distributed mostly under MIT, will probably need to switch to MIT license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to MIT license used by LWS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work overall!
#include "stdio.h" | ||
#include <libwebsockets.h> | ||
|
||
extern int __real_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not needed, but maybe useful to keep here (I'd just add a comment that we don't need the original handshake impl)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the comments, thanks!
#include <libwebsockets.h> | ||
|
||
extern int __real_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); | ||
extern int __wrap_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not extern
, right?
extern int __wrap_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); | |
int __wrap_mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, not even necessary, removed :D
@@ -0,0 +1,49 @@ | |||
/* | |||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, also please cleanup the copyrights -- for new files use 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Description