A lightweight WebSocket client library for CircuitPython. This library allows you to connect to WebSocket servers, send and receive data, and handle WebSocket frames with ease.
- Download the
cpwebsocketsfolder from this repository and copy it to the root of your CircuitPython device. - Install the required dependency:
adafruit_logging: Copy theadafruit_logginglibrary to thelibfolder on your CircuitPython device.
Your CircuitPython device should look like this:
code.py or
example.py
lib/
└── adafruit_logging.mpy
cpwebsockets/
├── client.py
└── protocol.py
A minimal example is provided in the example.py file, demonstrating how to:
- Connect to a WebSocket server (
wss://ws.postman-echo.com/raw). - Send and receive messages.
- Close the WebSocket connection gracefully.
Simply copy the example.py file to your CircuitPython device and modify it as needed for your project.
This library is designed to work with CircuitPython devices that support:
- Wi-Fi connections (via
wifi.radio). - TLS/SSL (for secure WebSocket connections using
wss://).
If you encounter compatibility issues on other devices, please create an issue in this repository.
- Support for both
ws://andwss://WebSocket protocols. - Frame handling compliant with RFC 6455.
- Client masking for secure communications.
- Text and binary message support.
- Graceful connection close handling.
- Continuation frames (
_OP_CONT) are not yet implemented. - The library has not been tested extensively on low-memory devices.
- Minimal support for WebSocket extensions.
We welcome contributions! If you'd like to report a bug, suggest a feature, or submit a pull request, please open an issue in this repository. Ensure your contributions adhere to CircuitPython's design guidelines.
This library is released under the MIT License.
This library is a CircuitPython adaptation of uwebsockets by danni.