Skip to content

ESP32 Wi-Fi: joining the strongest access point on a mesh ​

Measured on a real ESP32 on 24 Oct 2026. Three access points, all on channel 2.

The board joined the weakest node (-79 to -84 dBm) instead of the nearest (-16 dBm). MQTT over WSS then failed with -0x7280 (MBEDTLS_ERR_SSL_CONN_EOF). Connecting took about 130 seconds.

With a full-channel scan sorted by signal, it joined the node at -15 to -17 dBm. Wi-Fi was up in 6.4 seconds. MQTT was up in 12.0 seconds. A shared attribute was received and applied 12.5 seconds after a hardware reset.

SDK option ​

AutoconnectoSDK 1.7.76 joins the strongest access point by default.

  • config.wifiJoinStrongest = true scans every channel and sorts by signal. false keeps the first match.
  • config.wifiConnectTimeoutMs defaults to 15 seconds.
  • A failed MQTT connect switches between WSS and MQTTS, then retries with a bounded backoff.
  • Register sdk.onWifiJoin before begin. It receives BSSID, channel, and RSSI even when enableSerialLogs is false. sdk.lastWifiJoin reads the same result.
  • enableSerialLogs = false prints no SDK log lines. The sketch can still print the join callback.
  • On boot the device takes the retained shared-attribute push. It does not send a second request when that push has already arrived.

examples/MqttConnectFault_mqtt fails the first two MQTT connects in software so the transport switch and the backoff can be checked without waiting for a dead broker.

Examples in the SDK:

  • examples/WifiJoinStrongest_mqtt
  • examples/Attributes_RestoreOnBoot_mqtt — read shared attributes at boot, drive a GPIO, and report a client attribute.
  • examples/MqttConnectFault_mqtt

Next ​

support@autoconnecto.in · founder@autoconnecto.in · +91 92121 00555 · app.autoconnecto.in