parent
91025a4cc7
commit
daf3d6dee4
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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 & 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 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%><!-- |
||||
--> <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%"><!-- |
||||
--> seconds |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<th>Service:</th> |
||||
<td> |
||||
<input type="radio" name="rep-service" value="xively" id="rep-svc-xv" %repSvcCheckXv%> <label for="rep-svc-xv">Xively</label> |
||||
<input type="radio" name="rep-service" value="thingspeak" id="rep-svc-ts" %repSvcCheckTs%> <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> </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> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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
|
Loading…
Reference in new issue