logging reboots

This commit is contained in:
Nic Limper
2023-06-11 13:29:49 +02:00
parent 5c7b53b740
commit 205dfa0ce2
10 changed files with 163 additions and 36 deletions

View File

@@ -157,6 +157,7 @@ Latency will be around 40 seconds.">
<div class="actionbox">
<div>
<div>Currently active tags:</div>
<div><span id="runstate"></div>
<div><span id="apstatecolor">&#11044;</span> <span id="apstate">loading</span></div>
<div><span id="apconfigbutton">AP config</span></div>
<div><a href="/edit" target="littlefs" class="filebutton">edit littleFS</a></div>
@@ -180,7 +181,7 @@ Latency will be around 40 seconds.">
<div class="nextupdate"></div>
<div class="corner">
<div class="pendingicon" title="A new message is waiting for the tag to pick up">&circlearrowright;</div>
<div class="warningicon" title="This tag has nog been seen for a long time">&#9888;</div>
<div class="warningicon" title="This tag has not been seen for a long time">&#9888;</div>
</div>
</div>
</div>

View File

@@ -270,7 +270,7 @@ select {
}
.tagpending {
animation: pending 1s ease infinite;
animation: pending 1.5s ease infinite;
}
.currimg {
@@ -539,9 +539,9 @@ ul.messages li.new {
}
@keyframes pending {
0% { background-color: #d0d0e0;}
50% { background-color: #b0b0e0;}
100% { background-color: #d0d0e0;}
0% { }
50% { background-color: #d4d4f5;}
100% { }
}
@media screen and (max-width: 480px) {
@@ -587,5 +587,10 @@ ul.messages li.new {
.actionbox>div {
gap: 5px;
flex-flow: wrap;
}
.actionbox>div:first-child>div:first-child {
flex-basis: 100%;
}
}

View File

@@ -25,6 +25,12 @@ const apstate = [
{ state: "failed", color: "red" },
{ state: "coming online", color: "yellow" }
];
const runstate = [
{ state: "⏹︎ stopped" },
{ state: "⏸pause" },
{ state: "" }, // hide running
{ state: "⏳︎ init" }
];
const imageQueue = [];
let isProcessing = false;
@@ -92,6 +98,7 @@ function connect() {
if (msg.sys.apstate) {
$("#apstatecolor").style.color = apstate[msg.sys.apstate].color;
$("#apstate").innerHTML = apstate[msg.sys.apstate].state;
$("#runstate").innerHTML = runstate[msg.sys.runstate].state;
}
servertimediff = (Date.now() / 1000) - msg.sys.currtime;
}
@@ -209,6 +216,7 @@ function processTags(tagArray) {
break;
case WAKEUP_REASON_GPIO:
$('#tag' + tagmac + ' .nextcheckin').innerHTML = "GPIO wakeup"
$('#tag' + tagmac).style.background = "#c8f1bb";
break;
case WAKEUP_REASON_NFC:
$('#tag' + tagmac + ' .nextcheckin').innerHTML = "NFC wakeup"

View File

@@ -0,0 +1,14 @@
#include <Arduino.h>
#define WAKEUP_REASON_TIMED 0
#define WAKEUP_REASON_BOOT 1
#define WAKEUP_REASON_GPIO 2
#define WAKEUP_REASON_NFC 3
#define WAKEUP_REASON_FIRSTBOOT 0xFC
#define WAKEUP_REASON_NETWORK_SCAN 0xFD
#define WAKEUP_REASON_WDT_RESET 0xFE
void init_time();
void logLine(char* buffer);
void logLine(String text);
void logStartUp();

View File

@@ -14,6 +14,7 @@
#define RUNSTATUS_STOP 0
#define RUNSTATUS_PAUSE 1
#define RUNSTATUS_RUN 2
#define RUNSTATUS_INIT 3
class tagRecord {
public:
@@ -62,7 +63,7 @@ struct Config {
uint8_t runStatus;
};
extern SemaphoreHandle_t tagDBOwner;
// extern SemaphoreHandle_t tagDBOwner;
extern Config config;
extern std::vector<tagRecord*> tagDB;
extern DynamicJsonDocument APconfig;

View File

@@ -184,14 +184,14 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
// https://github.com/erikflowers/weather-icons
drawWeather(filename, cfgobj, taginfo, imageParams);
taginfo->nextupdate = now + 3600;
taginfo->nextupdate = now + 1800;
updateTagImage(filename, mac, 15, taginfo, imageParams);
break;
case Forecast:
drawForecast(filename, cfgobj, taginfo, imageParams);
taginfo->nextupdate = now + 3 * 3600;
taginfo->nextupdate = now + 3600;
updateTagImage(filename, mac, 15, taginfo, imageParams);
break;

View File

@@ -8,6 +8,7 @@
#include "makeimage.h"
#include "serialap.h"
#include "settings.h"
#include "system.h"
#include "tag_db.h"
#ifdef HAS_USB
@@ -26,31 +27,20 @@ void delayedStart(void* parameter) {
Serial.println("Resuming content generation");
wsLog("resuming content generation");
config.runStatus = RUNSTATUS_RUN;
vTaskDelay(10 / portTICK_PERIOD_MS);
vTaskDelete(NULL);
}
void timeTask(void* parameter) {
config.runStatus = RUNSTATUS_RUN;
esp_reset_reason_t resetReason = esp_reset_reason();
if (resetReason == ESP_RST_PANIC) {
Serial.println("Panic! Pausing content generation for 60 seconds");
config.runStatus = RUNSTATUS_PAUSE;
xTaskCreate(delayedStart, "delaystart", 2000, NULL, 2, NULL);
}
wsSendSysteminfo();
while (1) {
time_t now;
time(&now);
tm tm;
if (!getLocalTime(&tm)) {
Serial.println("Waiting for valid time from NTP-server");
} else {
if (now % 5 == 0 || apInfo.state != AP_STATE_ONLINE) {
wsSendSysteminfo();
}
if (now % 300 == 6 && config.runStatus != RUNSTATUS_STOP) saveDB("/current/tagDB.json");
if (apInfo.state == AP_STATE_ONLINE) contentRunner();
}
if (now % 5 == 0 || apInfo.state != AP_STATE_ONLINE || config.runStatus != RUNSTATUS_RUN) wsSendSysteminfo();
if (now % 300 == 6 && config.runStatus != RUNSTATUS_STOP) saveDB("/current/tagDB.json");
if (apInfo.state == AP_STATE_ONLINE) contentRunner();
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
@@ -80,8 +70,7 @@ void setup() {
Serial.begin(115200);
Serial.print(">\n");
pinTest();
pinTest();
#ifdef BOARD_HAS_PSRAM
if (!psramInit()) {
Serial.printf("This build of the AP expects PSRAM, but we couldn't find/init any. Something is terribly wrong here! System halted.");
@@ -140,20 +129,36 @@ void setup() {
rgbIdle();
#endif
loadDB("/current/tagDB.json");
tagDBOwner = xSemaphoreCreateMutex();
// tagDBOwner = xSemaphoreCreateMutex();
xTaskCreate(APTask, "AP Process", 6000, NULL, 2, NULL);
xTaskCreate(webSocketSendProcess, "ws", 2000, NULL, configMAX_PRIORITIES - 10, NULL);
vTaskDelay(10 / portTICK_PERIOD_MS);
config.runStatus = RUNSTATUS_INIT;
xTaskCreate(timeTask, "timed tasks", 12000, NULL, 2, NULL);
init_time();
logStartUp();
esp_reset_reason_t resetReason = esp_reset_reason();
if (resetReason == ESP_RST_PANIC) {
Serial.println("Panic! Pausing content generation for 30 seconds");
config.runStatus = RUNSTATUS_PAUSE;
xTaskCreate(delayedStart, "delaystart", 2000, NULL, 2, NULL);
} else {
config.runStatus = RUNSTATUS_RUN;
}
}
void loop() {
vTaskDelay(10000 / portTICK_PERIOD_MS);
// performDeviceFlash();
while (1) {
// pinTest();
// pinTest();
while (1) {
vTaskDelay(10000 / portTICK_PERIOD_MS);
//pinTest();
// pinTest();
}
#ifdef OPENEPAPERLINK_PCB
if (extTagConnected()) {

View File

@@ -12,6 +12,7 @@
#include "commstructs.h"
#include "serialap.h"
#include "settings.h"
#include "system.h"
#include "tag_db.h"
#include "udp.h"
#include "web.h"
@@ -468,6 +469,23 @@ void processDataReq(struct espAvailDataReq* eadr, bool local) {
taginfo->lastseen = now;
if (eadr->adr.lastPacketRSSI != 0) {
if (eadr->adr.wakeupReason >= 0xF0) {
if (!taginfo->pending) taginfo->nextupdate = 0;
memset(taginfo->md5, 0, 16 * sizeof(uint8_t));
memset(taginfo->md5pending, 0, 16 * sizeof(uint8_t));
const char* reason = "";
if (eadr->adr.wakeupReason == WAKEUP_REASON_FIRSTBOOT) reason = "Booting";
else if (eadr->adr.wakeupReason == WAKEUP_REASON_NETWORK_SCAN) reason = "Network scan";
else if (eadr->adr.wakeupReason == WAKEUP_REASON_WDT_RESET) reason = "Watchdog reset";
sprintf(buffer, "%02X%02X%02X%02X%02X%02X%02X%02X %s", eadr->src[7], eadr->src[6], eadr->src[5], eadr->src[4], eadr->src[3], eadr->src[2], eadr->src[1], eadr->src[0], reason);
logLine(buffer);
}
if (taginfo->batteryMv != eadr->adr.batteryMv) {
sprintf(buffer, "%02X%02X%02X%02X%02X%02X%02X%02X battery went from %.2fV to %.2fV", eadr->src[7], eadr->src[6], eadr->src[5], eadr->src[4], eadr->src[3], eadr->src[2], eadr->src[1], eadr->src[0], static_cast<float>(taginfo->batteryMv) / 1000.0, static_cast<float>(eadr->adr.batteryMv) / 1000.0);
logLine(buffer);
}
taginfo->LQI = eadr->adr.lastPacketLQI;
taginfo->hwType = eadr->adr.hwType;
taginfo->RSSI = eadr->adr.lastPacketRSSI;
@@ -476,11 +494,6 @@ void processDataReq(struct espAvailDataReq* eadr, bool local) {
taginfo->hwType = eadr->adr.hwType;
taginfo->wakeupReason = eadr->adr.wakeupReason;
taginfo->capabilities = eadr->adr.capabilities;
if (eadr->adr.wakeupReason >= 0xF0) {
if (!taginfo->pending) taginfo->nextupdate = 0;
memset(taginfo->md5, 0, 16 * sizeof(uint8_t));
memset(taginfo->md5pending, 0, 16 * sizeof(uint8_t));
}
}
if (local) {
sprintf(buffer, "<ADR %02X%02X%02X%02X%02X%02X%02X%02X\n\0", eadr->src[7], eadr->src[6], eadr->src[5], eadr->src[4], eadr->src[3], eadr->src[2], eadr->src[1], eadr->src[0]);

View File

@@ -0,0 +1,80 @@
#include "system.h"
#include <Arduino.h>
#include <FS.h>
#include "LittleFS.h"
void init_time() {
struct tm timeinfo;
while (true) {
if (!getLocalTime(&timeinfo)) {
Serial.println("Waiting for valid time from NTP-server");
vTaskDelay(1000 / portTICK_PERIOD_MS);
} else {
break;
}
}
}
void logLine(char* buffer) {
logLine(String(buffer));
}
void logLine(String text) {
time_t now;
time(&now);
char timeStr[24];
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S ", localtime(&now));
File logFile = LittleFS.open("/log.txt", "a");
if (logFile) {
logFile.print(timeStr);
logFile.println(text);
logFile.close();
}
}
void logStartUp() {
esp_reset_reason_t resetReason = esp_reset_reason();
String logEntry = "Reboot. Reason: ";
switch (resetReason) {
case ESP_RST_POWERON:
logEntry += "Power-on";
break;
case ESP_RST_EXT:
logEntry += "External";
break;
case ESP_RST_SW:
logEntry += "Software";
break;
case ESP_RST_PANIC:
logEntry += "Panic";
break;
case ESP_RST_INT_WDT:
logEntry += "Watchdog";
break;
case ESP_RST_TASK_WDT:
logEntry += "Task Watchdog";
break;
case ESP_RST_WDT:
logEntry += "Other Watchdog";
break;
case ESP_RST_DEEPSLEEP:
logEntry += "Deep Sleep";
break;
case ESP_RST_BROWNOUT:
logEntry += "Brownout";
break;
case ESP_RST_SDIO:
logEntry += "SDIO";
break;
default:
logEntry += "Unknown";
break;
}
logLine(logEntry);
}

View File

@@ -11,7 +11,7 @@
std::vector<tagRecord*> tagDB;
Config config;
SemaphoreHandle_t tagDBOwner;
// SemaphoreHandle_t tagDBOwner;
tagRecord* tagRecord::findByMAC(uint8_t mac[8]) {
for (int16_t c = 0; c < tagDB.size(); c++) {