ESP32 WiFi Timeout Issues With FluidNC V4.0.0-pre2 & WEBUI3

by Alex Johnson 60 views

Are you encountering frustrating timeout errors and disconnections when using FluidNC v4.0.0-pre2 with your ESP32 in Access Point (AP) WiFi mode and the WEBUI3 interface? You're not alone! This comprehensive guide dives into a specific issue reported by a user, analyzing the problem, configuration, and potential solutions. We'll break down the user's experience, configuration details, and the error messages they encountered to understand the root cause and how to address it.

Understanding the Problem: WiFi Timeouts in FluidNC WEBUI3

The core issue revolves around frequent timeouts and disconnections experienced when using FluidNC v4.0.0-pre2 on an ESP32 in Access Point (AP) mode, specifically with the WEBUI3 interface. The user reported that while using an Android tablet with Chrome, they encountered a "Token error" upon each WEBUI3 start. Furthermore, attempting a simple X-axis movement of 100mm triggered numerous timeout errors, connection errors, and ultimately, disconnections from the web interface. This significantly hinders the usability of the CNC controller, making it crucial to diagnose and resolve the problem. Let's delve deeper into the specifics of the user's setup and the error messages encountered to gain a clearer understanding of the situation. The user also explicitly asked if this behavior was expected, particularly since using AP mode is generally not recommended. Understanding why AP mode might contribute to these issues is a key part of the solution.

Decoding the Configuration: A Detailed Look

The user provided a detailed configuration file (Cnc3040YXZ.yaml), which is crucial for understanding the setup and identifying potential misconfigurations. Let's examine some key sections:

1. Board and Stepping Configuration

The configuration specifies a "MakerFr V3" board and utilizes the I2S_STREAM stepping engine. This is a common setup for many CNC applications, but it's important to ensure that the I2S configuration (bck_pin, data_pin, ws_pin) aligns with the physical wiring of the ESP32. The stepping parameters (pulse_us, dir_delay_us, disable_delay_us, idle_ms) should also be appropriately tuned for the stepper motors being used. Incorrect stepping configurations can lead to erratic motor behavior, but are less likely to be the primary cause of WiFi timeouts. However, it's a good practice to verify these settings.

2. SPI and SD Card Configuration

SPI is used for communication with the SD card. The configuration includes pin assignments (miso_pin, mosi_pin, sck_pin, cs_pin) and a frequency setting (frequency_hz). While SD card operations are generally independent of WiFi, a faulty SD card or SPI configuration could potentially introduce system instability, indirectly affecting WiFi performance. It's worth ensuring the SD card is functioning correctly and the SPI settings are appropriate.

3. UART Configuration

UART1 is configured for serial communication with a baud rate of 115200. This is typically used for communication with a host computer or other serial devices. While UART communication itself is unlikely to cause WiFi timeouts, excessive serial traffic or a misconfigured UART could potentially contribute to system load, which might indirectly impact WiFi performance. It's important to ensure that the UART configuration is correct and that the serial communication is not overwhelming the ESP32's resources.

4. Kinematics and Axis Configuration

The configuration defines a Cartesian kinematic system with three axes (X, Y, Z). Each axis has its own set of parameters, including steps_per_mm, max_rate_mm_per_min, acceleration_mm_per_sec2, and max_travel_mm. While kinematic settings primarily affect motion control, incorrect values can lead to unexpected behavior or even trigger safety limits, but are unlikely to directly cause WiFi timeouts. However, ensuring these settings are accurate is crucial for proper CNC operation.

5. Homing Configuration

Each axis has a homing configuration, specifying the homing cycle, direction, position, speeds, and limit switch settings. Incorrect homing configurations can lead to homing failures or unexpected movements, but are unlikely to be the direct cause of WiFi timeouts. However, verifying the homing settings is essential for reliable CNC operation.

6. Control and Safety Features

The configuration includes settings for safety door pin, reset pin, feed hold pin, cycle start pin, and estop pin. These pins are crucial for ensuring safe operation of the CNC machine. While these safety features are essential, they are unlikely to be the primary cause of WiFi timeouts. However, it's crucial to ensure these pins are correctly configured and functioning as expected.

7. Spindle and Laser Configuration

The configuration includes settings for a 10V spindle and a laser, defining PWM frequencies, output pins, and speed maps. Incorrect spindle or laser configurations can lead to unexpected behavior or damage, but are unlikely to directly cause WiFi timeouts. However, verifying these settings is crucial for safe and effective spindle and laser operation.

