Fix bot mode hang on WiFi connection (closes #5)#9
Open
semichcsc-byte wants to merge 1 commit into
Open
Conversation
…es#5) WiFiManager creates an Access Point during setup() so users can pick a game mode from a phone. When the user later selects the bot mode, ChessBot::connectToWiFi() calls WiFi.begin(SSID, PASS) directly without ever shutting the AP down. WiFiNINA (firmware 1.x and 3.x on the Arduino Nano RP2040 Connect, Nano 33 IoT and MKR WiFi 1010) cannot run AP and STA modes simultaneously. The result is that WiFi.begin() silently never returns WL_CONNECTED, so the bot mode hangs after 'Connecting to WiFi...' with no further serial output and the board flashes red 5x as if the password were wrong. Fix: explicitly call WiFi.disconnect() + WiFi.end() and wait 2s before WiFi.begin(), forcing a clean AP -> STA transition. Verified on an Arduino Nano RP2040 Connect with WiFiNINA firmware 3.0.1: the bot now connects on attempt 1, the Stockfish API responds, and the game proceeds normally.
This was referenced May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the user selects the Chess Bot (Human vs AI) mode, the board hangs after
Connecting to WiFi...with no further serial output. After ~50s the failure animation runs (board flashes red 5x) as if the WiFi credentials were wrong, but they are correct — same SSID/password works for any other client.This matches the symptoms reported in #5 exactly:
Root cause
WiFiManager::begin()runs insetup()and puts the WiFiNINA module into AP mode (OpenChessBoard/chess123) so the user can pick a game mode from a browser. When the user later picks the bot mode on the physical board,ChessBot::connectToWiFi()immediately callsWiFi.begin(SECRET_SSID, SECRET_PASS)to switch to STA mode.WiFiNINA on the Arduino Nano RP2040 Connect (and the Nano 33 IoT / MKR WiFi 1010) cannot run AP and STA simultaneously. With the AP still listening,
WiFi.begin()silently never reachesWL_CONNECTED, the 10×5s retry loop times out, and the bot mode dies.Fix
Explicitly tear the AP down before opening the STA connection:
Then proceed with
WiFi.begin()as before.WiFi.end()releases the radio cleanly anddelay(2000)lets the WiFiNINA firmware finish reinitialising before the next mode change.Verification
Tested on Arduino Nano RP2040 Connect with WiFiNINA firmware 3.0.1 and the official
OpenChess.ino(with#define ENABLE_WIFI):Bot connects on the first attempt, Stockfish API responds, gameplay proceeds normally.
Trade-offs
chess_bot.cpp)OpenChessBoardAP is no longer reachable once bot mode starts. This is unavoidable on WiFiNINA hardware and matches user expectation: once a mode is picked, the AP is no longer needed.