This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
MenuStuff.ino
300 lines (267 loc) · 13.2 KB
/
MenuStuff.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
***************************************************************************
** Program : MenuStuff, part of DSMRlogger2HTTP
** Version : v0.7.8
**
** Copyright (c) 2019 Willem Aandewiel
**
** TERMS OF USE: MIT License. See bottom of file.
***************************************************************************
*/
//===========================================================================================
void displayDaysHist(bool Telnet=true) {
//===========================================================================================
char ED[20], ER[20], GD[20], today;
int thisDay = weekday(unixTimestamp) - 1;
int Label;
if (Telnet) TelnetStream.println("\n======== WeekDay History ==========\r\n");
for (int i=0; i<7; i++) {
if (i == thisDay) today = '*';
else today = ' ';
Label = weekDat[i].Label;
dtostrf(weekDat[i].EnergyDelivered, 9, 3, ED);
dtostrf(weekDat[i].EnergyReturned, 9, 3, ER);
dtostrf(weekDat[i].GasDelivered, 8, 2, GD);
sprintf(cMsg, "[%02d][%02d]%c Energy Del.[%s], Ret.[%s], Gas Del.[%s]\r", i, Label, today
, ED, ER, GD);
if (Telnet) TelnetStream.println(cMsg);
}
TelnetStream.flush();
} // displayDaysHist()
//===========================================================================================
void displayHoursHist(bool Telnet=true) {
//===========================================================================================
char ED[20], ER[20], GD[20], hour;
int thisHour = HourFromTimestamp(pTimestamp);
int Label;
if (Telnet) TelnetStream.println("\n======== Hours History ==========\r\n");
for (int i=1; i<=8; i++) {
if (i == thisHour) hour = '*';
else hour = ' ';
Label = hoursDat[i].Label;
dtostrf(hoursDat[i].EnergyDelivered, 9, 3, ED);
dtostrf(hoursDat[i].EnergyReturned, 9, 3, ER);
dtostrf(hoursDat[i].GasDelivered, 8, 2, GD);
sprintf(cMsg, "[%02d][%02d]%c Energy Del.[%s], Ret.[%s], Gas Del.[%s]\r", i, Label, hour
, ED, ER, GD);
if (Telnet) TelnetStream.println(cMsg);
}
TelnetStream.flush();
} // displayHoursHist()
//===========================================================================================
void displayMonthsHist(bool Telnet=true) {
//===========================================================================================
char ED[20], ER[20], GD[20], signal;
int thisMonth = MonthFromTimestamp(pTimestamp);
int thisYear = YearFromTimestamp(pTimestamp);
int Label;
if (Telnet) TelnetStream.println("\n======== Months History ==========\r\n");
for (int i=1; i<=24; i++) {
Label = monthsDat[i].Label;
dtostrf(monthsDat[i].EnergyDelivered, 9, 3, ED);
dtostrf(monthsDat[i].EnergyReturned, 9, 3, ER);
dtostrf(monthsDat[i].GasDelivered, 8, 2, GD);
sprintf(cMsg, "[%02d][%04d] Energy Del.[%s], Ret.[%s], Gas Del.[%s]\r", i, Label
, ED, ER, GD);
if (Telnet) TelnetStream.println(cMsg);
}
TelnetStream.flush();
} // displayMonthsHist()
//===========================================================================================
void displayBoardInfo() {
//===========================================================================================
TelnetStream.println("\r\n==================================================================\r");
TelnetStream.print(" \r\n (c)2018 by [Willem Aandewiel (www.aandewiel.nl)");
TelnetStream.print("]\r\n Firmware Version ["); TelnetStream.print( _FW_VERSION );
TelnetStream.print("]\r\n Compiled ["); TelnetStream.print( __DATE__ );
TelnetStream.print( " " );
TelnetStream.print( __TIME__ );
TelnetStream.print("]\r\n Telegrams Processed ["); TelnetStream.print( telegramCount );
TelnetStream.print("]\r\n With Errors ["); TelnetStream.print( telegramErrors );
TelnetStream.print("]\r\n FreeHeap ["); TelnetStream.print( ESP.getFreeHeap() );
TelnetStream.print("]\r\n Chip ID ["); TelnetStream.print( ESP.getChipId(), HEX );
TelnetStream.print("]\r\n Core Version ["); TelnetStream.print( ESP.getCoreVersion() );
TelnetStream.print("]\r\n SDK Version ["); TelnetStream.print( ESP.getSdkVersion() );
TelnetStream.print("]\r\n CPU Freq (MHz) ["); TelnetStream.print( ESP.getCpuFreqMHz() );
TelnetStream.print("]\r\n Sketch Size (kB) ["); TelnetStream.print( ESP.getSketchSize() / 1024.0 );
TelnetStream.print("]\r\n Free Sketch Space (kB) ["); TelnetStream.print( ESP.getFreeSketchSpace() / 1024.0 );
if ((ESP.getFlashChipId() & 0x000000ff) == 0x85)
sprintf(cMsg, "%08X (PUYA)", ESP.getFlashChipId());
else sprintf(cMsg, "%08X", ESP.getFlashChipId());
TelnetStream.print("]\r\n Flash Chip ID ["); TelnetStream.print( cMsg );
TelnetStream.print("]\r\n Flash Chip Size (kB) ["); TelnetStream.print( ESP.getFlashChipSize() / 1024 );
TelnetStream.print("]\r\nFlash Chip Real Size (kB) ["); TelnetStream.print( ESP.getFlashChipRealSize() / 1024 );
TelnetStream.print("]\r\n Flash Chip Speed ["); TelnetStream.print( ESP.getFlashChipSpeed() / 1000 / 1000 );
FlashMode_t ideMode = ESP.getFlashChipMode();
TelnetStream.print("]\r\n Flash Chip Mode ["); TelnetStream.print( flashMode[ideMode] );
TelnetStream.println("]\r");
TelnetStream.println("==================================================================");
TelnetStream.print(" \r\n Board type [");
#ifdef ARDUINO_ESP8266_NODEMCU
TelnetStream.print("ESP8266_NODEMCU");
#endif
#ifdef ARDUINO_ESP8266_GENERIC
TelnetStream.print("ESP8266_GENERIC");
#endif
#ifdef ESP8266_ESP01
TelnetStream.print("ESP8266_ESP01");
#endif
#ifdef ESP8266_ESP12
TelnetStream.print("ESP8266_ESP12");
#endif
TelnetStream.print("]\r\n SSID ["); TelnetStream.print( WiFi.SSID() );
TelnetStream.print("]\r\n PSK key ["); TelnetStream.print( WiFi.psk() );
TelnetStream.print("]\r\n IP Address ["); TelnetStream.print( WiFi.localIP() );
TelnetStream.print("]\r\n Hostname ["); TelnetStream.print( HOSTNAME );
TelnetStream.print("]\r\n upTime ["); TelnetStream.print( upTime() );
TelnetStream.println("]\r");
TelnetStream.println("==================================================================\r\n");
TelnetStream.flush();
} // displayBoardInfo()
//===========================================================================================
void waitForOTAupload() {
//===========================================================================================
uint32_t maxWait = millis() + 33000;
TelnetStream.println("Wait 30 seconds for OTAupload to start....\r");
TelnetStream.flush();
OTAinProgress = true;
while(maxWait > millis()) { // hm.. does not seem to work ..
ArduinoOTA.handle();
delay(10);
}
TelnetStream.println("now Rebooting.\r");
TelnetStream.flush();
ESP.reset();
} // waitForOTAupload()
//===========================================================================================
void handleKeyInput() {
//===========================================================================================
char inChar;
while (TelnetStream.available() > 0) {
yield();
inChar = (char)TelnetStream.read();
switch(inChar) {
case 'b':
case 'B': displayBoardInfo();
break;
case 'd':
case 'D': displayDaysHist(true);
displayHoursHist(true);
displayMonthsHist(true);
break;
case 'F': TelnetStream.printf("\r\nConnect to AP [%s] and go to ip address shown in the AP-name\r\n", APname);
TelnetStream.flush();
delay(1000);
WiFi.disconnect(); // deletes credentials !
//setupWiFi(true);
ESP.reset();
break;
case 'G': if (!readWeekData()) TelnetStream.println("handleKeyInput(): error readWeekData()!");
if (!readHourData()) TelnetStream.println("handleKeyInput(): error readHourData()!");
if (!readMonthData()) TelnetStream.println("handleKeyInput(): error readMonthData()!");
break;
case 'i':
case 'I': for(int I=0; I<10; I++) {
digitalWrite(BUILTIN_LED, !digitalRead(BUILTIN_LED));
delay(1000);
}
break;
#ifdef HAS_NO_METER
case 'Z': createDummyData();
break;
case 'm':
case 'M': testMonth++;
break;
#else
case 'n':
case 'M': showRaw = !showRaw;
break;
#endif
case 'R': TelnetStream.print("Reboot in 3 seconds ... \r");
TelnetStream.flush();
delay(3000);
TelnetStream.println("now Rebooting. \r");
TelnetStream.flush();
ESP.reset();
break;
case 's':
case 'S': listSPIFFS();
break;
case 'U': saveWeekData();
saveHourData(9);
saveThisMonth(thisYear, thisMonth, false);
break;
case 'v':
case 'V': if (Verbose) {
TelnetStream.println("Verbose is OFF\r");
Verbose = false;
} else {
TelnetStream.println("Verbose is ON\r");
Verbose = true;
}
TelnetStream.flush();
break;
case 'w':
case 'W': if (waitForATOupdate > millis()) {
OTAinProgress = false;
waitForATOupdate = millis();
} else {
OTAinProgress = true;
waitForATOupdate = millis() + 30000; // wait for 30 seconds
}
break;
default: TelnetStream.println("\nCommands are:\r\n");
TelnetStream.println(" B - Board Type\r");
TelnetStream.println(" D - Display tables from memory\r");
TelnetStream.println(" *F - Force Re-Config WiFi\r");
TelnetStream.println(" *G - Get from SPIFFS (read Data-files)\r");
TelnetStream.printf (" I - Identify by blinking LED on GPIO[%02d]\r\n", BUILTIN_LED);
#ifdef HAS_NO_METER
TelnetStream.println(" *Z - create Dummy Data\r");
TelnetStream.println(" m - force next Month\r");
#endif
if (showRaw) {
TelnetStream.println(" N - Start Parsing again\r");
} else {
TelnetStream.println(" N - No Parsing (show RAW data from Smart Meter)\r");
showRawCount = 0;
}
TelnetStream.println(" *R - Reboot\r");
TelnetStream.println(" S - SPIFFS space available\r");
TelnetStream.println(" *U - Update SPIFFS (save Data-files)\r");
TelnetStream.println(" V - Toggle Verbose\r");
if (waitForATOupdate > millis()) {
TelnetStream.println(" W - Cancel Wait for ATO update\r");
} else {
TelnetStream.println(" W - Wait for OTA upload \r");
}
TelnetStream.println("\r");
} // switch()
while (TelnetStream.available() > 0) {
yield();
(char)TelnetStream.read();
}
}
} // handleKeyInput()
/***************************************************************************
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
***************************************************************************/