More web chunks

More web chunks
This commit is contained in:
Theo Arends 2019-03-16 16:23:41 +01:00
parent 06a3678c20
commit 99d20f803b
7 changed files with 107 additions and 108 deletions

View File

@ -167,7 +167,6 @@ bool i2c_flg = false; // I2C configured
bool spi_flg = false; // SPI configured bool spi_flg = false; // SPI configured
bool soft_spi_flg = false; // Software SPI configured bool soft_spi_flg = false; // Software SPI configured
bool ntp_force_sync = false; // Force NTP sync bool ntp_force_sync = false; // Force NTP sync
bool reset_web_log_flag = false; // Reset web console log
myio my_module; // Active copy of Module GPIOs (17 x 8 bits) myio my_module; // Active copy of Module GPIOs (17 x 8 bits)
gpio_flag my_module_flag; // Active copy of Module GPIO flags gpio_flag my_module_flag; // Active copy of Module GPIO flags
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)

View File

@ -383,7 +383,7 @@ const char HTTP_END[] PROGMEM =
"</html>"; "</html>";
const char HTTP_DEVICE_CONTROL[] PROGMEM = "<td style='width:%d%%'><button onclick='la(\"&o=%d\");'>%s%s</button></td>"; // ?o is related to WebGetArg("o", tmp, sizeof(tmp)); const char HTTP_DEVICE_CONTROL[] PROGMEM = "<td style='width:%d%%'><button onclick='la(\"&o=%d\");'>%s%s</button></td>"; // ?o is related to WebGetArg("o", tmp, sizeof(tmp));
const char HTTP_DEVICE_STATE[] PROGMEM = "%s<td style='width:%d{c}%s;font-size:%dpx'>%s</div></td>"; // {c} = %'><div style='text-align:center;font-weight: const char HTTP_DEVICE_STATE[] PROGMEM = "<td style='width:%d{c}%s;font-size:%dpx'>%s</div></td>"; // {c} = %'><div style='text-align:center;font-weight:
enum ButtonTitle { enum ButtonTitle {
BUTTON_RESTART, BUTTON_RESET_CONFIGURATION, BUTTON_RESTART, BUTTON_RESET_CONFIGURATION,
@ -423,6 +423,7 @@ ESP8266WebServer *WebServer;
String chunk_buffer = ""; // Could be max 2 * CHUNKED_BUFFER_SIZE String chunk_buffer = ""; // Could be max 2 * CHUNKED_BUFFER_SIZE
int minimum_signal_quality = -1; int minimum_signal_quality = -1;
bool remove_duplicate_access_points = true; bool remove_duplicate_access_points = true;
bool reset_web_log_flag = false; // Reset web console log
uint8_t webserver_state = HTTP_OFF; uint8_t webserver_state = HTTP_OFF;
uint8_t upload_error = 0; uint8_t upload_error = 0;
uint8_t upload_file_type; uint8_t upload_file_type;
@ -588,6 +589,19 @@ void WSSend(int code, int ctype, const String& content)
* HTTP Content Chunk handler * HTTP Content Chunk handler
**********************************************************************************************/ **********************************************************************************************/
void WSContentBegin(int code, int ctype)
{
WebServer->client().flush();
WSHeaderSend();
#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
WebServer->sendHeader(F("Accept-Ranges"),F("none"));
WebServer->sendHeader(F("Transfer-Encoding"),F("chunked"));
#endif
WebServer->setContentLength(CONTENT_LENGTH_UNKNOWN);
WSSend(code, ctype, ""); // Signal start of chunked content
chunk_buffer = "";
}
void _WSContentSend(const String& content) // Low level sendContent for all core versions void _WSContentSend(const String& content) // Low level sendContent for all core versions
{ {
size_t len = content.length(); size_t len = content.length();
@ -648,19 +662,13 @@ void WSContentStart_P(const char* title, bool auth)
return WebServer->requestAuthentication(); return WebServer->requestAuthentication();
} }
WebServer->client().flush(); WSContentBegin(200, CT_HTML);
WebServer->setContentLength(CONTENT_LENGTH_UNKNOWN);
WSHeaderSend();
#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
WebServer->sendHeader(F("Accept-Ranges"),F("none"));
WebServer->sendHeader(F("Transfer-Encoding"),F("chunked"));
#endif
WSSend(200, CT_HTML, ""); // Signal start of chunked content
chunk_buffer = "";
if (title != NULL) {
char ctitle[strlen_P(title) +1]; char ctitle[strlen_P(title) +1];
strcpy_P(ctitle, title); // Get title from flash to RAM strcpy_P(ctitle, title); // Get title from flash to RAM
WSContentSend_P(HTTP_HEAD, Settings.friendlyname[0], ctitle); WSContentSend_P(HTTP_HEAD, Settings.friendlyname[0], ctitle);
}
} }
void WSContentStart_P(const char* title) void WSContentStart_P(const char* title)
@ -677,16 +685,18 @@ void WSContentSendStyle_P(const char* style)
} }
WSContentSend_P(HTTP_HEAD_STYLE1); WSContentSend_P(HTTP_HEAD_STYLE1);
WSContentSend_P(HTTP_HEAD_STYLE2); WSContentSend_P(HTTP_HEAD_STYLE2);
if (style != NULL) {
WSContentSend_P(style); WSContentSend_P(style);
}
WSContentSend_P(HTTP_HEAD_STYLE3, ModuleName().c_str(), Settings.friendlyname[0]); WSContentSend_P(HTTP_HEAD_STYLE3, ModuleName().c_str(), Settings.friendlyname[0]);
if (Settings.flag3.gui_hostname_ip) { if (Settings.flag3.gui_hostname_ip) {
bool lip = (static_cast<uint32_t>(WiFi.localIP()) != 0); bool lip = (static_cast<uint32_t>(WiFi.localIP()) != 0);
bool sip = (static_cast<uint32_t>(WiFi.softAPIP()) != 0); bool sip = (static_cast<uint32_t>(WiFi.softAPIP()) != 0);
WSContentSend_P(PSTR("<h4>%s%s (%s%s%s)</h4>"), // sonoff.local (192.168.2.12,192.168.4.1) WSContentSend_P(PSTR("<h4>%s%s (%s%s%s)</h4>"), // sonoff.local (192.168.2.12, 192.168.4.1)
my_hostname, my_hostname,
(mdns_begun) ? ".local" : "", (mdns_begun) ? ".local" : "",
(lip) ? WiFi.localIP().toString().c_str() : "", (lip) ? WiFi.localIP().toString().c_str() : "",
(lip && sip) ? "," : "", (lip && sip) ? ", " : "",
(sip) ? WiFi.softAPIP().toString().c_str() : ""); (sip) ? WiFi.softAPIP().toString().c_str() : "");
} }
WSContentSend_P(PSTR("</div>")); WSContentSend_P(PSTR("</div>"));
@ -694,7 +704,7 @@ void WSContentSendStyle_P(const char* style)
void WSContentSendStyle(void) void WSContentSendStyle(void)
{ {
WSContentSendStyle_P(PSTR("")); WSContentSendStyle_P(NULL);
} }
void WSContentButton(uint8_t title_index) void WSContentButton(uint8_t title_index)
@ -723,6 +733,13 @@ void WSContentSpaceButton(uint8_t title_index)
} }
void WSContentEnd(void) void WSContentEnd(void)
{
WSContentFlush(); // Flush chunk buffer
_WSContentSend(""); // Signal end of chunked content
WebServer->client().stop();
}
void WSContentStop(void)
{ {
if (WifiIsInManagerMode()) { if (WifiIsInManagerMode()) {
if (WifiConfigCounter()) { if (WifiConfigCounter()) {
@ -730,9 +747,7 @@ void WSContentEnd(void)
} }
} }
WSContentSend_P(HTTP_END, my_version); WSContentSend_P(HTTP_END, my_version);
WSContentFlush(); // Flush chunk buffer WSContentEnd();
_WSContentSend(""); // Signal end of chunked content
WebServer->client().stop();
} }
/*********************************************************************************************/ /*********************************************************************************************/
@ -762,7 +777,7 @@ void WebRestart(uint8_t type)
} else { } else {
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
} }
WSContentEnd(); WSContentStop();
ShowWebSource(SRC_WEBGUI); ShowWebSource(SRC_WEBGUI);
restart_flag = 2; restart_flag = 2;
@ -783,7 +798,7 @@ void HandleWifiLogin(void)
#endif // FIRMWARE_MINIMAL #endif // FIRMWARE_MINIMAL
} }
WSContentEnd(); WSContentStop();
} }
void HandleRoot(void) void HandleRoot(void)
@ -877,7 +892,7 @@ void HandleRoot(void)
WSContentButton(BUTTON_CONSOLE); WSContentButton(BUTTON_CONSOLE);
WSContentButton(BUTTON_RESTART); WSContentButton(BUTTON_RESTART);
} }
WSContentEnd(); WSContentStop();
} }
bool HandleRootStatusRefresh(void) bool HandleRootStatusRefresh(void)
@ -925,7 +940,7 @@ bool HandleRootStatusRefresh(void)
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{t}")); mqtt_data[0] = '\0';
XsnsCall(FUNC_WEB_APPEND); XsnsCall(FUNC_WEB_APPEND);
if (D_DECIMAL_SEPARATOR[0] != '.') { if (D_DECIMAL_SEPARATOR[0] != '.') {
for (uint16_t i = 0; i < strlen(mqtt_data); i++) { for (uint16_t i = 0; i < strlen(mqtt_data); i++) {
@ -934,28 +949,29 @@ bool HandleRootStatusRefresh(void)
} }
} }
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s</table>"), mqtt_data); char stemp[strlen(mqtt_data) +1];
memcpy(stemp, mqtt_data, sizeof(stemp));
WSContentBegin(200, CT_HTML);
WSContentSend_P(PSTR("{t}%s</table>"), stemp);
if (devices_present) { if (devices_present) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{t}<tr>"), mqtt_data); WSContentSend_P(PSTR("{t}<tr>"));
uint8_t fsize = (devices_present < 5) ? 70 - (devices_present * 8) : 32; uint8_t fsize = (devices_present < 5) ? 70 - (devices_present * 8) : 32;
if (SONOFF_IFAN02 == my_module_type) { if (SONOFF_IFAN02 == my_module_type) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_STATE, WSContentSend_P(HTTP_DEVICE_STATE, 36, (bitRead(power, 0)) ? "bold" : "normal", 54, GetStateText(bitRead(power, 0)));
mqtt_data, 36, (bitRead(power, 0)) ? "bold" : "normal", 54, GetStateText(bitRead(power, 0)));
uint8_t fanspeed = GetFanspeed(); uint8_t fanspeed = GetFanspeed();
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed); snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_STATE, WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
mqtt_data, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
} else { } else {
for (uint8_t idx = 1; idx <= devices_present; idx++) { for (uint8_t idx = 1; idx <= devices_present; idx++) {
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, idx -1)); snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, idx -1));
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_STATE, WSContentSend_P(HTTP_DEVICE_STATE, 100 / devices_present, (bitRead(power, idx -1)) ? "bold" : "normal", fsize, (devices_present < 5) ? GetStateText(bitRead(power, idx -1)) : svalue);
mqtt_data, 100 / devices_present, (bitRead(power, idx -1)) ? "bold" : "normal", fsize, (devices_present < 5) ? GetStateText(bitRead(power, idx -1)) : svalue);
} }
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s</tr></table>"), mqtt_data); WSContentSend_P(PSTR("</tr></table>"));
} }
WSHeaderSend(); WSContentEnd();
WSSend(200, CT_HTML, mqtt_data);
return true; return true;
} }
@ -987,7 +1003,7 @@ void HandleConfiguration(void)
WSContentButton(BUTTON_RESTORE); WSContentButton(BUTTON_RESTORE);
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
} }
/*-------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------*/
@ -1005,13 +1021,12 @@ void HandleTemplateConfiguration(void)
char stemp[20]; // Template number and Sensor name char stemp[20]; // Template number and Sensor name
if (WebServer->hasArg("m")) { if (WebServer->hasArg("m")) {
String page = ""; WSContentBegin(200, CT_PLAIN);
for (uint8_t i = 0; i < MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3" for (uint8_t i = 0; i < MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
uint8_t midx = pgm_read_byte(kModuleNiceList + i); uint8_t midx = pgm_read_byte(kModuleNiceList + i);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1); WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
page += mqtt_data;
} }
WSSend(200, CT_PLAIN, page); WSContentEnd();
return; return;
} }
@ -1025,32 +1040,26 @@ void HandleTemplateConfiguration(void)
gpio_flag flag = ModuleFlag(); gpio_flag flag = ModuleFlag();
Settings.module = module_save; Settings.module = module_save;
String page = AnyModuleName(module); // NAME: Generic WSContentBegin(200, CT_PLAIN);
page += F("}1"); // Field separator WSContentSend_P(PSTR("%s}1"), AnyModuleName(module).c_str()); // NAME: Generic
for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3... for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3...
if (1 == i) { if (1 == i) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MODULE_TEMPLATE_REPLACE, 255, D_SENSOR_USER, 255); // }2'255'>User (255)}3 WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, 255, D_SENSOR_USER, 255); // }2'255'>User (255)}3
page += mqtt_data;
} }
uint8_t midx = pgm_read_byte(kGpioNiceList + i); uint8_t midx = pgm_read_byte(kGpioNiceList + i);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx); WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx);
page += mqtt_data;
} }
page += F("}1"); // Field separator WSContentSend_P(PSTR("}1")); // Field separator
mqtt_data[0] = '\0';
for (uint8_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 for (uint8_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
if ((i < 6) || ((i > 8) && (i != 11))) { // Ignore flash pins GPIO06, 7, 8 and 11 if ((i < 6) || ((i > 8) && (i != 11))) { // Ignore flash pins GPIO06, 7, 8 and 11
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d"), mqtt_data, (i>0)?",":"", cmodule.io[i]); WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]);
} }
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}1%d}1%d"), mqtt_data, flag, Settings.user_template_base); // FLAG: 1 BASE: 17 WSContentSend_P(PSTR("}1%d}1%d"), flag, Settings.user_template_base); // FLAG: 1 BASE: 17
page += mqtt_data; WSContentEnd();
WSSend(200, CT_PLAIN, page);
return; return;
} }
@ -1078,7 +1087,7 @@ void HandleTemplateConfiguration(void)
WSContentSend_P(HTTP_FORM_TEMPLATE_FLAG); WSContentSend_P(HTTP_FORM_TEMPLATE_FLAG);
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void TemplateSaveSettings(void) void TemplateSaveSettings(void)
@ -1132,7 +1141,7 @@ void HandleModuleConfiguration(void)
ModuleGpios(&cmodule); ModuleGpios(&cmodule);
if (WebServer->hasArg("m")) { if (WebServer->hasArg("m")) {
String page = ""; WSContentBegin(200, CT_PLAIN);
uint8_t vidx = 0; uint8_t vidx = 0;
for (uint8_t i = 0; i <= MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3" for (uint8_t i = 0; i <= MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
if (0 == i) { if (0 == i) {
@ -1142,23 +1151,21 @@ void HandleModuleConfiguration(void)
midx = pgm_read_byte(kModuleNiceList + i -1); midx = pgm_read_byte(kModuleNiceList + i -1);
vidx = midx +1; vidx = midx +1;
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), vidx); WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), vidx);
page += mqtt_data;
} }
WSSend(200, CT_PLAIN, page); WSContentEnd();
return; return;
} }
if (WebServer->hasArg("g")) { if (WebServer->hasArg("g")) {
String page = ""; WSContentBegin(200, CT_PLAIN);
for (uint8_t j = 0; j < sizeof(kGpioNiceList); j++) { for (uint8_t j = 0; j < sizeof(kGpioNiceList); j++) {
midx = pgm_read_byte(kGpioNiceList + j); midx = pgm_read_byte(kGpioNiceList + j);
if (!GetUsedInModule(midx, cmodule.io)) { if (!GetUsedInModule(midx, cmodule.io)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx); WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx);
page += mqtt_data;
} }
} }
WSSend(200, CT_PLAIN, page); WSContentEnd();
return; return;
} }
@ -1185,7 +1192,7 @@ void HandleModuleConfiguration(void)
WSContentSend_P(PSTR("</table>")); WSContentSend_P(PSTR("</table>"));
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void ModuleSaveSettings(void) void ModuleSaveSettings(void)
@ -1327,7 +1334,7 @@ void HandleWifiConfiguration(void)
} else { } else {
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
} }
WSContentEnd(); WSContentStop();
} }
void WifiSaveSettings(void) void WifiSaveSettings(void)
@ -1386,7 +1393,7 @@ void HandleLoggingConfiguration(void)
WSContentSend_P(HTTP_FORM_LOG2, Settings.syslog_host, Settings.syslog_port, Settings.tele_period); WSContentSend_P(HTTP_FORM_LOG2, Settings.syslog_host, Settings.syslog_port, Settings.tele_period);
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void LoggingSaveSettings(void) void LoggingSaveSettings(void)
@ -1462,7 +1469,7 @@ void HandleOtherConfiguration(void)
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void OtherSaveSettings(void) void OtherSaveSettings(void)
@ -1558,7 +1565,7 @@ void HandleResetConfiguration(void)
WSContentSend_P(PSTR("<div style='text-align:center;'>" D_CONFIGURATION_RESET "</div>")); WSContentSend_P(PSTR("<div style='text-align:center;'>" D_CONFIGURATION_RESET "</div>"));
WSContentSend_P(HTTP_MSG_RSTRT); WSContentSend_P(HTTP_MSG_RSTRT);
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
char command[CMDSZ]; char command[CMDSZ];
snprintf_P(command, sizeof(command), PSTR(D_CMND_RESET " 1")); snprintf_P(command, sizeof(command), PSTR(D_CMND_RESET " 1"));
@ -1576,7 +1583,7 @@ void HandleRestoreConfiguration(void)
WSContentSend_P(HTTP_FORM_RST); WSContentSend_P(HTTP_FORM_RST);
WSContentSend_P(HTTP_FORM_RST_UPG, D_RESTORE); WSContentSend_P(HTTP_FORM_RST_UPG, D_RESTORE);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
upload_error = 0; upload_error = 0;
upload_file_type = UPL_SETTINGS; upload_file_type = UPL_SETTINGS;
@ -1678,7 +1685,7 @@ void HandleInformation(void)
"<div id='i' name='i'></div>")); "<div id='i' name='i'></div>"));
// WSContentSend_P(PSTR("</fieldset>")); // WSContentSend_P(PSTR("</fieldset>"));
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
} }
#endif // Not FIRMWARE_MINIMAL #endif // Not FIRMWARE_MINIMAL
@ -1695,7 +1702,7 @@ void HandleUpgradeFirmware(void)
WSContentSend_P(HTTP_FORM_UPG, Settings.ota_url); WSContentSend_P(HTTP_FORM_UPG, Settings.ota_url);
WSContentSend_P(HTTP_FORM_RST_UPG, D_UPGRADE); WSContentSend_P(HTTP_FORM_RST_UPG, D_UPGRADE);
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
upload_error = 0; upload_error = 0;
upload_file_type = UPL_TASMOTA; upload_file_type = UPL_TASMOTA;
@ -1723,7 +1730,7 @@ void HandleUpgradeFirmwareStart(void)
WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPGRADE_STARTED " ...</b></div>")); WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPGRADE_STARTED " ...</b></div>"));
WSContentSend_P(HTTP_MSG_RSTRT); WSContentSend_P(HTTP_MSG_RSTRT);
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
snprintf_P(command, sizeof(command), PSTR(D_CMND_UPGRADE " 1")); snprintf_P(command, sizeof(command), PSTR(D_CMND_UPGRADE " 1"));
ExecuteWebCommand(command, SRC_WEBGUI); ExecuteWebCommand(command, SRC_WEBGUI);
@ -1770,7 +1777,7 @@ void HandleUploadDone(void)
SettingsBufferFree(); SettingsBufferFree();
WSContentSend_P(PSTR("</div><br/>")); WSContentSend_P(PSTR("</div><br/>"));
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
} }
void HandleUploadLoop(void) void HandleUploadLoop(void)
@ -1990,7 +1997,7 @@ void HandleHttpCommand(void)
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, Settings.web_password))) { valid = 0; } if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, Settings.web_password))) { valid = 0; }
} }
String message = F("{\"" D_RSLT_WARNING "\":\""); WSContentBegin(200, CT_JSON);
if (valid) { if (valid) {
uint8_t curridx = web_log_index; uint8_t curridx = web_log_index;
String svalue = WebServer->arg("cmnd"); String svalue = WebServer->arg("cmnd");
@ -1998,7 +2005,8 @@ void HandleHttpCommand(void)
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND); ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND);
if (web_log_index != curridx) { if (web_log_index != curridx) {
uint8_t counter = curridx; uint8_t counter = curridx;
message = F("{"); WSContentSend_P(PSTR("{"));
bool cflg = false;
do { do {
char* tmp; char* tmp;
size_t len; size_t len;
@ -2007,28 +2015,28 @@ void HandleHttpCommand(void)
// [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}] // [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}]
char* JSON = (char*)memchr(tmp, '{', len); char* JSON = (char*)memchr(tmp, '{', len);
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O]) if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
if (message.length() > 1) { message += F(","); }
size_t JSONlen = len - (JSON - tmp); size_t JSONlen = len - (JSON - tmp);
if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); } if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); }
strlcpy(mqtt_data, JSON +1, JSONlen -2); char stemp[JSONlen];
message += mqtt_data; strlcpy(stemp, JSON +1, JSONlen -2);
WSContentSend_P(PSTR("%s%s"), (cflg) ? "," : "", stemp);
cflg = true;
} }
} }
counter++; counter++;
if (!counter) counter++; // Skip 0 as it is not allowed if (!counter) counter++; // Skip 0 as it is not allowed
} while (counter != web_log_index); } while (counter != web_log_index);
message += F("}"); WSContentSend_P(PSTR("}"));
} else { } else {
message += F(D_ENABLE_WEBLOG_FOR_RESPONSE "\"}"); WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}"));
} }
} else { } else {
message += F(D_ENTER_COMMAND " cmnd=\"}"); WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENTER_COMMAND " cmnd=\"}"));
} }
} else { } else {
message += F(D_NEED_USER_AND_PASSWORD "\"}"); WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_NEED_USER_AND_PASSWORD "\"}"));
} }
WSHeaderSend(); WSContentEnd();
WSSend(200, CT_JSON, message);
} }
/*-------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------*/
@ -2049,7 +2057,7 @@ void HandleConsole(void)
WSContentSendStyle(); WSContentSendStyle();
WSContentSend_P(HTTP_FORM_CMND); WSContentSend_P(HTTP_FORM_CMND);
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentEnd(); WSContentStop();
} }
void HandleConsoleRefresh(void) void HandleConsoleRefresh(void)
@ -2067,10 +2075,8 @@ void HandleConsoleRefresh(void)
WebGetArg("c2", stmp, sizeof(stmp)); WebGetArg("c2", stmp, sizeof(stmp));
if (strlen(stmp)) { counter = atoi(stmp); } if (strlen(stmp)) { counter = atoi(stmp); }
bool last_reset_web_log_flag = reset_web_log_flag; WSContentBegin(200, CT_PLAIN);
// mqtt_data used as scratch space WSContentSend_P(PSTR("%d}1%d}1"), web_log_index, reset_web_log_flag);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%d}1%d}1"), web_log_index, last_reset_web_log_flag);
String message = mqtt_data;
if (!reset_web_log_flag) { if (!reset_web_log_flag) {
counter = 0; counter = 0;
reset_web_log_flag = true; reset_web_log_flag = true;
@ -2085,21 +2091,18 @@ void HandleConsoleRefresh(void)
size_t len; size_t len;
GetLog(counter, &tmp, &len); GetLog(counter, &tmp, &len);
if (len) { if (len) {
if (cflg) {
message += F("\n");
} else {
cflg = true;
}
if (len > sizeof(mqtt_data) -2) { len = sizeof(mqtt_data); } if (len > sizeof(mqtt_data) -2) { len = sizeof(mqtt_data); }
strlcpy(mqtt_data, tmp, len); char stemp[len +1];
message += mqtt_data; // mqtt_data used as scratch space strlcpy(stemp, tmp, len);
WSContentSend_P(PSTR("%s%s"), (cflg) ? "\n" : "", stemp);
cflg = true;
} }
counter++; counter++;
if (!counter) { counter++; } // Skip log index 0 as it is not allowed if (!counter) { counter++; } // Skip log index 0 as it is not allowed
} while (counter != web_log_index); } while (counter != web_log_index);
} }
message += F("}1"); WSContentSend_P(PSTR("}1"));
WSSend(200, CT_PLAIN, message); WSContentEnd();
} }
/********************************************************************************************/ /********************************************************************************************/

