如何使用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.