8. Probe Configuration

The configuration includes settings for a probe, specifying the pin, toolsetter pin, and check mode. The probe is used for automated tool setting and probing operations. While probe functionality is important, it's unlikely to be the direct cause of WiFi timeouts. However, verifying the probe configuration is essential for reliable probing operations.

9. Macros and Startup Settings

The configuration includes macros for various functions and startup settings, such as must_home, deactivate_parking, and check_limits. Macros can automate complex tasks, and startup settings define the initial state of the CNC controller. While macros and startup settings are powerful features, they are unlikely to be the primary cause of WiFi timeouts. However, reviewing these settings is important for overall system behavior.

10. WiFi Configuration (Implicit)

While the provided configuration file doesn't explicitly show WiFi settings, the startup messages indicate that FluidNC is configured to operate in Access Point (AP) mode with the SSID "FluidNC" and IP address 192.168.0.1. This is a critical piece of information, as AP mode can be more susceptible to WiFi issues compared to Station mode (connecting to an existing WiFi network). The key difference is that in AP mode, the ESP32 acts as the WiFi router, handling connections for other devices. This puts more load on the ESP32's WiFi capabilities and can lead to performance issues, especially with multiple connected devices or interference.

Analyzing the Startup Messages: Clues to the Problem

The user also provided valuable startup messages from FluidNC, which offer further clues. Let's dissect the key information:

  • FluidNC Version: FluidNC v4.0.0-pre2 - This confirms the firmware version being used.
  • Configuration File: Configuration file: Cnc3040YXZ.yaml - This indicates the configuration file being loaded.
  • Machine and Board Information: Machine 3040 YXZ AMB-FME-DI, Board MakerFr V3 - These lines confirm the machine and board being used.
  • Pin Assignments: The messages detail the pin assignments for various peripherals like UART, I2S, SPI, and stepper motors. This is useful for verifying the hardware connections.
  • Stepping Engine: Stepping: I2S_STREAM - This confirms the stepping engine being used.
  • Axis Information: The messages provide information about each axis, including travel limits and motor configurations. This is helpful for verifying axis setup.
  • WiFi Information: AP SSID FluidNC IP 192.168.0.1 mask 255.255.255.0 channel 1, AP started, WiFi on, Captive Portal Started, HTTP started on port 80, Telnet started on port 23 - These lines are crucial. They confirm that the ESP32 is operating in Access Point (AP) mode, which, as mentioned earlier, can be a source of WiFi instability. The captive portal and HTTP server are also running, which are necessary for the WEBUI3 interface.
  • Warning Messages: [MSG:WARN: Motor0 switches do not support negative homing dir] - This warning indicates a potential issue with the homing configuration for the Z-axis, but it's unlikely to be the primary cause of WiFi timeouts.
  • Input Pin Warning: [MSG:WARN: Input pin(s) active on startup:PH], [MSG:INFO: ALARM: Input Pin Initially On], ALARM:11 - This is a significant warning! It indicates that an input pin (likely the probe or a limit switch) is active on startup, triggering an alarm. This could be a wiring issue, a faulty sensor, or a misconfiguration. While not directly causing WiFi timeouts, an active alarm state can impact the overall system performance and potentially contribute to instability. This needs to be investigated and resolved.

Deciphering the Error Messages: Token Error and Timeouts

The user reported two primary error messages:

  1. "Token error" at each WEBUI3 start: This error typically indicates an issue with the authentication token used by WEBUI3 to maintain a secure connection. It could be caused by a problem with token generation, storage, or validation. This error suggests a potential issue within the WEBUI3 interface itself or the communication between WEBUI3 and the FluidNC firmware.
  2. "Timeout error" and "Connection error" during X-axis movement: These errors strongly suggest a problem with the WiFi connection between the Android tablet and the ESP32. Timeouts occur when the connection is lost or unresponsive for a certain period, while connection errors indicate a failure to establish or maintain a connection. These errors, combined with the "Token error," point towards a fundamental issue with the WiFi communication in AP mode.

Pinpointing the Root Cause and Potential Solutions

Based on the analysis of the configuration, startup messages, and error messages, here's a breakdown of the likely root causes and potential solutions:

