Merge branch 'tweaks' of https://github.com/softplus/OpenBK7231T_App into tweaks2

This commit is contained in:
softplus
2022-09-04 00:02:37 +02:00
5 changed files with 282 additions and 206 deletions

View File

@ -105,7 +105,6 @@ int http_fn_testmsg(http_request_t *request) {
return 0;
}
int http_fn_index(http_request_t *request) {
int j, i;
char tmpA[128];
@ -119,67 +118,61 @@ int http_fn_index(http_request_t *request) {
if(!http_getArg(request->url, "state", tmpA, sizeof(tmpA))) {
http_setup(request, httpMimeTypeHTML);
http_html_start(request, NULL);
poststr(request, "<div id=\"statediv\">"); // replaceable content follows
}
poststr(request, "<div id=\"changed\">");
if(http_getArg(request->url,"tgl",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_LEDPOWER) {
hprintf128(request,"<h3>Toggled LED power!</h3>",j);
} else {
hprintf128(request,"<h3>Toggled %i!</h3>",j);
}
CHANNEL_Toggle(j);
}
if(http_getArg(request->url,"on",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
hprintf128(request,"<h3>Enabled %i!</h3>",j);
CHANNEL_Set(j,255,1);
}
if(http_getArg(request->url,"rgb",tmpA,sizeof(tmpA))) {
hprintf128(request,"<h3>Set RGB to %s!</h3>",tmpA);
LED_SetBaseColor(0,"led_basecolor",tmpA,0);
}
if(http_getArg(request->url,"off",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
hprintf128(request,"<h3>Disabled %i!</h3>",j);
CHANNEL_Set(j,0,1);
}
if(http_getArg(request->url,"pwm",tmpA,sizeof(tmpA))) {
int newPWMValue = atoi(tmpA);
http_getArg(request->url,"pwmIndex",tmpA,sizeof(tmpA));
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_TEMPERATURE) {
hprintf128(request,"<h3>Changed Temperature to %i!</h3>",newPWMValue);
} else {
hprintf128(request,"<h3>Changed pwm %i to %i!</h3>",j,newPWMValue);
}
CHANNEL_Set(j,newPWMValue,1);
}
if(http_getArg(request->url,"dim",tmpA,sizeof(tmpA))) {
int newDimmerValue = atoi(tmpA);
http_getArg(request->url,"dimIndex",tmpA,sizeof(tmpA));
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_BRIGHTNESS) {
hprintf128(request,"<h3>Changed LED brightness to %i!</h3>",newDimmerValue);
} else {
hprintf128(request,"<h3>Changed dimmer %i to %i!</h3>",j,newDimmerValue);
}
CHANNEL_Set(j,newDimmerValue,1);
}
if(http_getArg(request->url,"set",tmpA,sizeof(tmpA))) {
int newSetValue = atoi(tmpA);
http_getArg(request->url,"setIndex",tmpA,sizeof(tmpA));
j = atoi(tmpA);
hprintf128(request,"<h3>Changed channel %i to %i!</h3>",j,newSetValue);
CHANNEL_Set(j,newSetValue,1);
}
if(http_getArg(request->url,"restart",tmpA,sizeof(tmpA))) {
poststr(request,"<h5> Module will restart soon</h5>");
RESET_ScheduleModuleReset(3);
}
poststr(request, "</div>"); // end div#change
poststr(request, "<div id=\"state\">"); // replaceable content follows
if(http_getArg(request->url,"tgl",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_LEDPOWER) {
hprintf128(request,"<h3>Toggled LED power!</h3>",j);
} else {
hprintf128(request,"<h3>Toggled %i!</h3>",j);
}
CHANNEL_Toggle(j);
}
if(http_getArg(request->url,"on",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
hprintf128(request,"<h3>Enabled %i!</h3>",j);
CHANNEL_Set(j,255,1);
}
if(http_getArg(request->url,"rgb",tmpA,sizeof(tmpA))) {
hprintf128(request,"<h3>Set RGB to %s!</h3>",tmpA);
LED_SetBaseColor(0,"led_basecolor",tmpA,0);
}
if(http_getArg(request->url,"off",tmpA,sizeof(tmpA))) {
j = atoi(tmpA);
hprintf128(request,"<h3>Disabled %i!</h3>",j);
CHANNEL_Set(j,0,1);
}
if(http_getArg(request->url,"pwm",tmpA,sizeof(tmpA))) {
int newPWMValue = atoi(tmpA);
http_getArg(request->url,"pwmIndex",tmpA,sizeof(tmpA));
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_TEMPERATURE) {
hprintf128(request,"<h3>Changed Temperature to %i!</h3>",newPWMValue);
} else {
hprintf128(request,"<h3>Changed pwm %i to %i!</h3>",j,newPWMValue);
}
CHANNEL_Set(j,newPWMValue,1);
}
if(http_getArg(request->url,"dim",tmpA,sizeof(tmpA))) {
int newDimmerValue = atoi(tmpA);
http_getArg(request->url,"dimIndex",tmpA,sizeof(tmpA));
j = atoi(tmpA);
if(j == SPECIAL_CHANNEL_BRIGHTNESS) {
hprintf128(request,"<h3>Changed LED brightness to %i!</h3>",newDimmerValue);
} else {
hprintf128(request,"<h3>Changed dimmer %i to %i!</h3>",j,newDimmerValue);
}
CHANNEL_Set(j,newDimmerValue,1);
}
if(http_getArg(request->url,"set",tmpA,sizeof(tmpA))) {
int newSetValue = atoi(tmpA);
http_getArg(request->url,"setIndex",tmpA,sizeof(tmpA));
j = atoi(tmpA);
hprintf128(request,"<h3>Changed channel %i to %i!</h3>",j,newSetValue);
CHANNEL_Set(j,newSetValue,1);
}
poststr(request, "<table width=\"100%\">");
@ -428,6 +421,11 @@ int http_fn_index(http_request_t *request) {
DRV_AppendInformationToHTTPIndexPage(request);
#endif
if(http_getArg(request->url,"restart",tmpA,sizeof(tmpA))) {
poststr(request,"<h5> Module will restart soon</h5>");
RESET_ScheduleModuleReset(3);
}
if(1) {
int bFirst = true;
hprintf128(request,"<h5>");
@ -451,7 +449,7 @@ int http_fn_index(http_request_t *request) {
// for normal page loads, show the rest of the HTML
if(!http_getArg(request->url,"state",tmpA,sizeof(tmpA))) {
poststr(request, "</div>"); // end div#state
poststr(request, "</div>"); // end id=statediv
// Shared UI elements
poststr(request, "<form action=\"cfg\"><input type=\"submit\" value=\"Config\"/></form>");
@ -481,18 +479,16 @@ int http_fn_index(http_request_t *request) {
"req.onreadystatechange=()=>{"
"if(req.readyState==4 && req.status==200){"
"var s=req.responseText;"
"eb('state').innerHTML=s;"
"eb('statediv').innerHTML=s;"
"clearTimeout(firstTime);"
"clearTimeout(lastTime);"
"lastTime=setTimeout(showState, 3e3);"
"lastTime=setTimeout(showState, 3000);"
"}};"
"req.open('GET','index?state=1', true);"
"req.send();"
"firstTime=setTimeout(showState, 3e3);"
"firstTime=setTimeout(showState, 3000);"
"}"
"window.addEventListener('load', showState);"
"history.pushState(null, '', 'index');" // drop actions like 'toggle' from URL
"setTimeout(()=>{eb('changed').innerHTML=''}, 5e3);" // hide change info
"</script>"
);
}
@ -503,10 +499,12 @@ int http_fn_index(http_request_t *request) {
int http_fn_about(http_request_t *request){
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "About");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h2>Open source firmware for BK7231N, BK7231T, XR809 and BL602 by OpenSHWProjects</h2>");
poststr(request,htmlFooterReturnToMenu);
http_html_end(request);
poststr(request,htmlReturnToMenu);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -517,7 +515,8 @@ int http_fn_about(http_request_t *request){
int http_fn_cfg_mqtt(http_request_t *request) {
int i;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "MQTT");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h2> Use this to connect to your MQTT</h2>");
poststr(request,"<form action=\"/cfg_mqtt_set\">\
<label for=\"host\">Host:</label><br>\
@ -545,8 +544,9 @@ int http_fn_cfg_mqtt(http_request_t *request) {
poststr(request,"\"><br>\
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure? Please check MQTT data twice?')\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -554,7 +554,8 @@ int http_fn_cfg_mqtt(http_request_t *request) {
int http_fn_cfg_mqtt_set(http_request_t *request) {
char tmpA[128];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Saving MQTT");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
if(http_getArg(request->url,"host",tmpA,sizeof(tmpA))) {
CFG_SetMQTTHost(tmpA);
@ -579,15 +580,21 @@ int http_fn_cfg_mqtt_set(http_request_t *request) {
poststr(request,"<br>");
poststr(request,"<a href=\"cfg_mqtt\">Return to MQTT settings</a>");
poststr(request,"<br>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
int http_fn_cfg_webapp(http_request_t *request) {
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set Webapp");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h2> Use this to set the URL of the Webapp</h2>");
poststr(request,"<form action=\"/cfg_webapp_set\">\
<label for=\"url\">Url:</label><br>\
@ -596,8 +603,9 @@ int http_fn_cfg_webapp(http_request_t *request) {
poststr(request,"\"><br>\
<input type=\"submit\" value=\"Submit\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -605,7 +613,8 @@ int http_fn_cfg_webapp(http_request_t *request) {
int http_fn_cfg_webapp_set(http_request_t *request) {
char tmpA[128];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Saving Webapp");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
if(http_getArg(request->url,"url",tmpA,sizeof(tmpA))) {
if(CFG_SetWebappRoot(tmpA)) {
@ -618,8 +627,9 @@ int http_fn_cfg_webapp_set(http_request_t *request) {
}
poststr(request,"<br>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -635,7 +645,8 @@ int http_fn_cfg_ping(http_request_t *request) {
int bChanged;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set Watchdog");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
bChanged = 0;
poststr(request,"<h3> Ping watchdog (backup reconnect mechanism)</h3>");
poststr(request,"<p> By default, all OpenBeken devices automatically tries to reconnect to WiFi when a connection is lost.");
@ -695,8 +706,10 @@ int http_fn_cfg_ping(http_request_t *request) {
poststr(request,"\"><br><br>\
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure?')\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -706,7 +719,8 @@ int http_fn_cfg_wifi(http_request_t *request) {
char tmpA[128];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set Wifi");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
/*bChanged = 0;
if(http_getArg(recvbuf,"ssid",tmpA,sizeof(tmpA))) {
CFG_SetWiFiSSID(tmpA);
@ -789,8 +803,10 @@ int http_fn_cfg_wifi(http_request_t *request) {
poststr(request,"\"><br><br>\
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure? Please check SSID and pass twice?')\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -801,7 +817,8 @@ int http_fn_cfg_name(http_request_t *request) {
char tmpA[128];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set name");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h2> Change device names for display. </h2> Remember that short name is used by MQTT.<br>");
if(http_getArg(request->url,"shortName",tmpA,sizeof(tmpA))) {
@ -826,18 +843,20 @@ int http_fn_cfg_name(http_request_t *request) {
poststr(request,"\"><br><br>\
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure? Short name might be used by MQTT, so you will have to reconfig some stuff.')\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
int http_fn_cfg_wifi_set(http_request_t *request) {
char tmpA[128];
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: generating cfg_wifi_set \r\n");
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Saving Wifi");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
if(http_getArg(request->url,"open",tmpA,sizeof(tmpA))) {
CFG_SetWiFiSSID("");
CFG_SetWiFiPass("");
@ -859,18 +878,24 @@ int http_fn_cfg_wifi_set(http_request_t *request) {
poststr(request,"<br>");
poststr(request,"<a href=\"cfg_wifi\">Return to WiFi settings</a>");
poststr(request,"<br>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
int http_fn_cfg_loglevel_set(http_request_t *request) {
char tmpA[128];
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: generating cfg_loglevel_set \r\n");
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set log level");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
if(http_getArg(request->url,"loglevel",tmpA,sizeof(tmpA))) {
#if WINDOWS
#else
@ -893,8 +918,9 @@ int http_fn_cfg_loglevel_set(http_request_t *request) {
poststr(request,"<br>");
poststr(request,"<a href=\"cfg\">Return to config settings</a>");
poststr(request,"<br>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -907,7 +933,8 @@ int http_fn_cfg_mac(http_request_t *request) {
int i;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set MAC address");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
if(http_getArg(request->url,"mac",tmpA,sizeof(tmpA))) {
for( i = 0; i < 6; i++ )
@ -925,6 +952,7 @@ int http_fn_cfg_mac(http_request_t *request) {
WiFI_GetMacAddress((char *)mac);
poststr(request,"<h2> Here you can change MAC address.</h2>");
poststr(request,"<form action=\"/cfg_mac\">\
<label for=\"mac\">MAC:</label><br>\
@ -933,8 +961,10 @@ int http_fn_cfg_mac(http_request_t *request) {
poststr(request,"\"><br><br>\
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure? Please check MAC hex string twice?')\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -952,7 +982,8 @@ int http_fn_flash_read_tool(http_request_t *request) {
char tmpB[64];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Flash read");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h4>Flash Read Tool</h4>");
if( http_getArg(request->url,"hex",tmpA,sizeof(tmpA))){
hex = atoi(tmpA);
@ -1026,8 +1057,11 @@ int http_fn_flash_read_tool(http_request_t *request) {
<input type=\"submit\" value=\"Submit\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1043,7 +1077,8 @@ int http_fn_cmd_tool(http_request_t *request) {
//char tmpB[64];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Command tool");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h4>Command Tool</h4>");
if( http_getArg(request->url,"cmd",tmpA,sizeof(tmpA))) {
@ -1064,8 +1099,11 @@ int http_fn_cmd_tool(http_request_t *request) {
<input type=\"submit\" value=\"Submit\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1074,7 +1112,8 @@ int http_fn_startup_command(http_request_t *request) {
char tmpA[512];
const char *cmd;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Set startup command");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h4>Set/Change/Clear startup command line</h4>");
poststr(request,"<h5>Startup command is a shorter, smaller alternative to LittleFS autoexec.bat."
"The startup commands are ran at device startup."
@ -1103,8 +1142,11 @@ int http_fn_startup_command(http_request_t *request) {
<input type=\"submit\" value=\"Submit\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1112,9 +1154,12 @@ int http_fn_uart_tool(http_request_t *request) {
char tmpA[256];
int resultLen = 0;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "UART tool");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h4>UART Tool</h4>");
if(http_getArg(request->url,"data",tmpA,sizeof(tmpA))) {
#ifndef OBK_DISABLE_ALL_DRIVERS
byte results[128];
@ -1150,19 +1195,25 @@ int http_fn_uart_tool(http_request_t *request) {
<input type=\"submit\" value=\"Submit\">\
</form> ");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
int http_fn_config_dump_table(http_request_t *request) {
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Dump config");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"Not implemented <br>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1174,7 +1225,8 @@ int http_fn_cfg_quick(http_request_t *request) {
char tmpA[128];
int j;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Quick Config");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h4>Quick Config</h4>");
if(http_getArg(request->url,"dev",tmpA,sizeof(tmpA))) {
@ -1190,8 +1242,10 @@ int http_fn_cfg_quick(http_request_t *request) {
poststr(request,"</select>");
poststr(request,"<input type=\"submit\" value=\"Set\"/></form>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1221,7 +1275,8 @@ int http_fn_cfg_ha(http_request_t *request) {
baseName = CFG_GetShortDeviceName();
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Home Assistant Setup");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h4>Home Assistant Cfg</h4>");
hprintf128(request,"<h4>Note that your short device name is: %s</h4>",baseName);
poststr(request,"<h4>Paste this to configuration yaml</h4>");
@ -1304,8 +1359,10 @@ int http_fn_cfg_ha(http_request_t *request) {
poststr(request,"</textarea>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1443,7 +1500,8 @@ int http_fn_cm(http_request_t *request) {
int http_fn_cfg(http_request_t *request) {
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Config");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<form action=\"cfg_pins\"><input type=\"submit\" value=\"Configure Module\"/></form>");
poststr(request,"<form action=\"cfg_generic\"><input type=\"submit\" value=\"Configure General\"/></form>");
poststr(request,"<form action=\"cfg_startup\"><input type=\"submit\" value=\"Configure Startup\"/></form>");
@ -1475,8 +1533,9 @@ int http_fn_cfg(http_request_t *request) {
}
#endif
#endif
poststr(request,htmlFooterReturnToMenu);
http_html_end(request);
poststr(request,htmlReturnToMenu);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1489,7 +1548,8 @@ int http_fn_cfg_pins(http_request_t *request) {
char tmpB[64];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Pin config");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"<h5> First textfield is used to enter channel index (relay index), used to support multiple relays and buttons</h5>");
poststr(request,"<h5> (so, first button and first relay should have channel 1, second button and second relay have channel 2, etc)</h5>");
poststr(request,"<h5> Second textfield (only for buttons) is used to enter channel to toggle when doing double click</h5>");
@ -1604,8 +1664,10 @@ int http_fn_cfg_pins(http_request_t *request) {
}
poststr(request,"<input type=\"submit\" value=\"Save\"/></form>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1633,7 +1695,8 @@ int http_fn_cfg_generic(http_request_t *request) {
char tmpB[64];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Generic config");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
if( http_getArg(request->url,"boot_ok_delay",tmpA,sizeof(tmpA))) {
i = atoi(tmpA);
@ -1689,8 +1752,10 @@ int http_fn_cfg_generic(http_request_t *request) {
poststr(request,"\"><br>");
poststr(request,"<input type=\"submit\" value=\"Save\"/></form>");
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1701,7 +1766,9 @@ int http_fn_cfg_startup(http_request_t *request) {
char tmpA[128];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Config startup");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
hprintf128(request,"<h5>Here you can set pin start values<h5>");
hprintf128(request,"<h5>For relays, simply use 1 or 0</h5>");
hprintf128(request,"<h5>For 'remember last power state', use -1 as a special value</h5>");
@ -1745,8 +1812,10 @@ int http_fn_cfg_startup(http_request_t *request) {
}
}
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1755,7 +1824,8 @@ int http_fn_cfg_dgr(http_request_t *request) {
char tmpA[128];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Device groups");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
hprintf128(request,"<h5>Here you can configure Tasmota Device Groups<h5>");
@ -1834,8 +1904,10 @@ int http_fn_cfg_dgr(http_request_t *request) {
poststr(request," </tr></table> <input type=\"submit\" value=\"Submit\"></form>");
}
poststr(request,htmlFooterReturnToCfgLink);
http_html_end(request);
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
@ -1847,7 +1919,7 @@ int http_fn_ota_exec(http_request_t *request) {
//char tmpB[64];
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "OTA request");
poststr(request,htmlHeader);
if(http_getArg(request->url,"host",tmpA,sizeof(tmpA))) {
hprintf128(request,"<h3>OTA requested for %s!</h3>",tmpA);
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"http_fn_ota_exec: will try to do OTA for %s \r\n",tmpA);
@ -1863,15 +1935,17 @@ int http_fn_ota_exec(http_request_t *request) {
otarequest(tmpA);
#endif
}
poststr(request,htmlFooterReturnToMenu);
http_html_end(request);
poststr(request,htmlReturnToMenu);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
int http_fn_ota(http_request_t *request) {
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "OTA system");
poststr(request,htmlHeader);
poststr(request,"<p>Simple OTA system (you should rather use the OTA from App panel where you can drag and drop file easily without setting up server). Use RBL file for OTA. In the OTA below, you should paste link to RBL file (you need HTTP server).</p>");
poststr(request,"<form action=\"/ota_exec\">\
<label for=\"host\">URL for new bin file:</label><br>\
@ -1879,18 +1953,22 @@ int http_fn_ota(http_request_t *request) {
poststr(request,"\"><br>\
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure?')\">\
</form> ");
poststr(request,htmlFooterReturnToMenu);
http_html_end(request);
poststr(request,htmlReturnToMenu);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
int http_fn_other(http_request_t *request) {
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Not found");
poststr(request,htmlHeader);
HTTP_AddHeader(request);
poststr(request,"Not found.<br/>");
poststr(request,htmlFooterReturnToMenu);
http_html_end(request);
poststr(request,htmlReturnToMenu);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}

View File

@ -60,7 +60,7 @@ const char htmlHeadStyle[] =
".hf{display:none;}"
".hdiv{width:95%;white-space:nowrap;}"
".hele{width:210px;display:inline-block;margin-left:2px;}"
"div#state{padding:0} div#changed{padding:0}"
"div#statediv{padding:0}"
"div#main{text-align:left; display:inline-block; color:#eaeaea;min-width:340px;max-width:800px;}"
"</style>";
const char htmlBodyStart[] =
@ -200,46 +200,6 @@ void http_setup(http_request_t *request, const char *type){
poststr(request,"\r\n");
}
void http_html_start(http_request_t *request, const char *pagename) {
// void HTTP_AddHeader(http_request_t *request) {
poststr(request, htmlDoctype);
poststr(request, "<title>");
poststr(request, CFG_GetDeviceName()); // todo: check escaping
if (pagename) {
poststr(request, " - ");
poststr(request, pagename);
}
poststr(request, "</title>");
poststr(request, htmlHeadMain);
poststr(request, htmlHeadStyle);
poststr(request, htmlBodyStart);
poststr(request, CFG_GetDeviceName()); // todo: check escaping
poststr(request, htmlBodyStart2);
}
void http_html_end(http_request_t *request) {
// was void HTTP_AddBuildFooter(http_request_t *request) {
char upTimeStr[128];
unsigned char mac[32];
poststr(request, " | ");
poststr(request, htmlFooterInfo);
poststr(request, "<br>");
poststr(request, g_build_str);
poststr(request, "<br>Online for ");
misc_formatUpTimeString(Time_getUpTimeSeconds(), upTimeStr);
poststr(request, upTimeStr);
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]);
poststr(request, upTimeStr);
sprintf(upTimeStr, "<br>Short name: %s, Chipset %s",CFG_GetShortDeviceName(),PLATFORM_MCU_NAME);
poststr(request, upTimeStr);
poststr(request, htmlBodyEnd);
}
const char *http_checkArg(const char *p, const char *n) {
while(1) {
if(*n == 0 && (*p == 0 || *p == '='))
@ -393,6 +353,37 @@ 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>";
void HTTP_AddHeader(http_request_t *request) {
poststr(request,g_header_start);
poststr(request,CFG_GetDeviceName());
poststr(request,g_header_end);
}
void HTTP_AddBuildFooter(http_request_t *request) {
char upTimeStr[128];
unsigned char mac[32];
poststr(request,"<br>");
poststr(request,g_build_str);
poststr(request,"<br> Online for ");
misc_formatUpTimeString(Time_getUpTimeSeconds(), upTimeStr);
poststr(request,upTimeStr);
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]);
poststr(request,upTimeStr);
sprintf(upTimeStr,"<br> Short name: %s, Chipset %s",CFG_GetShortDeviceName(),PLATFORM_MCU_NAME);
poststr(request,upTimeStr);
}
// add some more output safely, sending if necessary.
// call with str == NULL to force send. - can be binary.
// supply length

View File

@ -7,10 +7,11 @@ extern const char httpMimeTypeHTML[]; // HTML MIME type
extern const char httpMimeTypeText[]; // TEXT MIME type
extern const char httpMimeTypeJson[];
extern const char httpMimeTypeBinary[];
extern const char htmlFooterReturnToMenu[];
extern const char htmlFooterRefreshLink[];
extern const char htmlFooterReturnToCfgLink[];
extern const char htmlHeader[];
extern const char htmlEnd[];
extern const char htmlReturnToMenu[];
extern const char htmlRefresh[];
extern const char htmlReturnToCfg[];
extern const char *htmlPinRoleNames[];
@ -20,6 +21,8 @@ extern const char *g_build_str;
#define HTTP_RESPONSE_NOT_FOUND 404
#define HTTP_RESPONSE_SERVER_ERROR 500
#define MAX_QUERY 16
#define MAX_HEADERS 16
typedef struct http_request_tag {
@ -50,13 +53,11 @@ typedef struct http_request_tag {
int HTTP_ProcessPacket(http_request_t *request);
void http_setup(http_request_t *request, const char *type);
void http_html_start(http_request_t *request, const char *pagename);
void http_html_end(http_request_t *request);
int poststr(http_request_t *request, const char *str);
int postany(http_request_t *request, const char *str, int len);
void misc_formatUpTimeString(int totalSeconds, char *o);
// void HTTP_AddBuildFooter(http_request_t *request);
// void HTTP_AddHeader(http_request_t *request);
void HTTP_AddBuildFooter(http_request_t *request);
void HTTP_AddHeader(http_request_t *request);
int http_getArg(const char *base, const char *name, char *o, int maxSize);
int http_getArgInteger(const char *base, const char *name);

View File

@ -179,6 +179,7 @@ static int http_rest_get(http_request_t *request){
return http_rest_get_flash_advanced(request);
}
if (!strcmp(request->url, "api/dumpconfig")){
return http_rest_get_dumpconfig(request);
}
@ -191,11 +192,13 @@ static int http_rest_get(http_request_t *request){
return http_rest_get_flash_vars_test(request);
}
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "GET REST API");
poststr(request, "GET of ");
poststr(request, request->url);
http_html_end(request);
poststr(request, htmlEnd);
poststr(request,NULL);
return 0;
}
@ -254,7 +257,6 @@ static int http_rest_post(http_request_t *request){
#endif
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "POST REST API");
poststr(request, "POST to ");
poststr(request, request->url);
poststr(request, "<br/>Content Length:");
@ -263,11 +265,16 @@ static int http_rest_post(http_request_t *request){
poststr(request, "<br/>Content:[");
poststr(request, request->bodystart);
poststr(request, "]<br/>");
http_html_end(request);
poststr(request, htmlEnd);
poststr(request,NULL);
return 0;
}
static int http_rest_app(http_request_t *request){
const char *webhost = CFG_GetWebappRoot();
const char *ourip = HAL_GetMyIPString(); //CFG_GetOurIP();
@ -281,10 +288,9 @@ static int http_rest_app(http_request_t *request){
poststr(request, webhost);
poststr(request, apppage4);
} else {
http_html_start(request, "Not available");
poststr(request, htmlFooterReturnToMenu);
poststr(request, "no APP available<br/>");
http_html_end(request);
poststr(request,htmlHeader);
poststr(request,htmlReturnToMenu);
poststr(request,"no APP available<br/>");
}
poststr(request,NULL);
return 0;