outdoor-weather-station.ino 915 B

123456789101112131415161718192021222324252627282930313233
  1. //#define TEST_MODE
  2. #define LIGHT_PIN A3
  3. #define ERR reboot()
  4. #define SLEEP_TIME_S 30
  5. #define SLEEP_TIME_MS SLEEP_TIME_S * 1000
  6. #define SLEEP_TIME_US SLEEP_TIME_MS * 1000
  7. #define debug(X) Serial.print(X)
  8. #define debugln(...) Serial.println(__VA_ARGS__)
  9. #define debuglog(A, B) debug(A); debugln(B)
  10. char log_buff[200];
  11. #define dout(...) sprintf(log_buff, __VA_ARGS__); Serial.println(log_buff);
  12. #define RTDB_AUTH_TOKEN "abc123"
  13. #define RTDB_PROJECT "weather-station-xxxxx"
  14. #define RTDB_PATH "outdoor"
  15. #define RTDB_HOST RTDB_PROJECT "-default-rtdb.firebaseio.com"
  16. #define RTDB_URL "https://" RTDB_HOST "/" RTDB_PATH ".json?auth=" RTDB_AUTH_TOKEN
  17. // Reboot on error
  18. void reboot() {
  19. showError();
  20. const int64_t reboot_sleep_time = 5 * 1000 * 1000;
  21. debuglog("Rebooting by going to sleep for: ", reboot_sleep_time);
  22. esp_sleep_enable_timer_wakeup(reboot_sleep_time);
  23. Serial.flush();
  24. esp_deep_sleep_start();
  25. }