1. Access Point (AP) Mode Limitations

  • Root Cause: Operating in AP mode puts a significant load on the ESP32's WiFi capabilities, as it acts as both a CNC controller and a WiFi access point. This can lead to performance issues, especially with multiple connected devices or interference.
  • Solution: The most recommended solution is to switch to Station mode, connecting the ESP32 to an existing WiFi network. This offloads the WiFi routing responsibilities to a dedicated router, improving stability and performance. If switching to Station mode is not feasible, try minimizing the number of devices connected to the ESP32's AP and ensuring there is minimal WiFi interference in the environment.

2. Input Pin Alarm

  • Root Cause: The [MSG:WARN: Input pin(s) active on startup:PH] and ALARM:11 messages indicate that an input pin is active on startup, triggering an alarm. This could be due to a wiring issue, a faulty sensor, or a misconfiguration in the Cnc3040YXZ.yaml file.
  • Solution: Investigate the input pin(s) that are triggering the alarm. Check the wiring, sensor functionality, and the corresponding configuration in the Cnc3040YXZ.yaml file. Ensure the pin is correctly configured as either normally open or normally closed, depending on the sensor type and wiring. Resolve this alarm as it can impact overall system behavior.

3. WEBUI3 Token Error

  • Root Cause: The "Token error" suggests a potential issue with the authentication mechanism within WEBUI3 or the communication between WEBUI3 and FluidNC. This could be related to token generation, storage, or validation.
  • Solution: Try clearing the browser cache and cookies on the Android tablet. This can often resolve issues related to stored tokens. If the problem persists, try using a different browser or device to access WEBUI3. It's also worth checking the FluidNC and WEBUI3 documentation for any known issues related to token handling. Updating FluidNC and WEBUI3 to the latest versions might also resolve this issue.

4. WiFi Interference and Signal Strength

  • Root Cause: WiFi interference from other devices or a weak signal between the ESP32 and the Android tablet can lead to timeouts and disconnections.
  • Solution: Ensure there is a strong WiFi signal between the ESP32 and the Android tablet. Minimize potential sources of WiFi interference, such as other wireless devices, microwave ovens, and metal objects. If possible, move the ESP32 and the Android tablet closer together. Consider using a WiFi analyzer app to identify channels with less interference.

5. ESP32 Resource Constraints

  • Root Cause: The ESP32 has limited resources (CPU, memory, WiFi bandwidth). Running FluidNC, WEBUI3, and operating in AP mode simultaneously can strain these resources, leading to performance issues.
  • Solution: Optimize the FluidNC configuration to reduce resource usage. Avoid unnecessary features or complex calculations. Close any other applications running on the Android tablet that might be consuming resources. Switching to Station mode (as mentioned earlier) will also reduce the load on the ESP32's WiFi capabilities.

Troubleshooting Steps: A Systematic Approach

To effectively resolve these issues, follow these troubleshooting steps:

  1. Switch to Station Mode: As mentioned earlier, this is the most recommended solution for WiFi stability. Configure FluidNC to connect to an existing WiFi network.
  2. Address the Input Pin Alarm: Investigate and resolve the alarm triggered by the active input pin on startup. This is crucial for overall system stability.
  3. Clear Browser Cache and Cookies: Clear the browser cache and cookies on the Android tablet to address potential token-related issues with WEBUI3.
  4. Check WiFi Signal Strength and Interference: Ensure a strong WiFi signal between the ESP32 and the Android tablet and minimize potential sources of interference.
  5. Simplify the Configuration: Try simplifying the Cnc3040YXZ.yaml file by temporarily disabling non-essential features to reduce resource usage.
  6. Update FluidNC and WEBUI3: Ensure you are running the latest versions of FluidNC and WEBUI3 to benefit from bug fixes and performance improvements.
  7. Test with a Different Device: Try accessing WEBUI3 from a different computer or mobile device to rule out device-specific issues.
  8. Monitor System Resources: If possible, monitor the ESP32's CPU and memory usage to identify potential resource bottlenecks.

Conclusion: Resolving WiFi Timeouts for Smooth CNC Operation

Experiencing WiFi timeouts with FluidNC and WEBUI3 can be frustrating, but by systematically analyzing the configuration, startup messages, and error messages, you can identify the root causes and implement effective solutions. Switching to Station mode, addressing input pin alarms, and optimizing WiFi connectivity are key steps towards achieving a stable and reliable CNC control system. By following the troubleshooting steps outlined in this guide, you can overcome these challenges and enjoy smooth CNC operation with your ESP32-based controller. Remember to consult the official FluidNC documentation and community forums for additional support and guidance.

For further information on networking and troubleshooting embedded systems, you can visit this trusted resource. (Please replace with an actual relevant link.)