Browse Source

much improved status page, reduced array sizes in wifi cgi

master
Ondřej Hruška 6 years ago
parent
commit
5bb7a303b3
  1. 6
      _web-build_do.sh
  2. 16
      esp_meas.pro
  3. 2
      esp_meas.pro.user
  4. 2
      flash.sh
  5. 2
      html/css/app.css
  6. 4
      html/js/all.js
  7. 7
      html/json/status.tpl
  8. 82
      html/pages/status.tpl
  9. 4
      html/pages/waveform.html
  10. 6
      html/pages/wifi.tpl
  11. 8
      html_src/_start.php
  12. 2
      html_src/css/app.css
  13. 2
      html_src/css/app.css.map
  14. 6
      html_src/gulpfile.js
  15. 78
      html_src/home.php
  16. 5
      html_src/index.php
  17. 58
      html_src/js-src/page_status.js
  18. 2
      html_src/js-src/page_waveform.js
  19. 19
      html_src/js-src/page_wifi.js
  20. 4
      html_src/js/all.js
  21. 2
      html_src/js/all.js.map
  22. 0
      html_src/page_layout.php
  23. 95
      html_src/page_status.php
  24. 2
      html_src/page_waveform.php
  25. 4
      html_src/page_wifi.php
  26. 4
      html_src/sass/pages/_home.scss
  27. 2
      libesphttpd/include/esp8266.h
  28. 0
      libesphttpd/include/espmissingprotos.h
  29. 8
      libesphttpd/include/platform.h
  30. 16
      libesphttpd/util/cgiwifi.c
  31. 9
      user/cgi.h
  32. 72
      user/page_home.c
  33. 159
      user/page_status.c
  34. 2
      user/page_status.h
  35. 101
      user/page_waveform.c
  36. 8
      user/page_waveform.h
  37. 24
      user/routes.c
  38. 42
      user/utils.c
  39. 10
      user/utils.h

6
_web-build_do.sh

@ -21,6 +21,6 @@ find "$BLDDIR" -name "*.map" -delete
mkdir -p "$BLDDIR/pages"
php "$SRCDIR/home.php" > "$BLDDIR/pages/home.tpl"
php "$SRCDIR/wifi.php" > "$BLDDIR/pages/wifi.tpl"
php "$SRCDIR/waveform.php" > "$BLDDIR/pages/wfm.html" # no substitutions, .html allows to gzip it.
php "$SRCDIR/page_status.php" > "$BLDDIR/pages/status.tpl"
php "$SRCDIR/page_wifi.php" > "$BLDDIR/pages/wifi.tpl"
php "$SRCDIR/page_waveform.php" > "$BLDDIR/pages/waveform.html" # no substitutions, .html allows to gzip it.

16
esp_meas.pro

@ -41,7 +41,6 @@ SOURCES += \
libesphttpd/util/cgiwebsocket.c \
libesphttpd/util/cgiwifi.c \
user/cgi-test.c \
user/cgi.c \
user/io.c \
user/user_main.c \
user/uart_driver.c \
@ -56,9 +55,11 @@ SOURCES += \
user/uptime.c \
sbmp/library/payload_parser.c \
user/sampling.c \
user/page_home.c \
user/ftoa.c \
user/routes.c
user/routes.c \
user/page_status.c \
user/page_waveform.c \
user/utils.c
HEADERS += \
include/uart_hw.h \
@ -74,7 +75,6 @@ HEADERS += \
libesphttpd/include/cgiwifi.h \
libesphttpd/include/esp8266.h \
libesphttpd/include/espfs.h \
libesphttpd/include/espmissingincludes.h \
libesphttpd/include/httpd.h \
libesphttpd/include/httpdespfs.h \
libesphttpd/include/platform.h \
@ -87,7 +87,6 @@ HEADERS += \
libesphttpd/lib/heatshrink/heatshrink_decoder.h \
libesphttpd/lib/heatshrink/heatshrink_encoder.h \
user/cgi-test.h \
user/cgi.h \
user/io.h \
user/uart_register.h \
esp_iot_sdk_v1.5.2/include/json/json.h \
@ -134,11 +133,14 @@ HEADERS += \
user/uptime.h \
sbmp/library/payload_parser.h \
user/sampling.h \
user/page_home.h \
user/sbmp_config.h \
sbmp/library/sbmp_config.example.h \
user/ftoa.h \
user/routes.h
user/routes.h \
user/page_status.h \
user/page_waveform.h \
libesphttpd/include/espmissingprotos.h \
user/utils.h
DISTFILES += \
style.astylerc \

2
esp_meas.pro.user

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.0, 2016-03-28T04:35:00. -->
<!-- Written by QtCreator 3.6.0, 2016-03-28T13:51:48. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

2
flash.sh

