Skip to main content

micropython-websockets

适用于ESP32的异步MicroPython WebSockets模块。

安装方法

在Thonny中安装到ESP32:

  1. 用USB将ESP32连接到电脑
  2. 打开Thonny,右下角切换为 MicroPython(ESP32)
  3. 菜单 Tools → Manage packages
  4. 搜索 micropython-websockets
  5. 点击安装

使用示例

import asyncio
import network
import micropython_websockets as websockets

# ── Wi-Fi 连接 ─────────────────────────────────────────────────────────────
async def connect_wifi(ssid, password):
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print("正在连接 Wi-Fi...")
        wlan.connect(ssid, password)
        while not wlan.isconnected():
            await asyncio.sleep(0.5)
    print("Wi-Fi 已连接,IP:", wlan.ifconfig()[0])

# ── WebSocket 客户端 ────────────────────────────────────────────────────────
async def main():
    await connect_wifi("你的WiFi名称", "你的WiFi密码")

    # 替换为 PC 的局域网 IP
    uri = "ws://192.168.1.107:8765"

    async with websockets.connect(uri) as ws:
        print("已连接到服务器:", uri)

        # 发送消息
        await ws.send("Hello from ESP32!")
        print("已发送: Hello from ESP32!")

        # 接收回复
        reply = await ws.recv()
        print("收到回复:", reply)

    print("连接已关闭")

asyncio.run(main())

Metadata

Release files for micropython-websockets 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micropython-websockets 0.1.0
File Size Uploaded Provenance Actions
micropython_websockets-0.1.0.tar.gz 16.3 kB Without provenance Details for micropython_websockets-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for micropython-websockets 0.1.0
File Interpreter ABI Platform Actions
micropython_websockets-0.1.0-py3-none-any.whl Python 3 none any Details for micropython_websockets-0.1.0-py3-none-any.whl

Total release size: 31.9 kB

Release files / micropython_websockets-0.1.0.tar.gz

Download URL micropython_websockets-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f822e91d042233812aa18a6038ede40cdc89d3ede716330365a3f0ff7a8fd0b1
BLAKE2b-256 checksum
How to use checksums
51b374e820f5cb3e995d27cc9f215f4fb85be1666cf0fd63fb269a38f201e89e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release files / micropython_websockets-0.1.0-py3-none-any.whl

Download URL micropython_websockets-0.1.0-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9029dadbd50482e8139b99ee4ec9ba37e64a02874bfcc32a7d96ec07bf095803
BLAKE2b-256 checksum
How to use checksums
4b403fd5675fd0018db54bf79c3551e2baa775984a1c4983fd5516c8c6d19c8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Security for micropython-websockets 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page