Table of Contents:
At the start of this project, it was possible to connect LEGO SPIKE and LEGO Science hardware to channels (a JSON wrapper over a PyScript.com WebSocket) via Chris’s Talking to Anyone and Summer25 **PyScript.com pages, respectively. In addition, ESP32 devices could be connected to channels using the Talking to Anyone page.
This worked by first connecting the devices to the webpage, which then handled the WebSocket connection to the channel. The connection itself was difficult to establish because the PyScript.com WebSocket uses the WSS protocol which is a secure version of the WebSocket API that requires additional processing (e.g., masking, different framing). Despite the complexity, these connections were fast and reliable.
For later clarification: SSL (Secure Sockets Layer) is a cryptographic protocol that provides secure communication over a computer network. In the context of the web, it is commonly used to secure HTTP connections, resulting in HTTPS. Similarly, WSS (WebSocket Secure) uses SSL/TLS to secure WebSocket communication. Just as HTTPS is HTTP over SSL/TLS, WSS is WebSocket over SSL/TLS.
With this in mind, the goal of this project was to create an equally reliable and fast WebSocket implementation that could run on the CEEO’s Smart Motors (devices that use an ESP32 as the primary microcontroller). Although several robust Python libraries exist to handle this type of secure connection (see the code Chris and I wrote here: Python Solutions), as of summer 2025, MicroPython still lacks many of the necessary libraries to support SSL and WSS communication.
Therefore, the ultimate goal was to develop a wireless solution without relying on a PyScript webpage that would allow Smart Motors to send and receive data to and from channels directly.
Throughout the project I continued to pivot and explore alternatives for both connecting to the channels and other methods of wireless connection between the ESP32s (over the internet). You can find all of that code and explanations of how well it worked in the GitHub’s README. However, the final version that uses the technologies described in the Background section can be found in the final_websocket/final folder in the GitHub. This version had quite a lot of delay in Smart Motor to Smart Motor connections, but there was a noticeable improvement in Smart Motor to LEGO Science Hardware connections (see more below).
<aside> 💡
DISCLAIMER: the code in this folder is made specifically for Smart Motors. There is a lot of debug code that prints to the Smart Motor OLED screen so this code will not run on another device without significant edits.
</aside>