Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
+1 for the answer and -1 for the Arduino IDE. Valid C++ should simply compile. I don't want to learn the quirks of another programming language if I can already program C++. I can't believe this hasn't been resolved in the last 4 years.
if (WiFi.status() == WL_CONNECTED){ return true; } else {return false; } is cargo cult programming. It can be simplified to return WiFi.status() == WL_CONNECTED. Similar for if (setupWifi() == true), which is equal to if (setupWifi())
Also, I don't get why esp_sleep_enable_timer_wakeup() is only activated if it was possible to connect to the Wifi. If it was not possible to connect to the Wifi, you still goto into deep sleep. But you don't want to wake up after 30 seconds then?
If setupWifi() == false, then dht.begin(); is never called but it still enters loop() and tries to read temperatures. Not sure if that's good or eventually runs into undefined behavior.