diff --git a/user/config_flash.c b/user/config_flash.c index 0926241..2fd098b 100644 --- a/user/config_flash.c +++ b/user/config_flash.c @@ -156,6 +156,9 @@ uint32_t reg0, reg1, reg3; os_sprintf(config->ota_host,"%s", "none"); config->ota_port = 80; #endif +#if WEB_ALT_PAGE + config->alt_web[0] = '\0'; // default none +#endif } int ICACHE_FLASH_ATTR config_load(sysconfig_p config) diff --git a/user/config_flash.h b/user/config_flash.h index ac02a7e..0342c8b 100644 --- a/user/config_flash.h +++ b/user/config_flash.h @@ -135,6 +135,9 @@ typedef struct { uint8_t ota_host[64]; uint16_t ota_port; #endif +#if WEB_ALT_PAGE + uint8_t alt_web[256]; // user defined body of web page +#endif } sysconfig_t, *sysconfig_p; int config_load(sysconfig_p config); diff --git a/user/user_config.h b/user/user_config.h index 68b8cc6..3f4dfd5 100644 --- a/user/user_config.h +++ b/user/user_config.h @@ -77,6 +77,10 @@ // #define WEB_CONFIG 1 #define WEB_CONFIG_PORT 80 +// +// Define this to 1 if you want to be able to display a user defined web page. +// +#define WEB_ALT_PAGE 1 // // Define this to 1 if you want to have ACLs for the SoftAP. @@ -140,7 +144,7 @@ // Define this to 1 to support an ENC28J60 Ethernet interface // Experimental feature - not yet stable // -#define HAVE_ENC28J60 1 +#define HAVE_ENC28J60 0 // // Define this to 1 to support ENC28J60 DHCP server diff --git a/user/user_main.c b/user/user_main.c index dce205c..74f264e 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -2063,6 +2063,20 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) os_sprintf(response, "Web port set to %d\r\n", config.web_port); goto command_handled; } +#if WEB_ALT_PAGE + if (strcmp(tokens[1], "alt_web") == 0) + { + if (strcmp(tokens[2],"none") == 0) { + config.alt_web[0] = '\0'; + os_sprintf_flash(response, "Alternative web page cleared\r\n"); + goto command_handled; + } + os_strncpy(config.alt_web, tokens[2], sizeof(config.alt_web)-1); + config.alt_web[sizeof(config.alt_web)-1] = '\0'; + os_sprintf_flash(response, "Alternative web page set\r\n"); + goto command_handled; + } +#endif #endif #if DAILY_LIMIT if (strcmp(tokens[1],"daily_limit") == 0) @@ -2712,7 +2726,28 @@ static void ICACHE_FLASH_ATTR web_config_client_connected_cb(void *arg) ringbuf_reset(console_rx_buffer); ringbuf_reset(console_tx_buffer); - if (!config.locked) { +#if WEB_ALT_PAGE + if (config.alt_web[0] != '\0') { + static const uint8_t alt_page_str[] ICACHE_RODATA_ATTR STORE_ATTR = ALT_PAGE; + uint32_t slen = (sizeof(alt_page_str) + 4) & ~3; + uint8_t *alt_page = (char *)os_malloc(slen); + if (alt_page == NULL) + return; + os_memcpy(alt_page, alt_page_str, slen); + + uint8_t *page_buf = (char *)os_malloc(slen+sizeof(config.alt_web)); + if (page_buf == NULL) + return; + os_sprintf(page_buf, alt_page, config.alt_web); + os_free(alt_page); + + espconn_send(pespconn, page_buf, os_strlen(page_buf)); + + os_free(page_buf); + } + else +#endif + if (!config.locked) { static const uint8_t config_page_str[] ICACHE_RODATA_ATTR STORE_ATTR = CONFIG_PAGE; uint32_t slen = (sizeof(config_page_str) + 4) & ~3; uint8_t *config_page = (char *)os_malloc(slen); diff --git a/user/web.h b/user/web.h index 5ff2460..d7113fe 100644 --- a/user/web.h +++ b/user/web.h @@ -133,3 +133,14 @@ setTimeout(\"location.href = '/'\",1000);\ \ \ " + +#if WEB_ALT_PAGE +#define ALT_PAGE "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n\ +\ +\ +\ +%s\ +\ +\ +" +#endif