@ -1,3 +1,3 @@
#!/bin/bash
xterm -title "ESP html build" -e "source $HOME/.bashrc && make flash -B -j4"
xterm -title "ESP flash" -e "source $HOME/.bashrc && make flash -B -j4"

2
html/css/app.css

File diff suppressed because one or more lines are too long

4
html/js/all.js

File diff suppressed because one or more lines are too long

7
html/json/status.tpl

@ -0,0 +1,7 @@
{
"uptime": "%uptime%",
"heap": %heap%,
"wifiMode": "%wifiMode%",
"sta": %staInfo%,
"ap": %apInfo%
}

82
html/pages/home.tpl → html/pages/status.tpl

@ -16,7 +16,7 @@
<div id="outer">
<nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current analyzer</div>
<a href="/" 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="/transient">Power-on transient</a><a href="/about">Credits &amp; About</a></nav>
<a href="/" class="selected">Home</a><a href="/wifi">WiFi config</a><a href="/waveform">Waveform</a></nav>
<div id="content">
<h1>System Status</h1>
@ -27,71 +27,87 @@
<tbody>
<tr>
<th>Uptime:</th>
<td>%uptime%</td>
<td id="uptime">%uptime%</td>
</tr>
<tr>
<th>Free heap:</th>
<td>%heap% bytes</td>
<td id="heap">%heap%</td>
</tr>
</tbody>
</table>
</div>
<div class="Box">
<h2>Wireless</h2>
<h2>WiFi</h2>
<table>
<tbody>
<tr>
<th>WiFi mode:</th>
<td>%wifiMode%</td>
<td id="wmode">%wifiMode%</td>
</tr>
<tr class="sta-only">
</tbody>
</table>
</div>
<!-- WiFi info is read & updated using AJAX -->
<div class="Box sta-only" style="display:none">
<h2>WiFi Station</h2>
<table>
<tbody>
<tr>
<th>SSID:</th>
<td>%staSSID%</td>
</tr>
<tr class="sta-only">
<th>RSSI:</th>
<td><span id="rssi-perc"></span>, <span id="rssi-dbm"></span></td>
<td id="staSSID"></td>
</tr>
<tr>
<th>Client MAC:</th>
<td>%staMAC%</td>
<th>RSSI:</th>
<td>
<span id="staRSSIperc"></span>,
<span id="staRSSI"></span>
</td>
</tr>
<tr>
<th>AP MAC:</th>
<td>%apMAC%</td>
<th>MAC:</th>
<td id="staMAC"></td>
</tr>
</tbody>
</table>
</div>
<div class="Box">
<h2>Hardware</h2>
<div class="Box ap-only" style="display:none">
<h2>WiFi AP</h2>
<table>
<tbody>
<tr>
<th>ESP8266 S/N:</th>
<td>%chipID%</td>
<th>SSID:</th>
<td id="apSSID"></td>
</tr>
<tr>
<th>Hidden:</th>
<td id="apHidden"></td>
</tr>
<tr>
<th>Auth. mode:</th>
<td id="apAuth"></td>
</tr>
<tr class="ap-auth-only">
<th>Password:</th>
<td id="apPwd"></td>
</tr>
<tr>
<th>Channel:</th>
<td id="apChan"></td>
</tr>
<tr>
<th>MAC:</th>
<td id="apMAC"></td>
</tr>
</tbody>
</table>
</div>
<script>
var wifiMode = '%wifiMode%';
var staRSSI = '%staRSSI%';
$().ready(function() {
if (wifiMode == 'SoftAP') {
$('.sta-only').hide();
} else {
$('#rssi-perc').html(rssiPerc(staRSSI));
$('#rssi-dbm').html(staRSSI);
}
// TODO use json + ajax instead
setTimeout(function(){location.reload()}, 10000);
});
$().ready(page_status.init);
</script>
</div>

4
html/pages/wfm.html → html/pages/waveform.html

@ -16,7 +16,7 @@
<div id="outer">
<nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current analyzer</div>
<a href="/">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="/transient">Power-on transient</a><a href="/about">Credits &amp; About</a></nav>
<a href="/">Home</a><a href="/wifi">WiFi config</a><a href="/waveform" class="selected">Waveform</a></nav>
<div id="content">
<h1>Waveform</h1>
@ -32,7 +32,7 @@
</div>
<script>
$().ready(wfm.init());
$().ready(page_waveform.init());
</script>
</div>

6
html/pages/wifi.tpl

@ -16,7 +16,7 @@
<div id="outer">
<nav id="menu">
<div id="brand" onclick="$('#menu').toggleClass('expanded')">Current analyzer</div>
<a href="/">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="/transient">Power-on transient</a><a href="/about">Credits &amp; About</a></nav>
<a href="/">Home</a><a href="/wifi" class="selected">WiFi config</a><a href="/waveform">Waveform</a></nav>
<div id="content">
<h1>Wireless Setup</h1>
@ -44,8 +44,8 @@
<script>
// Current SSID
wifi.current = '%currSsid%';
$().ready(wifi.init);
page_wifi.current = '%currSsid%';
$().ready(page_wifi.init);
</script>
<div class="Modal hidden" id="psk-modal">

