work on reporting code. todo..

Former-commit-id: 0a0a48ec0d540d232b2cf3e8930a125ad7f38256
master
Ondřej Hruška 9 years ago
parent 91025a4cc7
commit daf3d6dee4
  1. 1
      _web-build_do.sh
  2. 8
      esp_meas.pro
  3. 2
      html/css/app.css
  4. 6
      html/js/all.js
  5. 13
      html/pages/about.tpl
  6. 2
      html/pages/fft.html
  7. 99
      html/pages/monitoring.tpl
  8. 2
      html/pages/sgm.html
  9. 4
      html/pages/status.tpl
  10. 2
      html/pages/wfm.html
  11. 2
      html/pages/wifi.tpl
  12. 1367
      html_src/css/app.css
  13. 9499
      html_src/js/all.js
  14. 3
      user/datalink.h
  15. 39
      user/page_monitoring.c
  16. 8
      user/page_monitoring.h
  17. 103
      user/reporting.c
  18. 45
      user/reporting.h
  19. 2
      user/routes.c

@ -26,6 +26,7 @@ mkdir -p "$BLDDIR/pages"
php "$SRCDIR/page_status.php" > "$BLDDIR/pages/status.tpl" php "$SRCDIR/page_status.php" > "$BLDDIR/pages/status.tpl"
php "$SRCDIR/page_about.php" > "$BLDDIR/pages/about.tpl" php "$SRCDIR/page_about.php" > "$BLDDIR/pages/about.tpl"
php "$SRCDIR/page_wifi.php" > "$BLDDIR/pages/wifi.tpl" php "$SRCDIR/page_wifi.php" > "$BLDDIR/pages/wifi.tpl"
php "$SRCDIR/page_monitoring.php" > "$BLDDIR/pages/monitoring.tpl"
php "$SRCDIR/page_waveform.php" > "$BLDDIR/pages/wfm.html" # no substitutions, .html allows to gzip it. php "$SRCDIR/page_waveform.php" > "$BLDDIR/pages/wfm.html" # no substitutions, .html allows to gzip it.
php "$SRCDIR/page_fft.php" > "$BLDDIR/pages/fft.html" # same php "$SRCDIR/page_fft.php" > "$BLDDIR/pages/fft.html" # same
php "$SRCDIR/page_spectrogram.php" > "$BLDDIR/pages/sgm.html" # same php "$SRCDIR/page_spectrogram.php" > "$BLDDIR/pages/sgm.html" # same

@ -66,7 +66,9 @@ SOURCES += \
user/cgi_reset.c \ user/cgi_reset.c \
user/cgi_ping.c \ user/cgi_ping.c \
esphttpclient/test/httpclient_test.c \ esphttpclient/test/httpclient_test.c \
esphttpclient/httpclient.c esphttpclient/httpclient.c \
user/page_monitoring.c \
user/reporting.c
HEADERS += \ HEADERS += \
include/uart_hw.h \ include/uart_hw.h \
@ -154,7 +156,9 @@ HEADERS += \
user/cgi_reset.h \ user/cgi_reset.h \
user/cgi_ping.h \ user/cgi_ping.h \
esphttpclient/espmissingincludes.h \ esphttpclient/espmissingincludes.h \
esphttpclient/httpclient.h esphttpclient/httpclient.h \
user/page_monitoring.h \
user/reporting.h
DISTFILES += \ DISTFILES += \
style.astylerc \ style.astylerc \

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -19,7 +19,7 @@
<div id="outer"> <div id="outer">
<nav id="menu"> <nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div> <div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/about" class="selected">About</a></nav> <a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/monitoring">Monitoring</a><a href="/about" class="selected">About</a></nav>
<div id="content"> <div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader"> <img src="/img/loader.gif" alt="Loading…" id="loader">
@ -39,11 +39,6 @@
<div class="Box"> <div class="Box">
<h2>Firmware</h2> <h2>Firmware</h2>
<p>
The ESP8266 firmware is based on the amazing <a href="https://github.com/Spritetm/esphttpd" target="blank">esp-httpd</a>
library by Jeroen Domburg.
</p>
<table> <table>
<tr> <tr>
<th>Firmware</th> <th>Firmware</th>
@ -61,7 +56,13 @@
<th>IoT SDK</th> <th>IoT SDK</th>
<td>v%vers_sdk%</td> <td>v%vers_sdk%</td>
</tr> </tr>
<!-- Read & show version of the stm32 firmware -->
</table> </table>
<p>
The webserver is built using the great <a href="https://github.com/Spritetm/esphttpd" target="blank">esp-httpd</a>
library by Jeroen Domburg.
</p>
</div> </div>

@ -19,7 +19,7 @@
<div id="outer"> <div id="outer">
<nav id="menu"> <nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div> <div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft" class="selected">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/about">About</a></nav> <a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft" class="selected">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/monitoring">Monitoring</a><a href="/about">About</a></nav>
<div id="content"> <div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader"> <img src="/img/loader.gif" alt="Loading…" id="loader">

@ -0,0 +1,99 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Monitoring - Current Analyser</title>
<link href="/css/app.css" rel="stylesheet">
<script src="/js/all.js"></script>
<script>
// server root (or URL) - used for local development with remote AJAX calls
// (this needs CORS working on the target - which I added to esp-httpd)
var _root = "";
</script>
</head>
<body class="page-monitoring">
<div id="outer">
<nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/monitoring" class="selected">Monitoring</a><a href="/about">About</a></nav>
<div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader">
<h1>Monitoring &amp; Reporting</h1>
<div class="Box">
<h2>Status</h2>
<table>
<tr>
<th>Reference:</th>
<td>
<span id="hasref" class="Valfield">%refStored%</span>
<a onclick="page_mon.captureRef()" class="button btn-green">Capture</a>
</td>
</tr>
<tr>
<th>Actual&nbsp;distance:</th>
<td>
<span id="refdist" class="Valfield">N/A</span>
<a onclick="page_mon.compareNow()" class="button btn-blue">Measure</a>
</td>
</tr>
</table>
</div>
<div class="Box">
<h2>Reporting</h2>
<form method="POST">
<table>
<tr>
<th><label for="rep-on">Reporting:</label></th>
<td>
<input type="checkbox" id="rep-on" name="rep-on" %repEnableCheck%><!--
-->&nbsp;<label for="rep-on">enabled</label>
</td>
</tr>
<tr>
<th><label for="rep-interval">Interval:</label></th>
<td>
<input type="number" id="rep-interval" style="max-width: 10em" value="%repInterval%"><!--
-->&nbsp;seconds
</td>
</tr>
<tr>
<th>Service:</th>
<td>
<input type="radio" name="rep-service" value="xively" id="rep-svc-xv" %repSvcCheckXv%>&nbsp;<label for="rep-svc-xv">Xively</label>&nbsp;
<input type="radio" name="rep-service" value="thingspeak" id="rep-svc-ts" %repSvcCheckTs%>&nbsp;<label for="rep-svc-ts">ThingSpeak</label>
</td>
</tr>
<tr>
<th><label for="rep-feed">Feed/Channel:</label></th>
<td><input type="text" name="rep-feed" id="rep-feed" value="%repFeed%"></td>
</tr>
<tr>
<th><label for="rep-key">API key:</label></th>
<td><input type="text" name="rep-key" id="rep-key" value="%repKey%"></td>
</tr>
<tr>
<th>&nbsp;</th>
<td><input type="submit" value="Save changes"></td>
</tr>
</table>
</form>
</div>
<script>
$().ready(page_mon.init);
</script>
<div class="ErrMsg hidden" id="notif"></div>
</div><!-- content -->
</div><!-- outer -->
</body>
</html>

@ -19,7 +19,7 @@
<div id="outer"> <div id="outer">
<nav id="menu"> <nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div> <div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram" class="selected">Spectrogram</a><a href="/about">About</a></nav> <a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram" class="selected">Spectrogram</a><a href="/monitoring">Monitoring</a><a href="/about">About</a></nav>
<div id="content"> <div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader"> <img src="/img/loader.gif" alt="Loading…" id="loader">

@ -19,7 +19,7 @@
<div id="outer"> <div id="outer">
<nav id="menu"> <nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div> <div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status" class="selected">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/about">About</a></nav> <a href="/status" class="selected">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/monitoring">Monitoring</a><a href="/about">About</a></nav>
<div id="content"> <div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader"> <img src="/img/loader.gif" alt="Loading…" id="loader">
@ -38,7 +38,7 @@
</tr> </tr>
<tr> <tr>
<th></th> <th></th>
<td><a onclick="page_status.trigReset()" class="button btn-red">SW reset</a></td> <td><a onclick="page_status.trigReset()" class="button btn-red">Restart system</a></td>
</tr> </tr>
</table> </table>
</div> </div>

@ -19,7 +19,7 @@
<div id="outer"> <div id="outer">
<nav id="menu"> <nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div> <div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform" class="selected">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/about">About</a></nav> <a href="/status">Home</a><a href="/wifi">WiFi config</a><a href="/waveform" class="selected">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/monitoring">Monitoring</a><a href="/about">About</a></nav>
<div id="content"> <div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader"> <img src="/img/loader.gif" alt="Loading…" id="loader">

@ -19,7 +19,7 @@
<div id="outer"> <div id="outer">
<nav id="menu"> <nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div> <div id="brand" onclick="$('#menu').toggleClass('expanded')">Current Analyser</div>
<a href="/status">Home</a><a href="/wifi" class="selected">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/about">About</a></nav> <a href="/status">Home</a><a href="/wifi" class="selected">WiFi config</a><a href="/waveform">Waveform</a><a href="/fft">FFT</a><a href="/spectrogram">Spectrogram</a><a href="/monitoring">Monitoring</a><a href="/about">About</a></nav>
<div id="content"> <div id="content">
<img src="/img/loader.gif" alt="Loading…" id="loader"> <img src="/img/loader.gif" alt="Loading…" id="loader">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -7,6 +7,9 @@
// request to capture data... // request to capture data...
#define DG_REQUEST_RAW 40 #define DG_REQUEST_RAW 40
#define DG_REQUEST_FFT 41 #define DG_REQUEST_FFT 41
// reporting helpers
#define DG_REQUEST_STORE_REF 42
#define DG_REQUEST_COMPARE_REF 43
extern SBMP_Endpoint *dlnk_ep; extern SBMP_Endpoint *dlnk_ep;

@ -0,0 +1,39 @@
#include <esp8266.h>
#include <httpd.h>
#include "page_monitoring.h"
/** "Monitoring" page - fill form fields */
int FLASH_FN tplMonitoring(HttpdConnData *connData, char *token, void **arg)
{
// arg is unused
(void)arg;
char buf[20];
if (token == NULL) return HTTPD_CGI_DONE;
if (streq(token, "refStored")) {
httpdSend(connData, true ? "OK" : "Not set!", -1); // fixme
} else if (streq(token, "repEnableCheck")) {
if (true) httpdSend(connData, "checked", -1); // fixme
} else if (streq(token, "repInterval")) {
sprintf(buf, "%d", 123); // fixme
httpdSend(connData, buf, -1);
} else if (streq(token, "repSvcCheckXv")) { // Xively
if (true) httpdSend(connData, "checked", -1); // fixme
} else if (streq(token, "repSvcCheckTs")) { // ThingSpeak
if (true) httpdSend(connData, "checked", -1); // fixme
} else if (streq(token, "repFeed")) {
httpdSend(connData, "null", -1); // fixme
} else if (streq(token, "repKey")) {
httpdSend(connData, "null", -1); // fixme
}
return HTTPD_CGI_DONE;
}

@ -0,0 +1,8 @@
#ifndef PAGE_MONITORING_H
#define PAGE_MONITORING_H
#include <httpd.h>
int tplMonitoring(HttpdConnData *connData, char *token, void **arg);
#endif // PAGE_MONITORING_H

