Debugging Wi-Fi Signal Strength with ESP32 and Xedge32

When working on ESP32-based projects, maintaining a reliable Wi-Fi connection is necessary for uninterrupted development. Xedge32 serves its IDE directly from the ESP32, making weak Wi-Fi signals a common source of frustration. This guide explains how to use the RSSI monitoring page as a mobile debugging tool to optimize Wi-Fi reception.

This debugging tool simplifies ensuring robust Wi-Fi communication during development and deployment. Providing real-time feedback on signal strength empowers you to make quick adjustments to your setup.

Setting Up the RSSI Monitoring Page

  1. Deploy the Page on ESP32
    Using Xedge32, create a new LSP app (web application) and leave the directory name blank to make it a root app. In this app, create index.lsp. Copy the content from the file CheckWiFi.lsp and paste the content into index.lsp. Save the file.
  2. Connect to the ESP32 Wi-Fi Network
    Using your mobile phone, connect to the same Wi-Fi network as the network the ESP32 is connected to. Open a browser and navigate to http://xedge32.local to access the RSSI monitoring page.
  3. Monitor Signal Strength
    The page prominently displays the RSSI (Received Signal Strength Indicator) value, which represents the strength of the Wi-Fi signal.

Moving Around to Optimize Signal

  1. Carry Both Devices
    Keep your mobile phone and the ESP32 close together to ensure accurate signal tracking.
  2. Observe RSSI Changes
    Move around your workspace with the ESP32 while keeping an eye on the RSSI value displayed on the page. Stronger signals are indicated by RSSI values closer to zero (e.g., -50 is better than -80). See function esp32.apinfo() for details.

How the Tool Works

This LSP (Lua Server Pages) file combines server-side Lua code and client-side HTML/JavaScript to create a tool for monitoring and optimizing Wi-Fi signal strength (RSSI) on an ESP32 device. Here's how each part works:

Server-Side (Lua)

  1. WebSocket Connection Handling:
    • The Lua code runs on the ESP32 and checks if a WebSocket request is received (request:header"Sec-WebSocket-Key").
    • Once a connection is established, a WebSocket object (s) is created, allowing the server to stream messages to the browser.
  2. RSSI Monitoring:
    • The esp32.apinfo() function retrieves the current Wi-Fi signal strength (RSSI).
    • A timer periodically checks for changes in the RSSI value. If the RSSI changes, the updated value is sent to the browser via the WebSocket connection.
  3. Resource Management:
    • The code ensures only one active WebSocket connection at a time by blocking new requests if the tool is already in use.
    • When the WebSocket session ends (e.g., the browser disconnects), the timer stops, and the WebSocket connection is cleaned up.

Client-Side (HTML/JavaScript)

  1. Real-Time Data Streaming:
    • The embedded JavaScript opens a WebSocket connection to the ESP32's WebSocket endpoint (the same page).
    • It listens to incoming messages containing updated RSSI values.
  2. Dynamic User Interface:
    • As new RSSI values arrive, the JavaScript updates the browser page in real-time, displaying the current signal strength without requiring a page reload.
  3. Interactive Learning:
    • The JavaScript code also serves as an example for beginners, demonstrating how to use WebSocket to stream real-time data from a server to the browser.

Posted in Xedge32