8
html_src/_start.php

@ -4,10 +4,10 @@ $menu = [
'home' => [ '/', 'Home' ],
'wifi' => [ '/wifi', 'WiFi config' ],
'waveform' => [ '/waveform', 'Waveform' ],
'fft' => [ '/fft', 'FFT' ],
'spectrogram' => [ '/spectrogram', 'Spectrogram' ],
'transient' => [ '/transient', 'Power-on transient' ],
'about' => [ '/about', 'Credits & About' ],
// 'fft' => [ '/fft', 'FFT' ],
// 'spectrogram' => [ '/spectrogram', 'Spectrogram' ],
// 'transient' => [ '/transient', 'Power-on transient' ],
// 'about' => [ '/about', 'Credits & About' ],
];
$appname = 'Current analyzer';

2
html_src/css/app.css

File diff suppressed because one or more lines are too long

2
html_src/css/app.css.map

File diff suppressed because one or more lines are too long

6
html_src/gulpfile.js

@ -5,6 +5,7 @@ elixir.config.css.autoprefix.options.browsers = ["> 2.5% in CZ"];
elixir.config.css.autoprefix.options.flexbox = "no-2009";
elixir.config.css.cssnano.pluginOptions.discardComments = {removeAll: true};
elixir.config.css.cssnano.pluginOptions.colormin = false;
elixir.config.js.uglify.options.compress.drop_console = false;
// var info = autoprefixer(elixir.config.css.autoprefix).info();
// console.log(info);
@ -26,7 +27,8 @@ elixir(function (mix) {
'js-src/utils.js',
'js-src/modal.js',
'js-src/app.js',
'js-src/wifi.js',
'js-src/waveform.js',
'js-src/page_wifi.js',
'js-src/page_waveform.js',
'js-src/page_status.js',
], 'js/all.js');
});

78
html_src/home.php

@ -1,78 +0,0 @@
<?php $page='home'; include "_start.php"; ?>
<h1>System Status</h1>
<div class="Box">
<h2>Runtime</h2>
<table>
<tbody>
<tr>
<th>Uptime:</th>
<td>%uptime%</td>
</tr>
<tr>
<th>Free heap:</th>
<td>%heap% bytes</td>
</tr>
</tbody>
</table>
</div>
<div class="Box">
<h2>Wireless</h2>
<table>
<tbody>
<tr>
<th>WiFi mode:</th>
<td>%wifiMode%</td>
</tr>
<tr class="sta-only">
<th>SSID:</th>
<td>%staSSID%</td>
</tr>
<tr class="sta-only">
<th>RSSI:</th>
<td><span id="rssi-perc"></span>, <span id="rssi-dbm"></span></td>
</tr>
<tr>
<th>Client MAC:</th>
<td>%staMAC%</td>
</tr>
<tr>
<th>AP MAC:</th>
<td>%apMAC%</td>
</tr>
</tbody>
</table>
</div>
<div class="Box">
<h2>Hardware</h2>
<table>
<tbody>
<tr>
<th>ESP8266 S/N:</th>
<td>%chipID%</td>
</tr>
</tbody>
</table>
</div>
<script>
var wifiMode = '%wifiMode%';
var staRSSI = '%staRSSI%';
$().ready(function() {
if (wifiMode == 'SoftAP') {
$('.sta-only').hide();
} else {
$('#rssi-perc').html(rssiPerc(staRSSI));
$('#rssi-dbm').html(staRSSI);
}
// TODO use json + ajax instead
setTimeout(function(){location.reload()}, 10000);
});
</script>
<?php include "_end.php"; ?>

5
html_src/index.php

@ -1,5 +0,0 @@
<?php $page='fft'; include "_start.php"; ?>
Home page.
<?php include "_end.php"; ?>

58
html_src/js-src/page_status.js

