Browse Source

Merge pull request #658 from lobradov/web-console

Debug console on web
rfm69
Xose Pérez 6 years ago
committed by GitHub
parent
commit
9e99cab572
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 118 additions and 46 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
    -2
      code/html/custom.js
  6. +56
    -43
      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
#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));
#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["rssi"] = WiFi.RSSI();
root["loadaverage"] = getLoadAverage();
root["vcc"] = ESP.getVcc();
#if NTP_SUPPORT
if (ntpSynced()) root["now"] = now();
#endif
@ -327,7 +328,7 @@ void _wsLoop() {
}
// -----------------------------------------------------------------------------
// Piblic API
// Public API
// -----------------------------------------------------------------------------
bool wsConnected() {
@ -363,6 +364,7 @@ void wsSend(const char * payload) {
}
}
/*
void wsSend_P(PGM_P payload) {
if (_ws.count() > 0) {
char buffer[strlen_P(payload)];
@ -370,6 +372,26 @@ void wsSend_P(PGM_P payload) {
_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) {
DynamicJsonBuffer jsonBuffer;


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

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

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

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


+ 56
- 43
code/html/index.html View File

@ -179,71 +179,84 @@
<div id="magnitudes"></div>
<div class="pure-u-1 state">
<div class="pure-u-1 pure-u-lg-1-2 state">
<div class="pure-u-1-2">Manufacturer</div>
<div class="pure-u-11-24"><span class="right" name="manufacturer"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Manufacturer</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="manufacturer"></span></div>
<div class="pure-u-1-2">Device</div>
<div class="pure-u-11-24"><span class="right" name="device"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Device</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="device"></span></div>
<div class="pure-u-1-2">Chip ID</div>
<div class="pure-u-11-24"><span class="right" name="chipid"></span></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-1-2">Firmware name</div>
<div class="pure-u-11-24"><span class="right" name="app_name"></span></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-1-2">Firmware version</div>
<div class="pure-u-11-24"><span class="right" name="app_version"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Network</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="network"></span></div>
<div class="pure-u-1-2">Firmware build</div>
<div class="pure-u-11-24"><span class="right" name="app_build"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">BSSID</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="bssid"></span></div>
<div class="pure-u-1-2">Current time</div>
<div class="pure-u-11-24"><span class="right" name="now"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Channel</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="channel"></span></div>
<div class="pure-u-1-2">Uptime</div>
<div class="pure-u-11-24"><span class="right" name="uptime"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">RSSI</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="rssi"></span></div>
<div class="pure-u-1-2">Load average</div>
<div class="pure-u-11-24"><span class="right" name="loadaverage"></span><span>%</span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">IP</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="deviceip"></span></div>
<div class="pure-u-1-2">Vcc</div>
<div class="pure-u-11-24"><span class="right" name="vcc"></span><span>mV</span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Firmware name</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="app_name"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Firmware version</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="app_version"></span></div>
<div class="pure-u-1-2">MQTT Status</div>
<div class="pure-u-11-24"><span class="right" name="mqttStatus">NOT AVAILABLE</span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Firmware build</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="app_build"></span></div>
</div>
<div class="pure-u-1 pure-u-lg-11-24">
<div class="pure-u-1-2">Wifi MAC</div>
<div class="pure-u-11-24"><span class="right" name="mac"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Current time</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="now"></span></div>
<div class="pure-u-1-2">Network</div>
<div class="pure-u-11-24"><span class="right" name="network"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Uptime</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">BSSID</div>
<div class="pure-u-11-24"><span class="right" name="bssid"></span></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-1-2">Channel</div>
<div class="pure-u-11-24"><span class="right" name="channel"></span></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-1-2">RSSI</div>
<div class="pure-u-11-24"><span class="right" name="rssi"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Firmware size</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="sketch_size" post=" bytes"></span></div>
<div class="pure-u-1-2">IP</div>
<div class="pure-u-11-24"><span class="right" name="deviceip"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Free space</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="free_size" post=" bytes"></span></div>
<div class="pure-u-1-2">Free heap</div>
<div class="pure-u-11-24"><span class="right" name="heap" post=" bytes"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">MQTT Status</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="mqttStatus">NOT AVAILABLE</span></div>
<div class="pure-u-1-2">Firmware size</div>
<div class="pure-u-11-24"><span class="right" name="sketch_size" post=" bytes"></span></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-1-2">Free space</div>
<div class="pure-u-11-24"><span class="right" name="free_size" post=" bytes"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Last 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-1-2">NTP Status</div>
<div class="pure-u-11-24"><span class="right" name="ntpStatus">NOT AVAILABLE</span></div>
<div class="pure-u-1-2">Last update</div>
<div class="pure-u-11-24"><span class="right" name="ago">?</span><span> seconds ago</span></div>
</div>
<div class="header">
<h2>Debug log</h2>
</div>
<div class="pure-g">
<textarea class="pure-u-1" readonly id="weblog" name="weblog" wrap="off"></textarea>
</div>
</fieldset>


Loading…
Cancel
Save