diff --git a/esp-link/cgiservices.c b/esp-link/cgiadv/cgiservices.c similarity index 96% rename from esp-link/cgiservices.c rename to esp-link/cgiadv/cgiservices.c index c42fd96..d13ad12 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiadv/cgiservices.c @@ -4,6 +4,7 @@ #include "config.h" #include "sntp.h" #include "cgimqtt.h" +#include "stringdefs.h" #ifdef SYSLOG #include "syslog.h" @@ -15,15 +16,6 @@ #define DBG(format, ...) do { } while(0) #endif -char* rst_codes[7] = { - "normal", "wdt reset", "exception", "soft wdt", "restart", "deep sleep", "external", -}; - -char* flash_maps[7] = { - "512KB:256/256", "256KB", "1MB:512/512", "2MB:512/512", "4MB:512/512", - "2MB:1024/1024", "4MB:1024/1024" -}; - static ETSTimer reassTimer; // Cgi to update system info (name/description) diff --git a/esp-link/cgiservices.h b/esp-link/cgiadv/cgiservices.h similarity index 84% rename from esp-link/cgiservices.h rename to esp-link/cgiadv/cgiservices.h index 9c44242..d27fc6d 100644 --- a/esp-link/cgiservices.h +++ b/esp-link/cgiadv/cgiservices.h @@ -10,7 +10,4 @@ void cgiServicesSNTPInit(); int cgiServicesInfo(HttpdConnData *connData); int cgiServicesSet(HttpdConnData *connData); -extern char* rst_codes[7]; -extern char* flash_maps[7]; - #endif // CGISERVICES_H diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 50ea536..239fd46 100755 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -18,7 +18,10 @@ Cgi/template routines for the /wifi url. #include "cgi.h" #include "status.h" #include "config.h" + +#ifdef LOG #include "log.h" +#endif #ifdef CGIWIFI_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -315,7 +318,9 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only #endif } +#ifdef LOG log_uart(false); +#endif // no more resetTimer at this point, gotta use physical reset to recover if in trouble } else { if (m != 3) { @@ -323,7 +328,9 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { wifi_set_opmode(3); wifi_softap_set_config(&apconf); } +#ifdef LOG log_uart(true); +#endif DBG("Enabling/continuing uart log\n"); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); } diff --git a/esp-link/main.c b/esp-link/main.c index e7a65f1..ee4d163 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -14,27 +14,40 @@ #include "httpdespfs.h" #include "cgi.h" #include "cgiwifi.h" -#include "cgipins.h" -#include "cgitcp.h" #include "cgimqtt.h" #include "cgiflash.h" -#include "cgioptiboot.h" #include "auth.h" #include "espfs.h" #include "uart.h" -#include "serbridge.h" #include "status.h" #include "serled.h" -#include "console.h" #include "config.h" -#include "log.h" #include "gpio.h" -#include "cgiservices.h" +#include "stringdefs.h" + +#ifdef LOG +#include "log.h" +#endif #ifdef SYSLOG #include "syslog.h" #endif +#ifdef CONSOLE +#include "console.h" +#endif + +#ifdef SERIAL_BRIDGE +#include "serbridge.h" +#endif + +#ifdef CGI_ADVANCED +#include "cgiservices.h" +#include "cgipins.h" +#include "cgitcp.h" +#include "cgioptiboot.h" +#endif + #define NOTICE(format, ...) do { \ LOG_NOTICE(format, ## __VA_ARGS__ ); \ os_printf(format "\n", ## __VA_ARGS__); \ @@ -56,15 +69,26 @@ HttpdBuiltInUrl builtInUrls[] = { { "/flash/next", cgiGetFirmwareNext, NULL }, { "/flash/upload", cgiUploadFirmware, NULL }, { "/flash/reboot", cgiRebootFirmware, NULL }, +#ifdef CGI_ADVANCED { "/pgm/sync", cgiOptibootSync, NULL }, { "/pgm/upload", cgiOptibootData, NULL }, + { "/pins", cgiPins, NULL }, + { "/system/info", cgiSystemInfo, NULL }, + { "/system/update", cgiSystemSet, NULL }, + { "/services/info", cgiServicesInfo, NULL }, + { "/services/update", cgiServicesSet, NULL }, +#endif +#ifdef LOG { "/log/text", ajaxLog, NULL }, { "/log/dbg", ajaxLogDbg, NULL }, { "/log/reset", cgiReset, NULL }, +#endif +#ifdef CONSOLE { "/console/reset", ajaxConsoleReset, NULL }, { "/console/baud", ajaxConsoleBaud, NULL }, { "/console/text", ajaxConsole, NULL }, { "/console/send", ajaxConsoleSend, NULL }, +#endif //Enable the line below to protect the WiFi configuration with an username/password combo. // {"/wifi/*", authBasic, myPassFn}, { "/wifi", cgiRedirect, "/wifi/wifi.html" }, @@ -77,11 +101,6 @@ HttpdBuiltInUrl builtInUrls[] = { { "/wifi/special", cgiWiFiSpecial, NULL }, { "/wifi/apinfo", cgiApSettingsInfo, NULL }, { "/wifi/apchange", cgiApSettingsChange, NULL }, - { "/system/info", cgiSystemInfo, NULL }, - { "/system/update", cgiSystemSet, NULL }, - { "/services/info", cgiServicesInfo, NULL }, - { "/services/update", cgiServicesSet, NULL }, - { "/pins", cgiPins, NULL }, #ifdef MQTT { "/mqtt", cgiMqtt, NULL }, #endif @@ -121,7 +140,9 @@ void user_init(void) { gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled // init UART uart_init(flashConfig.baud_rate, 115200); +#ifdef LOG logInit(); // must come after init of uart +#endif // Say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); os_printf("\n\n** %s\n", esp_link_version); @@ -142,9 +163,11 @@ void user_init(void) { #endif // mount the http handlers httpdInit(builtInUrls, 80); +#ifdef SERIAL_BRIDGE // init the wifi-serial transparent bridge (port 23) serbridgeInit(23, 2323); uart_add_recv_cb(&serbridgeUartCb); +#endif #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); @@ -161,8 +184,10 @@ void user_init(void) { fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); NOTICE("** esp-link ready"); +#ifdef CGI_ADVANCED // Init SNTP service cgiServicesSNTPInit(); +#endif #ifdef MQTT NOTICE("initializing MQTT"); mqtt_client_init(); diff --git a/esp-link/stringdefs.c b/esp-link/stringdefs.c new file mode 100644 index 0000000..131b65a --- /dev/null +++ b/esp-link/stringdefs.c @@ -0,0 +1,8 @@ +const char* const rst_codes[7] = { + "normal", "wdt reset", "exception", "soft wdt", "restart", "deep sleep", "external", +}; + +const char* const flash_maps[7] = { + "512KB:256/256", "256KB", "1MB:512/512", "2MB:512/512", "4MB:512/512", + "2MB:1024/1024", "4MB:1024/1024" +}; \ No newline at end of file diff --git a/esp-link/stringdefs.h b/esp-link/stringdefs.h new file mode 100644 index 0000000..40733a7 --- /dev/null +++ b/esp-link/stringdefs.h @@ -0,0 +1,2 @@ +extern const char* const rst_codes[7]; +extern const char* const flash_maps[7]; \ No newline at end of file diff --git a/serial/console/console.c b/serial/console/console.c index 68b5b55..1f68dbd 100644 --- a/serial/console/console.c +++ b/serial/console/console.c @@ -4,10 +4,14 @@ #include "uart.h" #include "cgi.h" #include "uart.h" -#include "serbridge.h" #include "config.h" #include "console.h" +#ifdef SERIAL_BRIDGE +#include "serbridge.h" +#endif + + // Microcontroller console capturing the last 1024 characters received on the uart so // they can be shown on a web page @@ -54,7 +58,9 @@ ajaxConsoleReset(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. jsonHeader(connData, 200); console_rd = console_wr = console_pos = 0; +#ifdef SERIAL_BRIDGE serbridgeReset(); +#endif return HTTPD_CGI_DONE; }