@ -0,0 +1,58 @@
var page_status = (function() {
var st = {};
function onUpdate(resp, status) {
if (status != 200) {
// bad response
console.error('Update failed.');
} else {
try {
// OK
var j = JSON.parse(resp);
$('.sta-only').toggle(j.sta);
$('.ap-only').toggle(j.ap);
$('#uptime').html(j.uptime);
$('#heap').html(j.heap + " bytes");
$('#wmode').html(j.wifiMode);
if (j.sta) {
$('#staSSID').html(j.sta.SSID);
$('#staRSSIperc').html(j.sta.RSSIperc);
$('#staRSSI').html(j.sta.RSSI);
$('#staMAC').html(j.sta.MAC);
}
if (j.ap) {
$('#apSSID').html(j.ap.SSID);
$('#apHidden').html(j.ap.hidden ? "Yes" : "No");
$('#apAuth').html(j.ap.auth);
// hide the password row if auth is Open
$('.ap-auth-only').toggle(j.ap.auth != 'Open');
$('#apPwd').html(j.ap.pwd);
$('#apChan').html(j.ap.chan);
$('#apMAC').html(j.ap.MAC);
}
// chip ID & macs don't change
} catch(e) {
console.error(e);
}
}
setTimeout(requestUpdate, 10000);
}
function requestUpdate() {
$().get('/api/status.json', onUpdate, true, true);
}
st.init = function() {
requestUpdate();
setTimeout(requestUpdate, 10000);
};
return st;
})();

2
html_src/js-src/waveform.js → html_src/js-src/page_waveform.js