View File

@ -18,7 +18,6 @@
*/ */
#define XDRV_02 2 #define XDRV_02 2
/*********************************************************************************************/
#ifdef USE_MQTT_TLS #ifdef USE_MQTT_TLS
#ifdef USE_MQTT_TLS_CA_CERT #ifdef USE_MQTT_TLS_CA_CERT
@ -441,13 +440,11 @@ void MqttReconnect(void)
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT); GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_OFFLINE); snprintf_P(mqtt_data, sizeof(mqtt_data), S_OFFLINE);
//#ifdef ARDUINO_ESP8266_RELEASE_2_4_1
#ifdef USE_MQTT_TLS #ifdef USE_MQTT_TLS
EspClient = WiFiClientSecure(); // Wifi Secure Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497) EspClient = WiFiClientSecure(); // Wifi Secure Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497)
#else #else
EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497) EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497)
#endif #endif
//#endif
if (2 == mqtt_initial_connection_state) { // Executed once just after power on and wifi is connected if (2 == mqtt_initial_connection_state) { // Executed once just after power on and wifi is connected
#ifdef USE_MQTT_TLS #ifdef USE_MQTT_TLS
@ -777,7 +774,7 @@ void HandleMqttConfiguration(void)
Settings.mqtt_fulltopic); Settings.mqtt_fulltopic);
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void MqttSaveSettings(void) void MqttSaveSettings(void)

View File

@ -482,7 +482,7 @@ void HandleDomoticzConfiguration(void)
WSContentSend_P(PSTR("</table>")); WSContentSend_P(PSTR("</table>"));
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void DomoticzSaveSettings(void) void DomoticzSaveSettings(void)

View File

@ -721,7 +721,7 @@ void HandleTimerConfiguration(void)
WSContentSend_P(HTTP_FORM_TIMER4); WSContentSend_P(HTTP_FORM_TIMER4);
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void TimerSaveSettings(void) void TimerSaveSettings(void)

View File

@ -934,7 +934,7 @@ void HandleKNXConfiguration(void)
WSContentSend_P(PSTR("</table></center></fieldset>")); WSContentSend_P(PSTR("</table></center></fieldset>"));
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
} }

View File

@ -434,7 +434,7 @@ void HandleHxAction(void)
WSContentSend_P(HTTP_FORM_HX711, stemp1, stemp2); WSContentSend_P(HTTP_FORM_HX711, stemp1, stemp2);
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentEnd(); WSContentStop();
} }
void HxSaveSettings(void) void HxSaveSettings(void)