MQTT + Wi-Fi unreliability issue in ESP32-C3

arTI23
Posts: 2
Joined: Sun Jan 11, 2026 11:01 am

MQTT + Wi-Fi unreliability issue in ESP32-C3

Postby arTI23 » Sun Jan 11, 2026 3:39 pm

I’m facing intermittent Wi-Fi/MQTT connection issues with an ESP32-C3-DevKitC-02 and would appreciate some guidance.

Setup
Sender: ESP32-Dev Module (sending sensor data from DHT22 and BMI160 in 1 second intervals) - No issues in this board for the problem said below.
Communication tested: MQTT (Wi-Fi)
Framework: Arduino (PlatformIO)
Arduino ESP32 Core v2.0.17

Receiver: ESP32-C3 driving a 7-segment display
[env:esp32-c3-devkitc-02]
platform = espressif32
board = esp32-c3-devkitc-02
framework = arduino
monitor_speed = 115200
build_flags =
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
lib_deps =
knolleary/PubSubClient@^2.8
(and the Wifi.h which is built-in for Wi-Fi)

I used a local Mosquitto broker on Windows (port 1883). I checked in Wireshark and it shows MQTT packets with correct payload. But sometimes the ESP32-C3 does not receive messages from the broker (Wireshark says Sending error). I had to restart the ESP32-C3 multiple times and suddenly it worked. I did not change any code of the program during that period, and the code uploaded includes the MQTT reconnect logic in loop(). When I cut off power for esp32c3 and tested again, it failed to connect and after repeating connected again. This was the same in another local mosquitto broker as well.

Before connecting to MQTT, when I tried connecting ESP32-C3 with my hotspot on its own through Wi-Fi, it connected immediately. When I had it connected to the circuit on the breadboard (common cathode 7-segment display is connected directly through GPIO pins - 0,1,3,4,6,7,8), it did not work immediately. I then slightly pulled it out, made it to connect and put it back down in circuit, and all worked perfectly. In both situations, the Wi-Fi module is positioned outward and very near the router (RSSI is also good). I had the same thing tested on another ESP32-C3 and same issue occurred.

Why is the connection intermittently instable? Is there any solution to make it connect without me trying to repeatedly restart both ESP32 and ESP32-C3?

lbernstone
Posts: 1132
Joined: Mon Jul 22, 2019 3:20 pm

Re: MQTT + Wi-Fi unreliability issue in ESP32-C3

Postby lbernstone » Mon Jan 12, 2026 4:19 am

Have you turned logging to verbose and watched the transaction? It sounds like you are losing your connection. The log should give some indication why. It's always a good idea to check for a connection before trying MQTT, even if you have reconnect set up.

Who is online

Users browsing this forum: ChatGPT-User and 1 guest