Skip to main content

A WebSocket client library for MicroPython on ESP32

Project description

micropython-websocket

适用于ESP32的MicroPython WebSocket-client模块。

安装方法

在Thonny中安装到ESP32:

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

使用示例

import websocket

import network
import websocket

def do_connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print("正在连接 Wi-Fi...")
        wlan.connect("你的WiFi名称", "你的WiFi密码")
        while not wlan.isconnected():
            pass
    print("已连接,IP:", wlan.ifconfig()[0])

do_connect()

# 创建连接(替换为你电脑的局域网 IP)
ws = websocket.create_connection("ws://192.168.1.109:8765")

ws.send("Hello, ESP32!")          # 发送文本
reply = ws.recv()                  # 阻塞等待回复
print("收到回复:", reply)

ws.close()                         # 关闭连接
print("连接已关闭")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

micropython_websocket-1.0.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

micropython_websocket-1.0.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file micropython_websocket-1.0.0.tar.gz.

File metadata

  • Download URL: micropython_websocket-1.0.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for micropython_websocket-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b440e22b83080493e678a98a4e9502fed62d9f1b244e64eb3bb6bd42e954b4c1
MD5 7640c81a56ef2037770b723aaebfde0c
BLAKE2b-256 cd4845f89c78d51255c073f397b3c1bbb7e8f84bf2256f50d296a49bc576ea0c

See more details on using hashes here.

File details

Details for the file micropython_websocket-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for micropython_websocket-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64435257a13d25cb8274c67d6e378815b3bc2b97223cc0410d3a7119fa8afdf2
MD5 0ba97b7b8178f22fcc4d0f5ce99c4812
BLAKE2b-256 ddbaed7b1e2b12bfdb9ccd3c2f92ff2c29d7754e7e85cb2c1658c5c29447d009

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page