Updates to espMQTTclient and WiFi have broken code that used to work?

sensor_mqtt_v3_7.ino (12.8 KB)

Earlier this year, I created a simple ToF sensor using a XIAO_ESP32C3 using typical libraries. Health took me offline for a while, so now I'm getting back to my project. Which, after updating my libraries to current without imagining the consequences will no longer compile. Sigh.

I BELIEVE the issue is related to espMQTTClient now supporting direct WiFi configuration, but perhaps does NOT support some of the old WiFi methods, but I'm stumped on how to proceed.

The compiler complains about things like "WiFi not declared in this scope":

/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp: In member function 'bool EspMQTTClient::handleWiFi()':
/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp:187:5: error: 'WiFi' was not declared in this scope
  187 |     WiFi.disconnect(true);
      |     ^~~~
/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp:194:27: error: 'WiFi' was not declared in this scope
  194 |   bool isWifiConnected = (WiFi.status() == WL_CONNECTED);
      |                           ^~~~
/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp:194:44: error: 'WL_CONNECTED' was not declared in this scope; did you mean 'MQTT_CONNECTED'?
  194 |   bool isWifiConnected = (WiFi.status() == WL_CONNECTED);
      |                                            ^~~~~~~~~~~~
      |                                            MQTT_CONNECTED
/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp:215:27: error: 'WL_CONNECT_FAILED' was not declared in this scope; did you mean 'MQTT_CONNECT_FAILED'?
  215 |       if(WiFi.status() == WL_CONNECT_FAILED || millis() - _lastWifiConnectiomAttemptMillis >= _wifiReconnectionAttemptDelay)
      |                           ^~~~~~~~~~~~~~~~~
      |                           MQTT_CONNECT_FAILED
/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp: In member function 'bool EspMQTTClient::handleMQTT()':
/Users/etimberl/Documents/Hobbies/Micro Controllers/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp:325:9: error: 'WiFi' was not declared in this scope
  325 |         WiFi.disconnect(true);

I'm not clear what I need to do to get back to working code here? It all seems to be about initializing, then checking the WiFi connection, but my addled brain can't seem to make sense of it..

Thoughts or suggestions? I'm planning on migrating to WIFImanager, and it would seem when I mix in espMQTTCLient without understanding the current situation, I might just end up right back here again?

It's not necessarily the libraries. In your case it's the Espressif's (brain dead?) decision to overhaul their board package. You previous board package was probably 2.x and you did update to 3.x. Your code compiles with the former but not with the latter.

So you either start from scratch looking at the examples that are included in the new board package or you roll back to the 2.x version.

Note that you can not stick to the 2.x version for the rest of your life but for the project you can; you might need the newer version in future for another board.

I just ran into this issue as well today and this post had a one-line fix that solved it for me.

1 Like

Thank you, David - that, indeed, fixed my problem and saved me innumerable hours of wasted time.

Seriously appreciate your taking time to respond to my plea!

-ET-

@sterretje You made my day :pray: