main: Deep sleep for up to an hour
It really isn't necessary to have minute-level granularity of soil moisture (especially since it's just been sitting at "max" for 2 weeks!). Updating frequently is helpful for diagnostics, though. To compromise, the sensor will now publish data every minute for the first few minutes after it starts up, then reduce its update frequency to once every hour.master
parent
e628508ff5
commit
6c1757b43d
|
@ -9,4 +9,5 @@
|
|||
#define TOPIC_ERRORS "garden/errors"
|
||||
#define TOPIC_STATE "garden/state"
|
||||
|
||||
#define SLEEP_MILLIS (1000 * 60)
|
||||
#define SLEEP_MILLIS_EARLY (1000 * 60)
|
||||
#define SLEEP_MILLIS (1000 * 60 * 60)
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
INCTXT(RootCA, "isrgrootx1.pem");
|
||||
|
||||
RTC_DATA_ATTR uint32_t boot_count = 0;
|
||||
|
||||
WiFiClientSecure sock;
|
||||
PubSubClient mqtt(sock);
|
||||
|
||||
|
@ -18,12 +20,17 @@ Values values;
|
|||
Adafruit_seesaw ss;
|
||||
|
||||
void setup() {
|
||||
delay(1000); // VSCode is slow to open the serial console after upload
|
||||
|
||||
Serial.begin(115200);
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, 1);
|
||||
|
||||
// VSCode is slow to open the serial console after upload
|
||||
if (boot_count == 0) {
|
||||
delay(1000);
|
||||
}
|
||||
boot_count++;
|
||||
Serial.printf("This is boot number %d\n", boot_count);
|
||||
|
||||
if (!wifi_connect()) {
|
||||
Serial.printf("Failed to connect to WiFi, status %s\n", WiFi.status());
|
||||
reboot();
|
||||
|
@ -65,9 +72,11 @@ void setup() {
|
|||
mqtt.disconnect();
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Entering deep sleep ...");
|
||||
unsigned long timer =
|
||||
((boot_count <= 5 ? SLEEP_MILLIS_EARLY : SLEEP_MILLIS) - millis());
|
||||
Serial.printf("Entering deep sleep for %d milliseconds...\n", timer);
|
||||
Serial.flush();
|
||||
esp_sleep_enable_timer_wakeup((SLEEP_MILLIS - millis()) * 1000);
|
||||
esp_sleep_enable_timer_wakeup(timer * 1000);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue