Skip to content

Commit 6d32cf0

Browse files
authored
Merge pull request #101 from OpenEVSE/remote_debug
Changes for remote displaying the serial output(s)
2 parents 9ba62ad + 954f116 commit 6d32cf0

File tree

13 files changed

+136
-56
lines changed

13 files changed

+136
-56
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ lib/ArduinoMongoose
8686
lib/ConfigJson
8787
lib/OpenEVSE
8888
lib/ESPAL
89+
lib/MicroDebug
90+
lib/StreamSpy

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ version = -DBUILD_TAG=3.2.0
3434
monitor_speed = 115200
3535
lib_deps =
3636
37-
37+
3838
3939
4040
4141
42+
4243
extra_scripts = scripts/extra_script.py
4344
debug_flags =
4445
-DENABLE_DEBUG

src/debug.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <StreamSpy.h>
2+
3+
StreamSpy SerialDebug(DEBUG_PORT);
4+
StreamSpy SerialEvse(RAPI_PORT);
5+
6+
void debug_setup()
7+
{
8+
DEBUG_PORT.begin(115200);
9+
SerialDebug.begin(2048);
10+
11+
RAPI_PORT.begin(115200);
12+
SerialEvse.begin(2048);
13+
}

src/debug.h

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,18 @@
11
#ifndef __DEBUG_H
22
#define __DEBUG_H
33

4-
#ifdef ESP8266
5-
#include <core_version.h>
6-
#endif
4+
#undef DEBUG_PORT
5+
#define DEBUG_PORT SerialDebug
76

8-
//#define ENABLE_DEBUG
9-
//#define DEBUG_PORT Serial
7+
#undef RAPI_PORT
8+
#define RAPI_PORT SerialEvse
109

11-
#define TEXTIFY(A) #A
12-
#define ESCAPEQUOTE(A) TEXTIFY(A)
10+
#include "MicroDebug.h"
11+
#include "StreamSpy.h"
1312

14-
#ifdef ENABLE_DEBUG
13+
extern StreamSpy SerialDebug;
14+
extern StreamSpy SerialEvse;
1515

16-
// Use os_printf, works but also outputs additional dubug if not using Serial
17-
//#define DEBUG_BEGIN(speed) DEBUG_PORT.begin(speed); DEBUG_PORT.setDebugOutput(true)
18-
//#define DBUGF(format, ...) os_printf(PSTR(format "\n"), ##__VA_ARGS__)
19-
20-
21-
#define DEBUG_BEGIN(speed) DEBUG_PORT.begin(speed)
22-
23-
#ifdef ARDUINO_ESP8266_RELEASE_2_4_0
24-
// Serial.printf_P needs Git version of Arduino Core
25-
#define DBUGF(format, ...) DEBUG_PORT.printf_P(PSTR(format "\n"), ##__VA_ARGS__)
26-
#else
27-
#define DBUGF(format, ...) DEBUG_PORT.printf(format "\n", ##__VA_ARGS__)
28-
#endif
29-
30-
#define DBUG(...) DEBUG_PORT.print(__VA_ARGS__)
31-
#define DBUGLN(...) DEBUG_PORT.println(__VA_ARGS__)
32-
#define DBUGVAR(x, ...) do { DEBUG_PORT.print(ESCAPEQUOTE(x) " = "); DEBUG_PORT.println(x, ##__VA_ARGS__); } while (false)
33-
34-
#else
35-
36-
#define DEBUG_BEGIN(speed) DEBUG_PORT.begin(speed)
37-
#define DBUGF(...)
38-
#define DBUG(...)
39-
#define DBUGLN(...)
40-
#define DBUGVAR(...)
41-
42-
#endif // DEBUG
43-
44-
#ifdef DEBUG_SERIAL1
45-
#error DEBUG_SERIAL1 defiend, please use -DDEBUG_PORT=Serial1 instead
46-
#endif
47-
48-
#ifndef DEBUG_PORT
49-
#define DEBUG_PORT Serial1
50-
#endif
51-
#define DEBUG DEBUG_PORT
16+
extern void debug_setup();
5217

5318
#endif // __DEBUG_H

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ void event_send(JsonDocument &event)
239239

240240
void hardware_setup()
241241
{
242-
RAPI_PORT.begin(115200);
243-
DEBUG_BEGIN(115200);
242+
debug_setup();
244243

245244
#ifdef SERIAL_RX_PULLUP_PIN
246245
// https://forums.adafruit.com/viewtopic.php?f=57&t=153553&p=759890&hilit=esp32+serial+pullup#p769168
@@ -256,4 +255,4 @@ void hardware_setup()
256255
#endif
257256

258257
enableLoopWDT();
259-
}
258+
}

