khoih-prog / AsyncMQTT_Generic

Arduino Arduino Library for ESP8266, ESP32, Portenta_H7, STM32 and RP2040W asynchronous MQTT client implementation. This library, ported to support ESP32, WT32_ETH01 (ESP32 + LAN8720), ESP8266, Portenta_H7 (Ethernet or WiFi) and STM32 (LAN8742A or LAN8720 Ethernet), Teensy 4.1 using QNEthernet, RASPBERRY_PI_PICO_W with CYW43439 WiFi. Currently supporting TLS/SSL for ESP32 only
MIT License
65 stars 10 forks source link

Missing default case in switch causes #10

Closed jenschr closed 2 years ago

jenschr commented 2 years ago

Describe the bug

In the example file "FullyFeatured_ESP32.ino", the Switch case does not have a "default" to catch anything not handled.

Steps to Reproduce

Compile example "FullyFeatured_ESP32.ino" in Arduino IDE with board set to "Adafruit Feather ESP32-S2".

Expected behavior

Expected the file to compile without errors

Actual behavior

Error compiling....

Solution

Just add a default case for the WiFiEvent(WiFiEvent_t event) method outside the "if" so that both versions has a default so you don't hqve to handle all possible cases:

default: break;

Information

Arduino IDE version: 1.8.19 ESP32 Core Version 2.0.4 OS: OSX 11.6

Context: Trying to make the basic example compile

Additional context

Relevant error message:

/Users/jensa/Documents/Arduino/FullyFeatured_ESP32/FullyFeatured_ESP32.ino: In function 'void WiFiEvent(arduino_event_id_t)':
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_SCAN_DONE' not handled in switch [-Werror=switch]
   switch (event)
          ^
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_STA_STOP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_START' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STOP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STACONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STADISCONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_GOT_IP6' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_FTM_REPORT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_START' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_STOP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_CONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_DISCONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_GOT_IP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_GOT_IP6' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_SUCCESS' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_FAILED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_TIMEOUT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_PIN' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_PBC_OVERLAP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_SCAN_DONE' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_FOUND_CHANNEL' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_GOT_SSID_PSWD' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_SEND_ACK_DONE' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_INIT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_DEINIT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_START' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_END' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_CRED_RECV' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_CRED_FAIL' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_CRED_SUCCESS' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_MAX' not handled in switch [-Werror=switch]
cc1plus: some warnings being treated as errors
Multiple libraries were found for "WiFi.h"
 Used: /Users/jensa/Library/Arduino15/packages/esp32/hardware/esp32/2.0.4/libraries/WiFi
 Not used: /Applications/Arduino.app/Contents/Java/libraries/WiFi
Using library WiFi at version 2.0.0 in folder: /Users/jensa/Library/Arduino15/packages/esp32/hardware/esp32/2.0.4/libraries/WiFi 
Using library AsyncMQTT_Generic at version 1.6.1 in folder: /Users/jensa/Documents/Arduino/libraries/AsyncMQTT_Generic 
Using library AsyncTCP at version 1.1.1 in folder: /Users/jensa/Documents/Arduino/libraries/AsyncTCP 
exit status 1
enumeration value 'ARDUINO_EVENT_WIFI_SCAN_DONE' not handled in switch [-Werror=switch]
khoih-prog commented 2 years ago

HI @jenschr

Thanks for the bug report, which is caused by recently aggressive behaviour of the compiler settings.

While I'll fix the issue very soon, you can test normally by temporarily setting, if using Arduino IDE, Preferences->Compiler Warnings to Default, instead of All or More

jenschr commented 2 years ago

Yeah. I hacked around it, but wanted to be sure you knew about this issue. I'm looking through many MQTT libs for my students tonight and there sure is a lot of them that does not compile right now :)

khoih-prog commented 2 years ago

Hi @jenschr

The new AsyncMQTT_Generic releases v1.7.0 has just been published. Your contribution is noted in Contributions and Thanks

Best Regards,


Releases v1.7.0

  1. Fix ESP32 compile error. Check Missing default case in switch causes #10
  2. Change to new Forked ESPAsyncTCP library for ESP8266 boards, using WiFi or LwIP Ethernet, with ESP8266 core v3.0.2+ or WiFi with ESP8266 core v2.7.4 to avoid compile errors