Skip to content

Circuitpython websockets implementation

License

Notifications You must be signed in to change notification settings

intGus/cpwebsockets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircuitPython WebSocket Client

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.

⚠️ Work in Progress: Some features may be incomplete or subject to change.

Installation

  1. Download the cpwebsockets folder from this repository and copy it to the root of your CircuitPython device.
  2. Install the required dependency:
    • adafruit_logging: Copy the adafruit_logging library to the lib folder on your CircuitPython device.

Folder Structure

Your CircuitPython device should look like this:

code.py or
example.py
lib/
└── adafruit_logging.mpy
cpwebsockets/
├── client.py
└── protocol.py

Usage

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.

Compatibility

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://).

Tested on:

If you encounter compatibility issues on other devices, please create an issue in this repository.

Features

  • Support for both ws:// and wss:// WebSocket protocols.
  • Frame handling compliant with RFC 6455.
  • Client masking for secure communications.
  • Text and binary message support.
  • Graceful connection close handling.

Known Issues & Limitations

  • Continuation frames (_OP_CONT) are not yet implemented.
  • The library has not been tested extensively on low-memory devices.
  • Minimal support for WebSocket extensions.

Contributing

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.

License

This library is released under the MIT License.

Acknowledgments

This library is a CircuitPython adaptation of uwebsockets by danni.

About

Circuitpython websockets implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%