Skip to content

Commit e21d306

Browse files
committed
docs(websocket): enhance README with TOC, quick start and add pytest dependencies and execution instructions
1 parent 6f6237a commit e21d306

File tree

1 file changed

+116
-2
lines changed
  • components/esp_websocket_client/examples/target

1 file changed

+116
-2
lines changed

components/esp_websocket_client/examples/target/README.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
# Websocket Sample application
22

3-
This example will shows how to set up and communicate over a websocket.
3+
This example shows how to set up and communicate over a websocket.
4+
5+
## Table of Contents
6+
7+
- [Hardware Required](#hardware-required)
8+
- [Configure the project](#configure-the-project)
9+
- [Pre-configured SDK Configurations](#pre-configured-sdk-configurations)
10+
- [Server Certificate Verification](#server-certificate-verification)
11+
- [Generating Self-signed Certificates](#generating-a-self-signed-certificates-with-openssl)
12+
- [Build and Flash](#build-and-flash)
13+
- [Testing with pytest](#testing-with-pytest)
14+
- [Example Output](#example-output)
15+
- [Python Flask Echo Server](#python-flask-echo-server)
16+
17+
## Quick Start
18+
19+
1. **Install dependencies:**
20+
```bash
21+
pip install -r esp-protocols/ci/requirements.txt
22+
```
23+
24+
2. **Configure and build:**
25+
```bash
26+
idf.py menuconfig # Configure WiFi/Ethernet and WebSocket URI
27+
idf.py build
28+
```
29+
30+
3. **Flash and monitor:**
31+
```bash
32+
idf.py -p PORT flash monitor
33+
```
34+
35+
4. **Run tests:**
36+
```bash
37+
pytest .
38+
```
439

540
## How to Use Example
641

@@ -15,6 +50,27 @@ This example can be executed on any ESP32 board, the only required interface is
1550
* Configure the websocket endpoint URI under "Example Configuration", if "WEBSOCKET_URI_FROM_STDIN" is selected then the example application will connect to the URI it reads from stdin (used for testing)
1651
* To test a WebSocket client example over TLS, please enable one of the following configurations: `CONFIG_WS_OVER_TLS_MUTUAL_AUTH` or `CONFIG_WS_OVER_TLS_SERVER_AUTH`. See the sections below for more details.
1752

53+
### Pre-configured SDK Configurations
54+
55+
This example includes several pre-configured `sdkconfig.ci.*` files for different testing scenarios:
56+
57+
* **sdkconfig.ci** - Default configuration with WebSocket over Ethernet (IP101 PHY, ESP32, IPv6) and hardcoded URI.
58+
* **sdkconfig.ci.plain_tcp** - WebSocket over plain TCP (no TLS, URI from stdin) using Ethernet (IP101 PHY, ESP32, IPv6).
59+
* **sdkconfig.ci.mutual_auth** - WebSocket with mutual TLS authentication (client/server certificate verification, skips CN check) and URI from stdin.
60+
* **sdkconfig.ci.dynamic_buffer** - WebSocket with dynamic buffer allocation, Ethernet (IP101 PHY, ESP32, IPv6), and hardcoded URI.
61+
62+
To use a specific configuration for building:
63+
```
64+
rm sdkconfig
65+
cp sdkconfig.ci.plain_tcp sdkconfig
66+
idf.py build
67+
```
68+
69+
Or specify it directly when building:
70+
```
71+
idf.py -DSDKCONFIG_DEFAULTS="sdkconfig.ci.plain_tcp" build
72+
```
73+
1874
### Server Certificate Verification
1975

2076
* Mutual Authentication: When `CONFIG_WS_OVER_TLS_MUTUAL_AUTH=y` is enabled, it's essential to provide valid certificates for both the server and client.
@@ -73,7 +129,36 @@ idf.py -p PORT flash monitor
73129

74130
(To exit the serial monitor, type ``Ctrl-]``.)
75131

76-
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
132+
See the [ESP-IDF Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.
133+
134+
## Testing with pytest
135+
136+
### Install Dependencies
137+
138+
Before running the pytest tests, you need to install the required Python packages:
139+
140+
```
141+
pip install -r esp-protocols/ci/requirements.txt
142+
```
143+
144+
### Run pytest
145+
146+
After installing the dependencies, you can run the pytest tests:
147+
148+
Run all tests in current directory:
149+
```
150+
pytest .
151+
```
152+
153+
Run specific test file:
154+
```
155+
pytest pytest_websocket.py
156+
```
157+
158+
To specify the target device or serial port, use:
159+
```
160+
pytest --target esp32 --port /dev/ttyUSB0
161+
```
77162

78163
## Example Output
79164

@@ -135,3 +220,32 @@ if __name__ == '__main__':
135220
# gunicorn -b 0.0.0.0:5000 --workers 4 --threads 100 module:app
136221
app.run(host="0.0.0.0", debug=True)
137222
```
223+
224+
## Troubleshooting
225+
226+
### Common Issues
227+
228+
**Connection failed:**
229+
- Verify WiFi/Ethernet configuration in `idf.py menuconfig`
230+
- Check if the WebSocket server is running and accessible
231+
- Ensure the URI is correct (use `wss://` for TLS, `ws://` for plain TCP)
232+
233+
**TLS certificate errors:**
234+
- For self-signed certificates, ensure `CONFIG_WS_OVER_TLS_SKIP_COMMON_NAME_CHECK=y` is enabled
235+
- Verify certificate files are properly formatted and accessible
236+
237+
**Build errors:**
238+
- Clean build: `idf.py fullclean`
239+
- Check ESP-IDF version compatibility
240+
- Verify all dependencies are installed
241+
242+
**Test failures:**
243+
- Ensure the device is connected and accessible via the specified port
244+
- Check that the target device matches the configuration (`--target esp32`)
245+
- Verify pytest dependencies are installed correctly
246+
247+
### Getting Help
248+
249+
- Check the [ESP-IDF documentation](https://docs.espressif.com/projects/esp-idf/)
250+
- Review the [WebSocket client component documentation](../../README.md)
251+
- Report issues on the [ESP Protocols repository](https://github.com/espressif/esp-protocols)

0 commit comments

Comments
 (0)