feat: deep sleep single-fetch with probabilistic weighting
Refactor timerWakeCycle() to fetch a single random photo per wake using cycle-mode-aware server-side filtering via Immich's POST /api/search/random endpoint. Changes: - Add fetchOneRandomAssetId() to ImmichClient with support for isFavorite, takenAfter, takenBefore filter parameters - Add timer_last_date NVS field for chronological cursor persistence - Implement probabilistic filter selection per cycle mode: - Random: unfiltered size=1 - Chronological/ReverseChronological: date cursor in NVS - FavoritesWeighted: 66% favorites, 33% unfiltered - WeightedChronological: 66% recent (30d), 33% unfiltered - WeightedReverseChronological: 66% older (30d), 33% unfiltered - Add retry loop with filter relaxation on empty results - Initialize hardware RTC (RX8130CE) firmware-wide: - Seed system clock from RTC at boot (immediate time) - NTP sync after WiFi connect, write back to RTC - Add time_utils.h with isoNow(), isoNowMinus30d(), hasValidTime() Normal mode (PhotoQueue + displayTask) is completely untouched. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "wifi_manager.h"
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <M5Unified.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "config.h"
|
||||
|
||||
void WiFiManager::begin(SettingsManager& settings) {
|
||||
@@ -57,6 +60,7 @@ void WiFiManager::startStation() {
|
||||
Serial.printf("[wifi] Connected! IP: %s, RSSI: %d\n",
|
||||
WiFi.localIP().toString().c_str(), WiFi.RSSI());
|
||||
WiFi.setSleep(WIFI_PS_MIN_MODEM);
|
||||
syncNTP();
|
||||
setupMDNS("papercolor");
|
||||
return;
|
||||
}
|
||||
@@ -88,3 +92,37 @@ bool WiFiManager::attemptConnection(const String& ssid, const String& pass) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WiFiManager::syncNTP() {
|
||||
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
|
||||
|
||||
// Wait up to 5 seconds for NTP sync
|
||||
unsigned long start = millis();
|
||||
time_t now = 0;
|
||||
while (now < 1600000000 && (millis() - start) < 5000) {
|
||||
delay(100);
|
||||
time(&now);
|
||||
}
|
||||
|
||||
if (now < 1600000000) {
|
||||
Serial.println("[wifi] NTP sync timed out");
|
||||
return;
|
||||
}
|
||||
|
||||
// Write synced time to hardware RTC
|
||||
struct tm t;
|
||||
gmtime_r(&now, &t);
|
||||
|
||||
m5::rtc_datetime_t dt;
|
||||
dt.date.year = t.tm_year + 1900;
|
||||
dt.date.month = t.tm_mon + 1;
|
||||
dt.date.date = t.tm_mday;
|
||||
dt.time.hours = t.tm_hour;
|
||||
dt.time.minutes = t.tm_min;
|
||||
dt.time.seconds = t.tm_sec;
|
||||
M5.Rtc.setDateTime(dt);
|
||||
|
||||
Serial.printf("[wifi] NTP synced: %04d-%02d-%02d %02d:%02d:%02d UTC, written to RTC\n",
|
||||
dt.date.year, dt.date.month, dt.date.date,
|
||||
dt.time.hours, dt.time.minutes, dt.time.seconds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user