//#define TEST_MODE #define USE_SERIAL #define LIGHT_PIN A3 #define ERR reboot() #ifndef TEST_MODE #define SLEEP_TIME_MIN 5 #define SLEEP_TIME_SEC 60 * SLEEP_TIME_MIN #define SLEEP_TIME_MS 1000 * SLEEP_TIME_SEC #else #define SLEEP_TIME_MS 10 * 1000 // 10 second sleep in test mode #endif #define WIFI_TIMEOUT_SECONDS 30 // How long to wait before giving up on wifi connection #ifdef USE_SERIAL char log_buff[200]; #define debug(...) if(Serial) { sprintf(log_buff, __VA_ARGS__); Serial.println(log_buff); Serial.flush(); } #define debugln(X, Y) if(Serial) { Serial.print(X); Serial.println(Y); } // For things that can't be represented as a normal % formatter #define debugNoLn(...) if(Serial) { sprintf(log_buff, __VA_ARGS__); Serial.print(log_buff); } #else #define debug(...) #define debugln(X, Y) #define debugNoLn(...) #endif #define RTDB_AUTH_TOKEN "abc123" #define RTDB_PROJECT "weather-project" #define RTDB_PATH "outdoor" const String RTDB_HOST = String(RTDB_PROJECT) + "-default-rtdb.firebaseio.com"; const String RTDB_URL = String("https://") + RTDB_HOST + "/" + RTDB_PATH + ".json?auth=" + RTDB_AUTH_TOKEN; // Used in various places to get the sleep time to be as close to SLEEP_TIME_MIN as possible. int64_t wakeTime; // Defined later, but declare it now. void showError(); // Turn LEDs on to red, then go into deep sleep, restarting after 5 seconds. // Effectively doing a reboot, while visually displaying an error state. void reboot() { showError(); const int64_t reboot_sleep_time = 5 * 1000 * 1000; debug("Rebooting by going to sleep for: %d", reboot_sleep_time); esp_sleep_enable_timer_wakeup(reboot_sleep_time); Serial.flush(); esp_deep_sleep_start(); }