如何使用ESP32制作Arduino WebSocket服务器



WebSocket协议是在服务器和客户端之间进行通信而无需HTTP的有用工具。在这里,我展示了如何在ESP32上创建一个Arduino WebSocket服务器,该服务器将简单的文本消息回显到连接的客户端。我使用基本的Python脚本测试服务器。

视频中的Arduino和Python代码可在以下位置找到:http://shawnhymel.com/1675/arduino-websocket-server-using-an-esp32/。

18 comments
  1. Hello Awesome video! I have both scripts up and running. Im wondering if there is a way to convert the String" " data send from the python script in arduino to an integer. I am trying to send pwm values to drive a motor.

  2. when approaching the esp32 via python on pc, it works, but when I use android and a DNS routing, the app says connected, but the arduinoESP32 does not answer, nor say it is connected. Any clou ?

  3. Hi, I tried your ESP32 server example with a browser but could not make it work. Can you offer an example with ws used by browser to connect to the ESP32 please?

  4. Just in case someone has problems with the connection like me:

    import websocket

    # Connect to WebSocket server

    ws = websocket.WebSocket(sslopt={"check_hostname": False})

    ws.connect("ws://192.168.1.250")

    print("Connected to WebSocket server")

    # Ask the user for some input and transmit it

    str = input("Say something: ")

    ws.send(str)

    # Wait for server to respond and print it

    result = ws.recv()

    print("Received: " + result)

    # Gracefully close WebSocket connection

    ws.close()

    That code worked for me

  5. Hello sir, at the moment I'm working on ESP32 to control relay module via the Internet. I can connect my ESP32 board to WiFi and control the relays using web browser. However, instead of using WiFi, I want to use the Ethernet cable for connection. I've searched a lot on the Internet but found nothing useful. Could you please give me some advice on how to implement ethernet connection. (I'm using board SOM-ESP32-1 which has LAN8720, EMAC RMII interface). Thanks for your help.

  6. I really like your presentation style. Precise, easy to follow and high quality production. A shame that the channel is a bit underrated.

Comments are closed.