Browse Source

Add debug console to Status page.

rfm69
Lazar Obradovic 6 years ago
parent
commit
e1802de827
6 changed files with 71 additions and 4 deletions
  1. +11
    -0
      code/espurna/config/general.h
  2. +8
    -0
      code/espurna/debug.ino
  3. +23
    -1
      code/espurna/ws.ino
  4. +11
    -0
      code/html/custom.css
  5. +9
    -1
      code/html/custom.js
  6. +9
    -2
      code/html/index.html

+ 11
- 0
code/espurna/config/general.h View File

@ -94,6 +94,17 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef DEBUG_WEB_SUPPORT
#define DEBUG_WEB_SUPPORT WEB_SUPPORT // Enable web debug log if web is enabled too
#endif
#if DEBUG_WEB_SUPPORT
#undef WEB_SUPPORT
#define WEB_SUPPORT 1 // Chicken and egg :)
#endif
//------------------------------------------------------------------------------
// General debug options and macros // General debug options and macros
#define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT #define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT


+ 8
- 0
code/espurna/debug.ino View File

@ -60,6 +60,14 @@ void _debugSend(char * message) {
_telnetWrite(message, strlen(message)); _telnetWrite(message, strlen(message));
#endif #endif
#if DEBUG_WEB_SUPPORT
#if DEBUG_ADD_TIMESTAMP
wsSend_P(PSTR("{\"weblog\": \"%s %s\"}"), timestamp, message);
#else
wsSend_P(PSTR("{\"weblog\": \"%s\"}"), message);
#endif
#endif
} }


+ 23
- 1
code/espurna/ws.ino View File

@ -221,6 +221,7 @@ void _wsUpdate(JsonObject& root) {
root["uptime"] = getUptime(); root["uptime"] = getUptime();
root["rssi"] = WiFi.RSSI(); root["rssi"] = WiFi.RSSI();
root["loadaverage"] = getLoadAverage(); root["loadaverage"] = getLoadAverage();
root["vcc"] = ESP.getVcc();
#if NTP_SUPPORT #if NTP_SUPPORT
if (ntpSynced()) root["now"] = now(); if (ntpSynced()) root["now"] = now();
#endif #endif
@ -327,7 +328,7 @@ void _wsLoop() {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Piblic API
// Public API
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool wsConnected() { bool wsConnected() {
@ -363,6 +364,7 @@ void wsSend(const char * payload) {
} }
} }
/*
void wsSend_P(PGM_P payload) { void wsSend_P(PGM_P payload) {
if (_ws.count() > 0) { if (_ws.count() > 0) {
char buffer[strlen_P(payload)]; char buffer[strlen_P(payload)];
@ -370,6 +372,26 @@ void wsSend_P(PGM_P payload) {
_ws.textAll(buffer); _ws.textAll(buffer);
} }
} }
*/
void wsSend_P(PGM_P format_P, ...) {
if (_ws.count() > 0) {
char format[strlen_P(format_P)+1];
memcpy_P(format, format_P, sizeof(format));
va_list args;
va_start(args, format_P);
char test[1];
int len = ets_vsnprintf(test, 1, format, args) + 1;
char * buffer = new char[len];
ets_vsnprintf(buffer, len, format, args);
va_end(args);
_ws.textAll(buffer);
delete[] buffer;
}
}
void wsSend(uint32_t client_id, ws_on_send_callback_f callback) { void wsSend(uint32_t client_id, ws_on_send_callback_f callback) {
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;


+ 11
- 0
code/html/custom.css View File

@ -286,3 +286,14 @@ span.slider {
font-size: 60%; font-size: 60%;
margin-top: 10px; margin-top: 10px;
} }
/* -----------------------------------------------------------------------------
Logs
-------------------------------------------------------------------------- */
#weblog {
font-family: 'Courier New', monospace;
font-size: 60%;
resize: none;
height: 300px;
line-height: 100%;
}

+ 9
- 1
code/html/custom.js View File

@ -1105,6 +1105,11 @@ function processData(data) {
return; return;
} }
if ("weblog" === key) {
document.getElementById("weblog").value += value;
return;
}
// Enable options // Enable options
var position = key.indexOf("Visible"); var position = key.indexOf("Visible");
if (position > 0 && position === key.length - 7) { if (position > 0 && position === key.length - 7) {
@ -1247,7 +1252,10 @@ function connect(host) {
if (websock) { websock.close(); } if (websock) { websock.close(); }
websock = new WebSocket(wshost); websock = new WebSocket(wshost);
websock.onmessage = function(evt) { websock.onmessage = function(evt) {
var data = getJson(evt.data);
var data = getJson(evt.data
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t"));
if (data) { processData(data); } if (data) { processData(data); }
}; };
} }


+ 9
- 2
code/html/index.html View File

@ -190,6 +190,9 @@
<div class="pure-u-1-2 pure-u-lg-1-4">Chip ID</div> <div class="pure-u-1-2 pure-u-lg-1-4">Chip ID</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="chipid"></span></div> <div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="chipid"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Vcc</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="vcc"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">MAC</div> <div class="pure-u-1-2 pure-u-lg-1-4">MAC</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="mac"></span></div> <div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="mac"></span></div>
@ -224,7 +227,7 @@
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="uptime"></span></div> <div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="uptime"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Load average</div> <div class="pure-u-1-2 pure-u-lg-1-4">Load average</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="loadaverage"></span>%</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="loadaverage"></span><span>%</span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Free heap</div> <div class="pure-u-1-2 pure-u-lg-1-4">Free heap</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="heap" post=" bytes"></span></div> <div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="heap" post=" bytes"></span></div>
@ -241,11 +244,15 @@
<div class="pure-u-1-2 pure-u-lg-1-4">NTP Status</div> <div class="pure-u-1-2 pure-u-lg-1-4">NTP Status</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="ntpStatus">NOT AVAILABLE</span></div> <div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="ntpStatus">NOT AVAILABLE</span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Last update</div>
<div class="pure-u-1-2 pure-u-lg-1-4">Last NTP update</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="ago">?</span><span> seconds ago</span></div> <div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="ago">?</span><span> seconds ago</span></div>
</div> </div>
<div class="pure-g">
<textarea class="pure-u-1" readonly id="weblog" name="weblog" wrap="off"></textarea>
</div>
</fieldset> </fieldset>
</form> </form>


Loading…
Cancel
Save