如何在Arduino中使用ESP32创建Web服务器(带有WebSocket)



这是ESP32 WebSocket服务器视频的延续:https://www.youtube.com/watch?v=ZbX-l1Dl4N4。让我们再上一个台阶!我们首先使用Arduino在ESP32上托管Web服务器和WebSocket服务器。接下来,我们使用SPIFFS上传一个单独编写的简单index.html页面。该页面将打开一个与ESP32的WebSocket连接,在这里我们可以使用页面的按钮来切换LED(相对较快)。

请注意,此处我们将ESP32用作接入点(AP)以简化过程。如果希望将Web服务器放置在本地网络上,则可以取消访问点。

WebSocket在客户端和服务器之间提供了持久的连接,因此任何一方都可以随时发送数据。它们在联网视频游戏等方面非常有用,但如果我们需要通过网络快速控制硬件,它们也可以应用于IoT设备。

视频中的Arduino和HTML代码可以在以下位置找到:http://shawnhymel.com/1882/how-to-create-a-web-server-with-websockets-using-an-esp32-in-arduino/。

14 comments
  1. Hi, I would like to ask the way around. How about create a node websocket server and client, and esp32 as an endpoint just to send data to server. Is that possible?

  2. „A few months ago“ – man, feels more like ages. But as always, great work, clean code. Minor improvement could be made trough the use of a captive portal, which opens directly after connecting to the access point. thumbs up

Comments are closed.