@ -0,0 +1,103 @@
#include "reporting.h"
#include "datalink.h"
#include "serial.h"
#define RPT_CONF_MAGIC 0x24C595D5
ReportingResult rpt_result;
ReportingCfg rpt_conf;
static os_timer_t rpt_tim;
/** Timer cb */
static void rpt_tim_cb(void *arg)
{
(void)arg;
reporting_send_now();
}
/** Stop / start timer & set interval based on rpt conf */
static void set_timer(void)
{
os_timer_disarm(&rpt_tim);
if (rpt_conf.enabled) {
os_timer_setfn(&rpt_tim, rpt_tim_cb, NULL);
os_timer_arm(&rpt_tim, (int)(rpt_conf.interval*1000), 1);
}
}
/** Fix unterminated strings, add magic, etc.. */
static void normalize_rpt_conf(void)
{
// terminate strings
rpt_conf.feed[sizeof(rpt_conf.feed)-1] = 0;
rpt_conf.key[sizeof(rpt_conf.key)-1] = 0;
// set magic
rpt_conf.magic = RPT_CONF_MAGIC;
}
/** Save reporting config to flash */
void reporting_save(void)
{
normalize_rpt_conf(); // fix weirdness
system_param_save_with_protect(0x3D, &rpt_conf, sizeof(ReportingCfg));
// start timer for the new interval time
set_timer();
}
/** Load the reporting config from flash */
void reporting_load(void)
{
system_param_load(0x3D, 0, &rpt_conf, sizeof(ReportingCfg));
if (rpt_conf.magic != RPT_CONF_MAGIC) {
// invalid config, zero out
memset(&rpt_conf, 0, sizeof(ReportingCfg));
rpt_conf.magic = RPT_CONF_MAGIC;
// save fixed
reporting_save();
}
set_timer();
}
void compare_ref_cb(SBMP_Endpoint *ep, SBMP_Datagram *dg, void **obj)
{
(void)obj;
sbmp_ep_remove_listener(ep, dg->session);
PayloadParser pp = pp_start(dg->payload, dg->length);
rpt_result.deviation = pp_float(&pp);
rpt_result.rms = pp_float(&pp);
}
/** Immediately send report to xively / thingspeak */
void reporting_send_now(void)
{
uint16_t sesn;
sbmp_ep_send_message(dlnk_ep, DG_REQUEST_COMPARE_REF, NULL, 0, &sesn, NULL);
sbmp_ep_add_listener(dlnk_ep, sesn, compare_ref_cb, NULL);
// poll & wait for response
const int timeout = 500;
for (uint32_t i = 0; i < timeout*100; i++) {
uart_poll(); // can stop measure & start first chunk, if rx offer
// check for closed connection - aborted by peer?
if (meas_is_closed()) {
error("Session closed by peer, readout failed.");
return false; // assume already cleaned up
}
if (meas_chunk_ready()) {
// yay!!
return true;
}
os_delay_us(10);
system_soft_wdt_feed(); // Feed the dog, or it'll bite.
}
}

@ -0,0 +1,45 @@
#ifndef REPORTING_H
#define REPORTING_H
#include <esp8266.h>
typedef struct {
// 0
bool enabled : 4;
// 4
uint32_t interval;
// 8
enum {
RPT_XIVELY,
RPT_THINGSPEAK
} service : 4;
// 12
char feed[64];
// 76
char key[64];
// 80
uint32_t magic;
} ReportingCfg;
/** Comapre result is stored here */
typedef struct {
bool ready : 4;
float deviation;
float rms;
} ReportingResult;
extern ReportingResult rpt_result;
/** Reporting config struct */
extern ReportingCfg rpt_conf;
/** Save reporting config to flash */
void reporting_save(void);
/** Load the reporting config from flash */
void reporting_load(void);
/** Immediately send report to xively / thingspeak */
void reporting_send_now(void);
#endif // REPORTING_H

@ -13,6 +13,7 @@
#include "page_status.h" #include "page_status.h"
#include "page_waveform.h" #include "page_waveform.h"
#include "page_about.h" #include "page_about.h"
#include "page_monitoring.h"
#include "cgi_reset.h" #include "cgi_reset.h"
#include "cgi_ping.h" #include "cgi_ping.h"
@ -51,6 +52,7 @@ HttpdBuiltInUrl builtInUrls[] = {
ROUTE_TPL_FILE("/", tplSystemStatus, "/pages/status.tpl"), ROUTE_TPL_FILE("/", tplSystemStatus, "/pages/status.tpl"),
ROUTE_TPL_FILE("/status", tplSystemStatus, "/pages/status.tpl"), ROUTE_TPL_FILE("/status", tplSystemStatus, "/pages/status.tpl"),
ROUTE_TPL_FILE("/about", tplAbout, "/pages/about.tpl"), ROUTE_TPL_FILE("/about", tplAbout, "/pages/about.tpl"),
ROUTE_TPL_FILE("/monitoring", tplMonitoring, "/pages/monitoring.tpl"),
ROUTE_FILE("/waveform", "/pages/wfm.html"), // static file, html -> can use gzip ROUTE_FILE("/waveform", "/pages/wfm.html"), // static file, html -> can use gzip
ROUTE_FILE("/fft", "/pages/fft.html"), // static file, html -> can use gzip ROUTE_FILE("/fft", "/pages/fft.html"), // static file, html -> can use gzip
ROUTE_FILE("/spectrogram", "/pages/sgm.html"), // static file, html -> can use gzip ROUTE_FILE("/spectrogram", "/pages/sgm.html"), // static file, html -> can use gzip

Loading…
Cancel
Save