@ -1,4 +1,4 @@
var wfm = (function () {
var page_waveform = (function () {
var wfm = {};
function buildChart(samples, xlabel, ylabel) {

19
html_src/js-src/wifi.js → html_src/js-src/page_wifi.js

@ -1,5 +1,5 @@
/** Wifi page */
var wifi = (function () {
var page_wifi = (function () {
var wifi = {};
var authStr = ['Open', 'WEP', 'WPA', 'WPA2', 'WPA/WPA2'];
@ -91,27 +91,10 @@ var wifi = (function () {
// "APs": [
// {"essid": "Chlivek", "bssid": "88:f7:c7:52:b3:99", "rssi": "204", "enc": "4", "channel": "1"},
// {"essid": "TyNikdy", "bssid": "5c:f4:ab:0d:f1:1b", "rssi": "164", "enc": "3", "channel": "1"},
// {"essid": "UPC5616805", "bssid": "08:95:2a:0c:84:3f", "rssi": "164", "enc": "4", "channel": "1"},
// {"essid": "Sitovina", "bssid": "20:cf:30:98:cb:3a", "rssi": "166", "enc": "3", "channel": "1"},
// {"essid": "Tramp", "bssid": "c4:e9:84:6f:6c:e0", "rssi": "170", "enc": "3", "channel": "2"},
// {"essid": "KV2", "bssid": "4c:5e:0c:2c:84:9b", "rssi": "172", "enc": "3", "channel": "3"},
// {"essid": "UPC373123", "bssid": "e8:40:f2:ae:0e:f4", "rssi": "164", "enc": "3", "channel": "1"},
// {"essid": "www.podoli.org prazak", "bssid": "00:00:00:00:00:00", "rssi": "165", "enc": "0", "channel": "4"},
// {"essid": "Medvjedov", "bssid": "00:00:00:00:00:00", "rssi": "181", "enc": "4", "channel": "6"},
// {"essid": "MARIAN-PC", "bssid": "f8:d1:11:af:d7:72", "rssi": "175", "enc": "3", "channel": "6"},
// {"essid": "UPC3226244", "bssid": "64:7c:34:9a:6f:7c", "rssi": "169", "enc": "4", "channel": "6"},
// {"essid": "molly", "bssid": "00:00:00:00:00:00", "rssi": "168", "enc": "3", "channel": "7"},
// {"essid": "UPC2607759", "bssid": "88:f7:c7:4e:c1:b2", "rssi": "164", "enc": "4", "channel": "8"},
// {"essid": "blondyna", "bssid": "98:fc:11:bd:0f:b8", "rssi": "166", "enc": "4", "channel": "9"},
// {"essid": "UPC246587811", "bssid": "80:f5:03:20:6c:85", "rssi": "171", "enc": "3", "channel": "11"},
// {"essid": "UPC930648", "bssid": "4c:72:b9:50:6d:38", "rssi": "167", "enc": "3", "channel": "11"},
// {"essid": "PRAHA4.NET-R21-2", "bssid": "00:00:00:00:00:00", "rssi": "173", "enc": "0", "channel": "12"},
// {"essid": "Internet_B0", "bssid": "5c:f4:ab:11:3b:b3", "rssi": "166", "enc": "3", "channel": "13"}
// ]
// }
//};
//onScan(ap_json, 200);
scanAPs();
};

4
html_src/js/all.js

File diff suppressed because one or more lines are too long

2
html_src/js/all.js.map

File diff suppressed because one or more lines are too long

0
html_src/layout.php → html_src/page_layout.php

95
html_src/page_status.php

@ -0,0 +1,95 @@
<?php $page = 'home';
include "_start.php"; ?>
<h1>System Status</h1>
<div class="Box">
<h2>Runtime</h2>
<table>
<tbody>
<tr>
<th>Uptime:</th>
<td id="uptime">%uptime%</td>
</tr>
<tr>
<th>Free heap:</th>
<td id="heap">%heap%</td>
</tr>
</tbody>
</table>
</div>
<div class="Box">
<h2>WiFi</h2>
<table>
<tbody>
<tr>
<th>WiFi mode:</th>
<td id="wmode">%wifiMode%</td>
</tr>
</tbody>
</table>
</div>
<!-- WiFi info is read & updated using AJAX -->
<div class="Box sta-only" style="display:none">
<h2>WiFi Station</h2>
<table>
<tbody>
<tr>
<th>SSID:</th>
<td id="staSSID"></td>
</tr>
<tr>
<th>RSSI:</th>
<td>
<span id="staRSSIperc"></span>,
<span id="staRSSI"></span>
</td>
</tr>
<tr>
<th>MAC:</th>
<td id="staMAC"></td>
</tr>
</tbody>
</table>
</div>
<div class="Box ap-only" style="display:none">
<h2>WiFi AP</h2>
<table>
<tbody>
<tr>
<th>SSID:</th>
<td id="apSSID"></td>
</tr>
<tr>
<th>Hidden:</th>
<td id="apHidden"></td>
</tr>
<tr>
<th>Auth. mode:</th>
<td id="apAuth"></td>
</tr>
<tr class="ap-auth-only">
<th>Password:</th>
<td id="apPwd"></td>
</tr>
<tr>
<th>Channel:</th>
<td id="apChan"></td>
</tr>
<tr>
<th>MAC:</th>
<td id="apMAC"></td>
</tr>
</tbody>
</table>
</div>
<script>
$().ready(page_status.init);
</script>
<?php include "_end.php"; ?>

2
html_src/waveform.php → html_src/page_waveform.php

@ -14,7 +14,7 @@ include "_start.php"; ?>
</div>
<script>
$().ready(wfm.init());
$().ready(page_waveform.init());
</script>
<?php include "_end.php"; ?>

4
html_src/wifi.php → html_src/page_wifi.php

@ -26,8 +26,8 @@ include "_start.php"; ?>
<script>
// Current SSID
wifi.current = '%currSsid%';
$().ready(wifi.init);
page_wifi.current = '%currSsid%';
$().ready(page_wifi.init);
</script>
<div class="Modal hidden" id="psk-modal">

4
html_src/sass/pages/_home.scss

@ -1,10 +1,10 @@
.page-home #rssi-perc:after {
.page-home #staRSSIperc:after {
padding-left: dist(-4);
content: '%';
font-size: fsize(-1);
}
.page-home #rssi-dbm:after {
.page-home #staRSSI:after {
padding-left: dist(-4);
content: 'dBm';
font-size: fsize(-1);

2
libesphttpd/include/esp8266.h

@ -35,7 +35,7 @@
#include "platform.h"
#include "espmissingincludes.h"
#include "espmissingprotos.h"
#include "esp_sdk_ver.h"
#include "logging.h"

0
libesphttpd/include/espmissingincludes.h → libesphttpd/include/espmissingprotos.h

8
libesphttpd/include/platform.h

@ -1,6 +1,10 @@
#ifndef PLATFORM_H
#define PLATFORM_H
#include <osapi.h>
#include "espmissingprotos.h"
#ifdef FREERTOS
//#include "esp_timer.h"
typedef struct RtosConnType RtosConnType;
@ -16,6 +20,10 @@ typedef RtosConnType* ConnTypePtr;
#define strncpy(a, b, c) os_strncpy(a, b, c)
#define strcmp(a, b) os_strcmp(a, b)
#define strncmp(a, b, c) os_strncmp(a, b, c)
#define streq(a, b) (strcmp(a, b) == 0)
#define strneq(a, b, n) (strncmp(a, b, n) == 0)
#define malloc(x) os_malloc(x)
#define free(x) os_free(x)
#define memset(x, a, b) os_memset(x, a, b)

16
libesphttpd/util/cgiwifi.c

@ -15,6 +15,8 @@ Cgi/template routines for the /wifi url.
#include <esp8266.h>
#include "cgiwifi.h"
#include "utils.h" // ADDED
//Enable this to disallow any changes in AP settings
//#define DEMO_MODE
@ -113,7 +115,7 @@ static void ICACHE_FLASH_ATTR wifiStartScan() {
int ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData) {
int pos=(int)connData->cgiData;
int len;
char buff[1024];
char buff[256];
if (!cgiWifiAps.scanInProgress && pos!=0) {
//Fill in json code for an access point
@ -238,7 +240,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
//given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
int len;
char buff[1024];
char buff[64];
if (connData->conn==NULL) {
//Connection aborted. Clean up.
@ -258,7 +260,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
}
int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
char buff[1024];
char buff[256];
int len;
struct ip_info info;
int st=wifi_station_get_connect_status();
@ -290,7 +292,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
//Template code for the WLAN page.
int ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) {
char buff[1024];
char buff[256];
int x;
static struct station_config stconf;
if (token==NULL) return HTTPD_CGI_DONE;
@ -299,12 +301,10 @@ int ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg)
strcpy(buff, "Unknown");
if (strcmp(token, "WiFiMode")==0) {
x=wifi_get_opmode();
if (x==1) strcpy(buff, "Client");
if (x==2) strcpy(buff, "SoftAP");
if (x==3) strcpy(buff, "STA+AP");
strcpy(buff, opmode2str(x));
} else if (strcmp(token, "currSsid")==0) {
strcpy(buff, (char*)stconf.ssid);
// } else if (strcmp(token, "WiFiPasswd")==0) {
// } else if (strcmp(token, "WiFiPasswd")==0) { // don't expose password
// strcpy(buff, (char*)stconf.password);
} else if (strcmp(token, "WiFiapwarn")==0) {
x=wifi_get_opmode();

9
user/cgi.h

@ -1,9 +0,0 @@
#ifndef CGI_H
#define CGI_H
#include <esp8266.h>
#include "httpd.h"
int tplReadSamplesJSON(HttpdConnData *connData, char *token, void **arg);
#endif

72
user/page_home.c

@ -1,72 +0,0 @@
#include <esp8266.h>
#include <httpd.h>
#include "page_home.h"
#include "uptime.h"
/** System Status page */
int FLASH_FN tplHome(HttpdConnData *connData, char *token, void **arg)
{
// arg is unused
(void)arg;
struct station_config stconf;
char buff[128];
u8 mac[6];
// empty string if no token matches
buff[0] = 0;
if (token == NULL) return HTTPD_CGI_DONE;
if (strcmp(token, "uptime") == 0) {
// Uptime
uptime_str(buff);
} else if (strcmp(token, "heap") == 0) {
// Free heap
sprintf(buff, "%u", system_get_free_heap_size());
} else if (strcmp(token, "wifiMode") == 0) {
// WiFi mode
switch (wifi_get_opmode()) {
case STATION_MODE: strcpy(buff, "Client"); break;
case SOFTAP_MODE: strcpy(buff, "SoftAP"); break;
case STATIONAP_MODE: strcpy(buff, "STA+AP"); break;
default: strcpy(buff, "Unknown");
}
} else if (strcmp(token, "staSSID") == 0) {
// Station SSID (if in station mode)
int opmode = wifi_get_opmode();
if (opmode != STATION_MODE && opmode != STATIONAP_MODE) {
strcpy(buff, "N/A"); // no SSID in AP-only mode
} else {
wifi_station_get_config(&stconf);
strcpy(buff, (char*)stconf.ssid);
}
} else if (strcmp(token, "staRSSI") == 0) {
// Signal strength if in Station mode
int rssi = wifi_station_get_rssi();
sprintf(buff, "%d", rssi);
} else if (strcmp(token, "staMAC") == 0) {
// Station MAC addr
wifi_get_macaddr(STATION_IF, mac);
sprintf(buff, MACSTR, MAC2STR(mac));
} else if (strcmp(token, "apMAC") == 0) {
// SoftAP MAC addr
wifi_get_macaddr(SOFTAP_IF, mac);
sprintf(buff, MACSTR, MAC2STR(mac));
} else if (strcmp(token, "chipID") == 0) {
// Chip serial number
sprintf(buff, "%08x", system_get_chip_id());
}
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}

159
user/page_status.c

@ -0,0 +1,159 @@
#include <esp8266.h>
#include <httpd.h>
#include "page_status.h"
#include "uptime.h"
#include "utils.h"
/** System Status page */
int FLASH_FN tplSystemStatus(HttpdConnData *connData, char *token, void **arg)
{
// arg is unused
(void)arg;
struct station_config stconf;
struct softap_config apconf;
char buff[300];
u8 mac[6];
int rssi;
// empty string if no token matches
buff[0] = 0;
if (token == NULL) return HTTPD_CGI_DONE;
// {
// "uptime": "00:01:1200:01:12",
// "heap": 3391233912,
// "wifiMode": "ClientClient",
// "sta": null,
// "ap": {"SSID": "ESP_D58987", "pwd": "", "MAC": "1a:fe:34:d5:89:87", "chan": 1, "hidden": false, "auth": Open, }
// }
int opmode = wifi_get_opmode();
bool is_sta = (opmode == STATION_MODE || opmode == STATIONAP_MODE);
bool is_ap = (opmode == SOFTAP_MODE || opmode == STATIONAP_MODE);
if (streq(token, "uptime")) {
// Uptime
uptime_str(buff);
} else if (streq(token, "heap")) {
// Free heap
sprintf(buff, "%u", system_get_free_heap_size());
} else if (streq(token, "wifiMode")) {
// WiFi mode
strcpy(buff, opmode2str(opmode));
} else if (streq(token, "staInfo")) {
if (!is_sta) {
strcpy(buff, "null");
} else {
// AP info
wifi_station_get_config(&stconf);
wifi_get_macaddr(STATION_IF, mac);
rssi = wifi_station_get_rssi();
sprintf(buff,
"{"
"\"SSID\": \"%s\", "
"\"RSSI\": %d, "
"\"RSSIperc\": %d, "
"\"MAC\": \""MACSTR"\""
"}",
stconf.ssid,
rssi,
rssi2perc(rssi),
MAC2STR(mac)
);
}
} else if (streq(token, "apInfo")) {
if (!is_ap) {
strcpy(buff, "null");
} else {
wifi_softap_get_config(&apconf);
wifi_get_macaddr(SOFTAP_IF, mac);
// AP info
sprintf(buff,
"{"
"\"SSID\": \"%s\", "
"\"pwd\": \"%s\", "
"\"MAC\": \""MACSTR"\", "
"\"chan\": %d, "
"\"hidden\": %s, "
"\"auth\": \"%s\""
"}",
apconf.ssid,
apconf.password,
MAC2STR(mac),
apconf.channel,
apconf.ssid_hidden ? "true" : "false",
auth2str(apconf.authmode)
);
}
/*} else if (streq(token, "staSSID")) {
// Station SSID (if in station mode)
if (!is_sta) {
strcpy(buff, "N/A");
} else {
strcpy(buff, (char*)stconf.ssid);
}
} else if (streq(token, "staRSSI")) {
// Signal strength if in Station mode
if (!is_sta) {
strcpy(buff, "0");
} else {
rssi = wifi_station_get_rssi();
sprintf(buff, "%d", rssi);
}
} else if (streq(token, "staRSSIperc")) {
// Signal strength if in Station mode
if (!is_sta) {
strcpy(buff, "0");
} else {
rssi = wifi_station_get_rssi();
sprintf(buff, "%d", rssi2perc(rssi));
}
} else if (streq(token, "staMAC")) {
// Station MAC addr
wifi_get_macaddr(STATION_IF, mac);
sprintf(buff, MACSTR, MAC2STR(mac));
} else if (streq(token, "apMAC")) {
// SoftAP MAC addr
wifi_get_macaddr(SOFTAP_IF, mac);
sprintf(buff, MACSTR, MAC2STR(mac));
} else if (streq(token, "chipID")) {
// Chip serial number
sprintf(buff, "%08x", system_get_chip_id());*/
}
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
/*
"sta": {
"SSID": "%staSSID%",
"RSSI": %staRSSI%,
"RSSIperc": %staRSSIperc%,
"MAC": "%staMAC%"
},
"ap": {
"MAC": "%apMAC%"
},
*/

2
user/page_home.h → user/page_status.h

@ -3,6 +3,6 @@
#include <httpd.h>
int tplHome(HttpdConnData *connData, char *token, void **arg);
int tplSystemStatus(HttpdConnData *connData, char *token, void **arg);
#endif // PAGE_HOME_H

101
user/cgi.c → user/page_waveform.c

@ -1,25 +1,10 @@
/*
Some random cgi routines. Used in the LED example and the page that returns the entire
flash as a binary. Also handles the hit counter on the main page.
*/
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/
#include <esp8266.h>
#include "cgi.h"
#include "uptime.h"
#include "datalink.h"
#include <httpd.h>
#include "page_waveform.h"
#include "sampling.h"
#include "serial.h"
#include "payload_parser.h"
// -------------------------------------------------------------------------------
@ -32,7 +17,7 @@ typedef struct {
} tplReadSamplesJSON_state;
int FLASH_FN tplReadSamplesJSON(HttpdConnData *connData, char *token, void **arg)
int FLASH_FN tplWaveformJSON(HttpdConnData *connData, char *token, void **arg)
{
char buff20[20];
@ -127,79 +112,3 @@ int FLASH_FN tplReadSamplesJSON(HttpdConnData *connData, char *token, void **arg
// Example of multi-pass generation of a html file
/*
// better to put it in the fs...
int FLASH_FN cgiRandomNumbers(HttpdConnData *connData) {
RandomNumberState *rns=connData->cgiData;
char buff[128];
if (connData->conn == NULL) {
//Connection aborted. Clean up.
if (rns != NULL) free(rns);
return HTTPD_CGI_DONE;
}
if (rns == NULL) {
//First call to this cgi. Open the file so we can read it.
rns=(RandomNumberState *)malloc(sizeof(RandomNumberState));
connData->cgiData=rns;
// parse count
uint32_t count = 1;
int len = httpdFindArg(connData->getArgs, "count", buff, sizeof(buff));
if (len==-1) {
// no such get arg
} else {
count = (uint32_t)atoi(buff);
}
rns->count_remain = count;
printf("User wants %d numbers.", count);
httpdStartResponse(connData, 200);
httpdHeader(connData, "Content-Type", "text/html");
httpdEndHeaders(connData);
// start the page
httpdSend(connData, "<!DOCTYPE html>"
"<html>"
"<head>"
" <title>Generated page.</title>"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">"
"</head>"
"<body>"
"<div id=\"main\">"
"<h1>Random numbers:</h1>"
"<ul>", -1);
return HTTPD_CGI_MORE;
}
// send end of the page
if (rns->count_remain == 0) {
httpdSend(connData, "</ul></body></html>", -1);
free(rns);
return HTTPD_CGI_DONE;
}
// print chunk of data
for (int i = 0; i < 100; i++) {
os_sprintf(buff, "<li>%lu\n", os_random());
httpdSend(connData, buff, -1);
if (--rns->count_remain == 0) {
break;
}
}
return HTTPD_CGI_MORE;
}
*/

8
user/page_waveform.h

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

24
user/routes.c

@ -10,9 +10,8 @@
//#include "cgiwebsocket.h"
// user files
#include "cgi.h"
#include "page_home.h"
#include "sampling.h"
#include "page_status.h"
#include "page_waveform.h"
#define WIFI_PROTECT 0
@ -35,10 +34,19 @@ static int FLASH_FN myPassFn(HttpdConnData *connData, int no, char *user, int us
HttpdBuiltInUrl builtInUrls[] = {
ROUTE_CGI_ARG("*", cgiRedirectApClientToHostname, "esp8266.nonet"), // redirect func for the captive portal
// ! Templates in the JSON folder will have application/json content type !
// otherwise they're encoded the same like the HTML ones -> no heatshrink, no gzip
// --- UI pages ---
ROUTE_TPL_FILE("/", tplHome, "/pages/home.tpl"),
ROUTE_FILE("/waveform", "/pages/wfm.html"), // static file
// System Status page
ROUTE_TPL_FILE("/", tplSystemStatus, "/pages/status.tpl"),
ROUTE_TPL_FILE("/status", tplSystemStatus, "/pages/status.tpl"),
ROUTE_TPL_FILE("/api/status.json", tplSystemStatus, "/json/status.tpl"),
// Waveform page
ROUTE_FILE("/waveform", "/pages/waveform.html"), // static file, html -> can use gzip
ROUTE_TPL_FILE("/api/raw.json", tplWaveformJSON, "/json/samples.tpl"),
// --- WiFi config ---
@ -46,7 +54,6 @@ HttpdBuiltInUrl builtInUrls[] = {
ROUTE_AUTH("/wifi/*", myPassFn),
#endif
ROUTE_REDIRECT("/wifi/", "/wifi"),
ROUTE_TPL_FILE("/wifi", tplWlan, "/pages/wifi.tpl"),
ROUTE_CGI("/wifi/scan.cgi", cgiWiFiScan),
@ -54,11 +61,6 @@ HttpdBuiltInUrl builtInUrls[] = {
ROUTE_CGI("/wifi/connstatus.cgi", cgiWiFiConnStatus),
ROUTE_CGI("/wifi/setmode.cgi", cgiWiFiSetMode),
// --- API ---
// API for measurements
ROUTE_TPL_FILE("/api/raw.json", tplReadSamplesJSON, "/json/samples.tpl"),
// --- FS ---
ROUTE_FS("*"), //Catch-all cgi function for the filesystem NOTE: unsafe, lets user read templates.

42
user/utils.c

@ -0,0 +1,42 @@
#include <esp8266.h>
#include "utils.h"
int FLASH_FN rssi2perc(int rssi)
{
int r;
// convert to percentage
if (rssi > -50)
r = 100;
else if (rssi < -100)
r = 0;
else
r = 2 * (rssi + 100); // approx.
return r;
}
const FLASH_FN char *auth2str(AUTH_MODE auth)
{
switch (auth) {
case AUTH_OPEN: return "Open";
case AUTH_WEP: return "WEP";
case AUTH_WPA_PSK: return "WPA";
case AUTH_WPA2_PSK: return "WPA2";
case AUTH_WPA_WPA2_PSK: return "WPA/WPA2";
default:
return "Unknown";
}
}
const FLASH_FN char *opmode2str(int opmode)
{
switch (opmode) {
case NULL_MODE: return "Disabled";
case STATION_MODE: return "Client";
case SOFTAP_MODE: return "SoftAP";
case STATIONAP_MODE: return "STA+AP";
default:
return "Unknown";
}
}

10
user/utils.h

@ -0,0 +1,10 @@
#ifndef UTILS_H
#define UTILS_H
#include <esp8266.h>
int rssi2perc(int rssi);
const char *auth2str(AUTH_MODE auth);
const char *opmode2str(int opmode);
#endif // UTILS_H
Loading…
Cancel
Save