Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
steadramon authored and steadramon committed Apr 14, 2023
1 parent b00b593 commit ebed3e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 58 deletions.
17 changes: 3 additions & 14 deletions ESPGeiger/src/ConfigManager/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ void ConfigManager::handleJsonReturn()
void ConfigManager::handleStatusPage()
{
String page = FPSTR(HTTP_HEAD_START);
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(faviconHead);
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(STATUS_PAGE_BODY);
String title = FPSTR(thingName);
Expand All @@ -191,17 +189,16 @@ void ConfigManager::handleStatusPage()
void ConfigManager::handleRestart()
{
String page = FPSTR(HTTP_HEAD_START);
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(faviconHead);
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_HEAD_MREFRESH);
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(thingName);
page += F(" is restarting...<br /><br/>");
page.replace(FPSTR(T_v), "Restarting...");
page.replace(FPSTR(T_v), "Restarting ...");
page += FPSTR(HTTP_END);
ConfigManager::server->send(200, FPSTR(HTTP_HEAD_CT), page);
Log::console(PSTR("Config: Restarting ... "));
delay(1000);
ESP.restart();
}
Expand Down Expand Up @@ -264,19 +261,14 @@ void ConfigManager::loadParams()
{
WiFiManagerParameter** customParams = ConfigManager::getParameters();
// Should not be too verbose otherwise it triggers the watchdog reset
//logging::getLogStream().print("wifi: json to load: ");
//serializeJson(jsonBuffer, logging::getLogStream());
//logging::getLogStream().println();
JsonObject root = jsonBuffer.as<JsonObject>();
for (JsonObject::iterator it = root.begin(); it != root.end(); ++it)
{
int idx = getIndexFromID(it->key().c_str());
if (idx != -1)
{
// Should not be too verbose otherwise it triggers the watchdog reset
//logging::getLogStream().printf("wifi: reading key \"%s\" and value \"%s\"\n", it->key().c_str(), it->value().as<char*>());
// Log::console(PSTR("wifi: key \"%s\" with value \"%s\""), it->key().c_str(), it->value().as<char*>());

customParams[idx]->setValue(it->value().as<char*>(), customParams[idx]->getValueLength());
}
else
Expand All @@ -301,15 +293,13 @@ void ConfigManager::loadParams()

}


void ConfigManager::handleRefreshConsole()
{
uint32_t counter = 0;

char stmp[8];
String s = server->arg("c1");
strcpy(stmp, s.c_str());
// strlcpy(stmp, s.c_str(), sizeof(stmp));
if (strlen(stmp))
{
counter = atoi(stmp);
Expand Down Expand Up @@ -399,7 +389,6 @@ void ConfigManager::saveParams()
mqtt.disconnect();
}


const char* ConfigManager::getParamValueFromID(const char* str)
{
WiFiManagerParameter** customParams = ConfigManager::getParameters();
Expand Down Expand Up @@ -448,4 +437,4 @@ char* ConfigManager::getUptimeString () {
snprintf (strBuffer, sizeof (strBuffer) - 1, "%uT%02d:%02d:%02d", days, hours, minutes, seconds);

return strBuffer;
}
}
48 changes: 4 additions & 44 deletions ESPGeiger/src/ConfigManager/html.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const char IOTWEBCONF_DASHBOARD_STYLE_INNER[] PROGMEM = "table{margin:20px auto;}h3{text-align:center;}.card{height:12em;margin:10px;text-align:left;font-family:Arial;border:3px groove;border-radius:0.3rem;display:inline-block;padding:10px;min-width:260px;}td{padding:0 10px;}textarea{resize:vertical;width:100%;margin:0;height:318px;padding:5px;overflow:auto;}#c1{width:98%;padding:5px;}#t1{width:98%}.console{display:inline-block;text-align:center;margin:10px 0;width:98%;max-width:1080px;}.G{color:green;}.R{color:red}";

const char HTTP_HEAD_MREFRESH[] PROGMEM = "<meta http-equiv='refresh' content='10; url=/'>";

static const char STATUS_PAGE_BODY[] PROGMEM = R"HTML(<center><h1>{v}</h1></center>
<style>
textarea{resize:vertical;width:100%;margin:0;height:250px;padding:5px;overflow:auto;}
.wrap{min-width: 350px;max-width: 900px;width: 50vw; }
</style>
<canvas id="g1" style="height:200px; width: 100%; min-width: 350px; border:2px solid #000;"></canvas>
<div id="g2" class="wdr"></div>
<style>textarea{resize:vertical;width:100%;margin:0;height:250px;padding:5px;overflow:auto;} .wrap{min-width:350px;max-width:900px;width:50vw}</style>
<canvas id="g1" style="height:200px;width:100%;min-width:350px;border:2px solid #000;"></canvas><div id="g2" class="wdr"></div>
<table><tr><th>CPM:</th><td><span id="cpm">-</span></td></tr><tr><th>μSv:</th><td><span id="usv">-</span></td></tr><tr><th>Uptime:</th><td><span id="uptime">-</span></td></tr></table>
<div><h3>Console</h3><textarea readonly='' id='t1' wrap='off'></textarea></div>
<script src="/js"></script>
Expand All @@ -37,42 +31,8 @@ static const char STATUS_PAGE_FOOT[] PROGMEM = "<br/><small><a target='_blank' h

static const char statusJS[] PROGMEM = R"JS("use strict";
!function(){let e=new Graph("g1",["CPM","CPM5","CPM15"],"cpm","g2",15,null,0,!0,!0,5,5);!function t(){var n=new XMLHttpRequest;n.open("GET","/json",!0),n.onload=function(){if(n.status>=200&&n.status<400){var o=JSON.parse(n.responseText);byID('uptime').innerHTML=o.uptime;byID('cpm').innerHTML=o.cpm;byID('usv').innerHTML=(o.cpm/o.ratio).toFixed(4);e.update([o.cpm,o.cpm5,o.cpm15]),setTimeout(t,3e3)}},n.onerror=function(){setTimeout(t,6e3)},n.send()}()}();

var x=null,lt,to,tp,pc='';var sn=0,id=0;
function f(){
var c,o='',t;
clearTimeout(lt);
t = document.getElementById('t1');

x=new XMLHttpRequest();
x.onload = function() {
if(x.status==200){
var z,d;var a=x.responseText;
id=a.substr(0,a.indexOf('\n'));
z=a.substr(a.indexOf('\n')+1);
if(z.length>0){
t.value+=z;
}
if (t.scrollTop >= sn) {
t.scrollTop=99999;
sn=t.scrollTop;
}
}
lt=setTimeout(f,3210);
};
x.onerror = function() {
lt=setTimeout(f,6000);
};

x.open('GET','/cs?c1='+id,true);
x.send();

return false;
}

window.addEventListener('load', f);

var lt,to,tp,x=null,pc="",sn=0,id=0;
function f(){var t;return clearTimeout(lt),t=byID("t1"),(x=new XMLHttpRequest).onload=function(){if(200==x.status){var e,n=x.responseText;id=n.substr(0,n.indexOf("\n")),(e=n.substr(n.indexOf("\n")+1)).length>0&&(t.value+=e),t.scrollTop>=sn&&(t.scrollTop=99999,sn=t.scrollTop)}lt=setTimeout(f,3210)},x.onerror=function(){lt=setTimeout(f,6e3)},x.open("GET","/cs?c1="+id,!0),x.send(),!1}window.addEventListener("load",f);
)JS";
// picograph.js - https://github.com/RainingComputers/picograph.js
Expand Down

0 comments on commit ebed3e0

Please sign in to comment.