-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.h
67 lines (52 loc) · 1.54 KB
/
Main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include <Arduino.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#include <ESPAsyncWebServer.h>
#include <StreamString.h>
#include "ulog_sqlite.h"
#include <Esp32Logging.hpp>
#include "Consts.h"
//
// Record
struct Record
{
time_t timestamp;
float currentMilliAmps;
float voltageMilliVolts;
Record()
{
time(×tamp);
}
static constexpr int ColumnCount = 3;
int AppendToDb(struct dblog_write_context *wctx) const
{
static uint8_t types[] = {DBLOG_TYPE_INT, DBLOG_TYPE_REAL, DBLOG_TYPE_REAL};
const void *values[] = {×tamp, ¤tMilliAmps, &voltageMilliVolts};
static uint16_t lengths[] = {sizeof(time_t), sizeof(float), sizeof(float)};
return dblog_append_row_with_values(wctx, types, values, lengths);
}
String toJsonString() const
{
StreamString stringBuffer;
stringBuffer.printf("[%ld,%f,%f]", timestamp, currentMilliAmps, voltageMilliVolts);
return stringBuffer;
}
static constexpr int JsonMaxChars = 30;
};
//
// DataLogger.cpp
void setupDataLogger(int flushEverySeconds, int queueLength);
bool isDatabaseAccessible();
bool addRecord(const Record &record, bool addToRingbuffer);
void flushQueue();
uint getQueueSize();
void resetDb();
bool dbFileExists(bool noLog = false);
static constexpr size_t latestRecordsBufferSize = 6;
//
// WebserverAsync.cpp
extern AsyncWebServer asyncWebServer;
void setupWebServer();
void loopWebServer();