1# Websocket Sample application 2 3(See the README.md file in the upper level 'examples' directory for more information about examples.) 4This example will shows how to set up and communicate over a websocket. 5 6## How to Use Example 7 8### Hardware Required 9 10This example can be executed on any ESP32 board, the only required interface is WiFi and connection to internet or a local server. 11 12### Configure the project 13 14* Open the project configuration menu (`idf.py menuconfig`) 15* Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details. 16* 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) 17 18### Build and Flash 19 20Build the project and flash it to the board, then run monitor tool to view serial output: 21 22``` 23idf.py -p PORT flash monitor 24``` 25 26(To exit the serial monitor, type ``Ctrl-]``.) 27 28See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. 29 30## Example Output 31 32``` 33I (482) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 34I (2492) example_connect: Ethernet Link Up 35I (4472) tcpip_adapter: eth ip: 192.168.2.137, mask: 255.255.255.0, gw: 192.168.2.2 36I (4472) example_connect: Connected to Ethernet 37I (4472) example_connect: IPv4 address: 192.168.2.137 38I (4472) example_connect: IPv6 address: fe80:0000:0000:0000:bedd:c2ff:fed4:a92b 39I (4482) WEBSOCKET: Connecting to ws://echo.websocket.org... 40I (5012) WEBSOCKET: WEBSOCKET_EVENT_CONNECTED 41I (5492) WEBSOCKET: Sending hello 0000 42I (6052) WEBSOCKET: WEBSOCKET_EVENT_DATA 43W (6052) WEBSOCKET: Received=hello 0000 44 45I (6492) WEBSOCKET: Sending hello 0001 46I (7052) WEBSOCKET: WEBSOCKET_EVENT_DATA 47W (7052) WEBSOCKET: Received=hello 0001 48 49I (7492) WEBSOCKET: Sending hello 0002 50I (8082) WEBSOCKET: WEBSOCKET_EVENT_DATA 51W (8082) WEBSOCKET: Received=hello 0002 52 53I (8492) WEBSOCKET: Sending hello 0003 54I (9152) WEBSOCKET: WEBSOCKET_EVENT_DATA 55W (9162) WEBSOCKET: Received=hello 0003 56 57``` 58 59