| 51 | } |
| 52 | |
| 53 | void contentRunner() { |
| 54 | if (config.runStatus == RUNSTATUS_STOP) return; |
| 55 | |
| 56 | time_t now; |
| 57 | time(&now); |
| 58 | uint8_t wifimac[8]; |
| 59 | WiFi.macAddress(wifimac); |
| 60 | memset(&wifimac[6], 0, 2); |
| 61 | |
| 62 | for (tagRecord *taginfo : tagDB) { |
| 63 | |
| 64 | const bool isAp = memcmp(taginfo->mac, wifimac, 8) == 0; |
| 65 | if (taginfo->RSSI && |
| 66 | (now >= taginfo->nextupdate || needRedraw(taginfo->contentMode, taginfo->wakeupReason)) && |
| 67 | config.runStatus == RUNSTATUS_RUN && |
| 68 | (taginfo->expectedNextCheckin < now + 300 || isAp || (wsClientCount() && config.stopsleep == 1)) && |
| 69 | Storage.freeSpace() > 31000 && !util::isSleeping(config.sleepTime1, config.sleepTime2)) { |
| 70 | drawNew(taginfo->mac, taginfo); |
| 71 | taginfo->wakeupReason = 0; |
| 72 | } |
| 73 | |
| 74 | if (taginfo->expectedNextCheckin > now - 10 && taginfo->expectedNextCheckin < now + 30 && taginfo->pendingIdle == 0 && taginfo->pendingCount == 0 && !isAp) { |
| 75 | int32_t minutesUntilNextUpdate = (taginfo->nextupdate - now) / 60; |
| 76 | if (minutesUntilNextUpdate > config.maxsleep) { |
| 77 | minutesUntilNextUpdate = config.maxsleep; |
| 78 | } |
| 79 | if (util::isSleeping(config.sleepTime1, config.sleepTime2)) { |
| 80 | struct tm timeinfo; |
| 81 | getLocalTime(&timeinfo); |
| 82 | struct tm nextSleepTimeinfo = timeinfo; |
| 83 | nextSleepTimeinfo.tm_hour = config.sleepTime2; |
| 84 | nextSleepTimeinfo.tm_min = 0; |
| 85 | nextSleepTimeinfo.tm_sec = 0; |
| 86 | time_t nextWakeTime = mktime(&nextSleepTimeinfo); |
| 87 | if (nextWakeTime < now) nextWakeTime += 24 * 3600; |
| 88 | minutesUntilNextUpdate = (nextWakeTime - now) / 60 - 2; |
| 89 | } |
| 90 | if (minutesUntilNextUpdate > 1 && (wsClientCount() == 0 || config.stopsleep == 0)) { |
| 91 | taginfo->pendingIdle = minutesUntilNextUpdate * 60; |
| 92 | taginfo->expectedNextCheckin = now + taginfo->pendingIdle; |
| 93 | if (taginfo->isExternal == false) { |
| 94 | prepareIdleReq(taginfo->mac, minutesUntilNextUpdate); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | vTaskDelay(1 / portTICK_PERIOD_MS); // add a small delay to allow other threads to run |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void checkVars() { |
| 104 | JsonDocument cfgobj; |
no test coverage detected