如何关闭ESP8266 Socket-IO客户端的串口调试信息输出
Got it, let's tackle this problem head-on. Those [WS] prefixed logs you're seeing aren't coming from the SocketIOClient code you modified—they're actually from the underlying WebSocket client library that the socket.io-client depends on. Here's how you can shut them off completely:
Locate the WebSocket library's configuration file
Look for a header file likeWebSocketsClient.h(or similar, depending on the exact WebSocket library your project uses) in your libraries folder. Inside this file, search for debug-related macro definitions—common ones are#define WEBSOCKETS_DEBUG 1or#define DEBUG_WEBSOCKETS. Change the value from1to0, or comment out the entire line to disable debug output.Manually strip debug prints from the WebSocket implementation
If you can't find a debug toggle macro, open the WebSocket library's main implementation file (e.g.,WebSocketsClient.cpp). Scan for all lines that useSerial.print(),Serial.println(), or any serial output calls that produce the[WS]logs. Comment out or delete these lines entirely. Pay close attention to blocks labeledsendFrame,handleWebsocketWaitFor, orreadCb—those are the ones generating the logs you're seeing.Double-check your project's serial initialization
Make sure your own code isn't accidentally initializing the defaultSerialport (e.g.,Serial.begin(115200)somewhere insetup()) that these debug logs are using. If you're only usingSerial1for your custom output, ensure no other parts of the code are enabling the primary Serial port.Verify library dependencies in your build environment
If you're using PlatformIO or Arduino IDE with library manager, confirm that you're modifying the correct instance of the WebSocket library (sometimes multiple versions can exist). Clean your build folder and recompile after making changes to ensure the modifications take effect.
Once you've applied these steps, those annoying [WS] debug logs should disappear entirely, leaving only your custom Serial1 output.
内容的提问来源于stack exchange,提问作者Roger Lee

