Status information auto-updates, tweaked HTML

This commit is contained in:
softplus
2022-09-01 21:21:20 +02:00
parent 0c0cb11edd
commit 7f07356ce2
2 changed files with 65 additions and 25 deletions

View File

@ -114,10 +114,15 @@ int http_fn_index(http_request_t *request) {
bRawPWMs = CFG_HasFlag(OBK_FLAG_LED_RAWCHANNELSMODE);
forceShowRGBCW = CFG_HasFlag(OBK_FLAG_LED_FORCESHOWRGBCWCONTROLLER);
http_setup(request, httpMimeTypeHTML);
poststr(request,htmlHeader);
//poststr(request,"<style>.r { background-color: red; } .g { background-color: green; }</style>");
HTTP_AddHeader(request);
// use ?state URL parameter to only request current state
if(!http_getArg(request->url, "state", tmpA, sizeof(tmpA))) {
http_setup(request, httpMimeTypeHTML);
poststr(request,htmlHeader);
//poststr(request,"<style>.r { background-color: red; } .g { background-color: green; }</style>");
HTTP_AddHeader(request);
poststr(request, "<div id=\"statediv\">"); // replaceable content follows
}
if(http_getArg(request->url,"tgl",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_LEDPOWER) {
@ -455,16 +460,6 @@ int http_fn_index(http_request_t *request) {
RESET_ScheduleModuleReset(3);
}
poststr(request,"<form action=\"cfg\"><input type=\"submit\" value=\"Config\"/></form>");
poststr(request,"<form action=\"/index\">\
<input type=\"hidden\" id=\"restart\" name=\"restart\" value=\"1\">\
<input class=\"bred\" type=\"submit\" value=\"Restart\" onclick=\"return confirm('Are you sure to restart module?')\">\
</form> ");
poststr(request,"<form action=\"/app\" target=\"_blank\"><input type=\"submit\" value=\"Launch Web Application\"\"></form> ");
poststr(request,"<form action=\"about\"><input type=\"submit\" value=\"About\"/></form>");
if(1) {
int bFirst = true;
hprintf128(request,"<h5>");
@ -486,10 +481,53 @@ int http_fn_index(http_request_t *request) {
hprintf128(request,"<h5>Ping watchdog - %i lost, %i ok!</h5>",
PingWatchDog_GetTotalLost(),PingWatchDog_GetTotalReceived());
// for normal page loads, show the rest of the HTML
if(!http_getArg(request->url,"state",tmpA,sizeof(tmpA))) {
poststr(request, "</div>"); // end id=statediv
poststr(request,htmlRefresh);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
// Shared UI elements
poststr(request,"<form action=\"cfg\"><input type=\"submit\" value=\"Config\"/></form>");
poststr(request,"<form action=\"/index\">\
<input type=\"hidden\" id=\"restart\" name=\"restart\" value=\"1\">\
<input class=\"bred\" type=\"submit\" value=\"Restart\" onclick=\"return confirm('Are you sure to restart module?')\">\
</form> ");
poststr(request,"<form action=\"/app\" target=\"_blank\"><input type=\"submit\" value=\"Launch Web Application\"\"></form> ");
poststr(request,"<form action=\"about\"><input type=\"submit\" value=\"About\"/></form>");
poststr(request,htmlRefresh);
HTTP_AddBuildFooter(request);
// refresh status section every 3 seconds
poststr(
request,
"<script type='text/javascript'>"
"var firstTime, lastTime, req=null;"
"eb=s=>document.getElementById(s);"
"function showState() { "
"clearTimeout(firstTime);"
"clearTimeout(lastTime);"
"if (req!=null) { req.abort() }"
"req=new XMLHttpRequest();"
"req.onreadystatechange=()=>{"
"if(req.readyState==4 && req.status==200){"
"var s=req.responseText;"
"eb('statediv').innerHTML=s;"
"clearTimeout(firstTime);"
"clearTimeout(lastTime);"
"lastTime=setTimeout(showState, 3000);"
"}};"
"req.open('GET','index?state=1', true);"
"req.send();"
"firstTime=setTimeout(showState, 3000);"
"}"
"window.addEventListener('load', showState);"
"</script>"
);
poststr(request,htmlEnd);
}
poststr(request, NULL);
return 0;

View File

@ -295,12 +295,14 @@ void setupAllWB2SPinsAsButtons() {
PIN_SetPinChannelForPinIndex(27,1);
}
const char *g_header_start = "<h1><a href=\"https://github.com/openshwprojects/OpenBK7231T_App/\">";
const char *g_header_end = "</a></h1><h3><a href=\"https://www.elektroda.com/rtvforum/viewtopic.php?p=19841301#19841301\">[Read more]</a><a href=\"https://paypal.me/openshwprojects\">[Support project]</a></h3>";
const char *g_header_start =
"<noscript>To use this device, please enable JavaScript.<br></noscript>"
"<h1><a target=\"_blank\" href=\"https://github.com/openshwprojects/OpenBK7231T_App/\">";
const char *g_header_end =
"</a></h1><h3><a target=\"_blank\" "
"href=\"https://www.elektroda.com/rtvforum/"
"viewtopic.php?p=19841301#19841301\">[Read more]</a><a target=\"_blank\" "
"href=\"https://paypal.me/openshwprojects\">[Support project]</a></h3>";
void HTTP_AddHeader(http_request_t *request) {
poststr(request,g_header_start);
@ -320,9 +322,9 @@ void HTTP_AddBuildFooter(http_request_t *request) {
WiFI_GetMacAddress((char *)mac);
sprintf(upTimeStr,"<br> Device MAC: %02X%02X%02X%02X%02X%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
sprintf(upTimeStr,"<br>Device MAC: %02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
poststr(request,upTimeStr);
sprintf(upTimeStr,"<br> Short name: %s, Chipset %s",CFG_GetShortDeviceName(),PLATFORM_MCU_NAME);
sprintf(upTimeStr,"<br>Short name: %s, Chipset %s",CFG_GetShortDeviceName(),PLATFORM_MCU_NAME);
poststr(request,upTimeStr);
}