src/time_man.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <Arduino.h>
2-
#include <MicroDebug.h>
32
#include <MongooseCore.h>
43
#include <MongooseSntpClient.h>
54

5+
#include "debug.h"
66
#include "time_man.h"
77
#include "net_manager.h"
88
#include "openevse.h"

src/web_server.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef const __FlashStringHelper *fstr_t;
3838
MongooseHttpServer server; // Create class for Web server
3939

4040
bool enableCors = true;
41+
bool streamDebug = false;
4142

4243
// Event timeouts
4344
static unsigned long wifiRestartTime = 0;
@@ -46,7 +47,7 @@ static unsigned long apOffTime = 0;
4647

4748
// Content Types
4849
const char _CONTENT_TYPE_HTML[] PROGMEM = "text/html";
49-
const char _CONTENT_TYPE_TEXT[] PROGMEM = "text/text";
50+
const char _CONTENT_TYPE_TEXT[] PROGMEM = "text/plain";
5051
const char _CONTENT_TYPE_CSS[] PROGMEM = "text/css";
5152
const char _CONTENT_TYPE_JSON[] PROGMEM = "application/json";
5253
const char _CONTENT_TYPE_JS[] PROGMEM = "application/javascript";
@@ -1121,6 +1122,50 @@ web_server_setup() {
11211122
onUpload(handleUpdateUpload)->
11221123
onClose(handleUpdateClose);
11231124

1125+
server.on("/debug$", [](MongooseHttpServerRequest *request) {
1126+
MongooseHttpServerResponseStream *response;
1127+
if(false == requestPreProcess(request, response, CONTENT_TYPE_TEXT)) {
1128+
return;
1129+
}
1130+
1131+
response->setCode(200);
1132+
response->setContentType(CONTENT_TYPE_TEXT);
1133+
response->addHeader("Access-Control-Allow-Origin", "*");
1134+
SerialDebug.printBuffer(*response);
1135+
request->send(response);
1136+
});
1137+
1138+
server.on("/debug/console$")->onFrame([](MongooseHttpWebSocketConnection *connection, int flags, uint8_t *data, size_t len) {
1139+
});
1140+
1141+
SerialDebug.onWrite([](const uint8_t *buffer, size_t size)
1142+
{
1143+
server.sendAll("/debug/console", WEBSOCKET_OP_TEXT, buffer, size);
1144+
});
1145+
1146+
server.on("/evse$", [](MongooseHttpServerRequest *request) {
1147+
MongooseHttpServerResponseStream *response;
1148+
if(false == requestPreProcess(request, response, CONTENT_TYPE_TEXT)) {
1149+
return;
1150+
}
1151+
1152+
response->setCode(200);
1153+
response->setContentType(CONTENT_TYPE_TEXT);
1154+
response->addHeader("Access-Control-Allow-Origin", "*");
1155+
SerialEvse.printBuffer(*response);
1156+
request->send(response);
1157+
});
1158+
1159+
server.on("/evse/console$")->onFrame([](MongooseHttpWebSocketConnection *connection, int flags, uint8_t *data, size_t len) {
1160+
});
1161+
1162+
SerialEvse.onWrite([](const uint8_t *buffer, size_t size) {
1163+
server.sendAll("/evse/console", WEBSOCKET_OP_TEXT, buffer, size);
1164+
});
1165+
SerialEvse.onRead([](const uint8_t *buffer, size_t size) {
1166+
server.sendAll("/evse/console", WEBSOCKET_OP_TEXT, buffer, size);
1167+
});
1168+
11241169
server.on("/ws$")->onFrame(onWsFrame);
11251170

11261171
server.onNotFound(handleNotFound);
@@ -1158,5 +1203,5 @@ void web_server_event(JsonDocument &event)
11581203
{
11591204
String json;
11601205
serializeJson(event, json);
1161-
server.sendAll(json);
1206+
server.sendAll("/ws", json);
11621207
}

src/web_static/web_server.home.html.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
static const char CONTENT_TERM_HTML[] PROGMEM =
2+
"<html> <head> <title>OpenEVSE Terminal</title> <style> body {\n"
3+
" color:#fff;\n"
4+
" background-color:#300a24;\n"
5+
" }\n"
6+
" pre {\n"
7+
" word-break: break-all;\n"
8+
" white-space: pre-wrap;\n"
9+
" } </style> <script src=\"term.js\"></script> </head> <body> <pre id=\"term\"></pre> </body> </html>\n";

0 commit comments

Comments
 (0)