Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/companion_radio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ void setup() {

#ifdef WIFI_SSID
board.setInhibitSleep(true); // prevent sleep when WiFi is active
// Enable ESP-IDF auto-reconnect
WiFi.setAutoReconnect(true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed since auto reconnect defaults to true in the underlying library, however we might as well be explicit about it. So it can stay.

// Attach an event handler to force a reconnect specifically on disconnect events
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info){
#ifdef WIFI_DEBUG_LOGGING
Serial.println("WiFi disconnected. Forcing reconnect...");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the #ifdef sections and replace Serial.println(...) with WIFI_DEBUG_PRINTLN(...). The latter automatically handles the case where wifi debug logging is disabled.

#endif
WiFi.reconnect();
}, ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.begin(WIFI_SSID, WIFI_PWD);
serial_interface.begin(TCP_PORT);
#elif defined(BLE_PIN_CODE)
Expand Down