forked from patience4711/ESP32-read-APS-inverters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAAA_LOG.ino
186 lines (163 loc) · 6.03 KB
/
AAA_LOG.ino
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//<script type="text/javascript" src="SECURITY"></script>
//<table><tr><td style='width:240px;'>Last refresh : !@@!<td>
//<button onClick='window.location.reload();' style='width: 100px' value='0'>Refresh</button></table><br>
const char LOGPAGE[] PROGMEM = R"=====(
<!DOCTYPE html><html><head><meta charset='utf-8'>
<title>ESP32-ECU</title>
<meta http-equiv="refresh" content="112">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="/favicon.ico"/>
<link rel="stylesheet" type="text/css" href="/STYLESHEET">
<style>
#lijst {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 380px;
font-size:16px;
border: 1px solid;
text-align: left;
}
#lijst td {
padding-left: 10px;
border: 1px solid;
}
#lijst tr:nth-child(even){background-color: #f2f2f2;
border: 1px solid #ddd;
padding: 6px;
}
#lijst th {
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
text-align: left;
background-color: #4CAF50;
color: white;
}
.th1 { width:30%; }
.th2 { width:20%; }
.th3 { width:50%; }
tr {height:20px;}
@media only screen and (max-width: 600px) {
#lijst{ font-size:12px; width: 320px;}
tr {width:94vw;}
.th1 { width:25%; }
.th2 { width:15%; }
}
</style>
<script type="text/javascript" src="SECURITY"></script>
</head>
<body>
<center>
<ul>
<li><a href='/'>close</a></li>
<li><a href='/ABOUT'>info</a></li>
<li><a onclick="return confirm('are you sure?')" href='/CLEAR_LOG'>clear</a></li>
</ul>
<br><kop>ESP32-ECU LOG</kop>
<div class='divstijl'><center>
<table><button onClick='window.location.reload();' style='width: 100px' value='0'>Refresh</button></table>
<table id='lijst'><tr><th class='th1'>Time</th><th class='th2'>Type</th><th class='th3'>Command</th></tr>
)=====";
//</tr><tr><td>date </td><td>system</td><td>192.168.0.aaa.sss.ddd </td></tr>
void handleLogPage( AsyncWebServerRequest *request ) {
Serial.println("zendPageLog ");
// String uur = String(hour());
// if(hour() < 10) {
// uur = "0" + String(hour());
// }
// String minuten = String(minute());
// if(minute() < 10) {
// minuten = "0" + String(minute());
// }
//String cont = "";
//cont += uur + " : " + minuten + " hr.";
char page[3072] = {0};
char temp[100]={0};
strcpy_P(page, LOGPAGE);
//strcat(page, "<table id='lijst'><tr><th class='th1'>Time</th><th class='th2'>Type</th><th class='th3'>Command</th></tr>");
uint32_t lengte= strlen(page );
uint32_t added = 0;
Serial.println("initial length = " + String(lengte )); // 1319
//toSEND.replace("!@@!", cont);
//DebugPrintln(" zendlogpage :build eventlist");
byte Log_Count = 0;
Log_MaxReached ? Log_Count = Log_MaxEvents : Log_Count = logNr; // determine if the max number of event is reached
Serial.println("log_Count = " + String(Log_Count ));
Serial.println("printlog current event = " + String(logNr));
int j = logNr;
String content = "";
for ( int i = 1; i <= Log_Count; i++ ) {
//Serial.println("een regel van de lijst, nummer i = "); //Serial.println(i);
j--; // we get the index of the last record in the array
//Serial.println("een regel van de lijst, nummer j = "); //Serial.println(j);
if (j ==-1) j = Log_MaxEvents - 1; // if we are under the first index of the array ,we go to the last
////////////////// One table line ///////////////////
//sprintf(temp,"<tr><td>%s</td><td>%s</td><td>%s</td>", Log_date[logNr], Log_list[j].Log_kind, Log_list[j].Log_message);
sprintf(temp,"<tr><td>%s</td><td>%s</td><td>%s</td>", Log_date[j], Log_kind[j], Log_message[j] );
strcat(page, temp);
added = strlen(page) - lengte;
Serial.println("length added = " + String(added ));
lengte= strlen(page );
////////////////// One table line ///////////////////
}
//Serial.print(content);
// end of page
strcat(page, "</table></center></div></div></body></html>");
Serial.println("length = " + String(strlen(page )));
request->send(200, "text/html", page);
}
void Update_Log(char what[], char message[]) {
char nu[14];
//DebugPrintln("updating the log");
Serial.println("what = " + String(what));
if(String(what) != "clear") {
sprintf(nu,"%d-%d:%d:%d ", day(), hour(), minute(), second());
} else {
nu[0] = '\0';
what[0] = '\0';}
//Serial.println("nu = " + String(nu));
strcpy( Log_date[logNr], nu );
//Serial.println("Log_date[logNr] = " + String(Log_date[logNr]) );
strcpy( Log_kind[logNr], what );
//Serial.println("Log_kind[logNr] = " + String(Log_kind[logNr]) );
strcpy( Log_message[logNr], message );
//Serial.println("Log_message[logNr] = " + String(Log_message[logNr]) );
//strcpy( Log_list[logNr].Log_kind, what );
//strcpy( Log_list[logNr].Log_message, message );
logNr++;
Serial.println("log current event = " + String(logNr));
if (logNr >= Log_MaxEvents)
{
logNr = 0;//start again
Log_MaxReached = true;
}
Serial.println("log updated");
}
void Clear_Log(AsyncWebServerRequest *request) {
if(!checkRemote( request->client()->remoteIP().toString()) ) {
if(logNr != 0) {
for (int i=0; i <= Log_MaxEvents; i++) {
Log_date[20][0] = '\0';
Log_kind[20][0] = '\0';
Log_message[20][0] = '\0';
}
logNr = 0;//start again
Log_MaxReached = false;
//Serial.println("log cleared");
}
}
}
//void Clear_Log() {
// //Serial.println("clearing the log");
// if(logNr != 0) {
// //char nu[0]='\0';
// //char what[0]='\0';
// //char message[0]='\0';;
// for (int i=0; i <= Log_MaxEvents; i++) {
// //Update_log("clear", "");
// }
// logNr = 0;//start again
// Log_MaxReached = false;
// //Serial.println("log cleared");
// }
//}