From 47bd1ac5988e5eece1a19cb85cc3c8e212b530b2 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 18:44:48 -0700 Subject: [PATCH 1/8] Change Makefile to use SDK 1.5.4 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 523f85f..4138886 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ CHANGE_TO_STA ?= yes # hostname or IP address for wifi flashing -ESP_HOSTNAME ?= esp-link +ESP_HOSTNAME ?= esp-link # --------------- toolchain configuration --------------- @@ -57,7 +57,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/ # Firmware version # WARNING: if you change this expect to make code adjustments elsewhere, don't expect # that esp-link will magically work with a different version of the SDK!!! -SDK_VERS ?= esp_iot_sdk_v1.5.2 +SDK_VERS ?= esp_iot_sdk_v1.5.4 # Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS, # http://bbs.espressif.com/viewforum.php?f=46 From 38f5376196c8cde96177f2dc4b4ac9f2742913d0 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 19:41:45 -0700 Subject: [PATCH 2/8] Pull in contributions from #121 --- httpd/httpd.c | 30 ++++++++++++++++++------------ httpd/httpd.h | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/httpd/httpd.c b/httpd/httpd.c index 5590809..f3c5594 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -44,6 +44,7 @@ struct HttpdPriv { char *sendBuff; // output buffer short headPos; // offset into header short sendBuffLen; // offset into output buffer + short sendBuffMax; // size of output buffer short code; // http response code (only for logging) }; @@ -226,6 +227,13 @@ int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *re return 0; } +//Setup an output buffer +void ICACHE_FLASH_ATTR httpdSetOutputBuffer(HttpdConnData *conn, char *buff, short max) { + conn->priv->sendBuff = buff; + conn->priv->sendBuffLen = 0; + conn->priv->sendBuffMax = max; +} + //Start the response headers. void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code) { char buff[128]; @@ -277,9 +285,9 @@ int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) { //Returns 1 for success, 0 for out-of-memory. int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) { if (len<0) len = strlen(data); - if (conn->priv->sendBuffLen + len>MAX_SENDBUFF_LEN) { + if (conn->priv->sendBuffLen + len>conn->priv->sendBuffMax) { DBG("%sERROR! httpdSend full (%d of %d)\n", - connStr, conn->priv->sendBuffLen, MAX_SENDBUFF_LEN); + connStr, conn->priv->sendBuffLen, conn->priv->sendBuffMax); return 0; } os_memcpy(conn->priv->sendBuff + conn->priv->sendBuffLen, data, len); @@ -288,7 +296,7 @@ int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) } //Helper function to send any data in conn->priv->sendBuff -static void ICACHE_FLASH_ATTR xmitSendBuff(HttpdConnData *conn) { +void ICACHE_FLASH_ATTR httpdFlush(HttpdConnData *conn) { if (conn->priv->sendBuffLen != 0) { sint8 status = espconn_sent(conn->conn, (uint8_t*)conn->priv->sendBuff, conn->priv->sendBuffLen); if (status != 0) { @@ -307,13 +315,12 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) { if (conn == NULL) return; // aborted connection char sendBuff[MAX_SENDBUFF_LEN]; - conn->priv->sendBuff = sendBuff; - conn->priv->sendBuffLen = 0; + httpdSetOutputBuffer(conn, sendBuff, sizeof(sendBuff)); if (conn->cgi == NULL) { //Marked for destruction? //os_printf("Closing 0x%p/0x%p->0x%p\n", arg, conn->conn, conn); espconn_disconnect(conn->conn); // we will get a disconnect callback - return; //No need to call xmitSendBuff. + return; //No need to call httpdFlush. } int r = conn->cgi(conn); //Execute cgi fn. @@ -324,7 +331,7 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) { DBG("%sERROR! Bad CGI code %d\n", connStr, r); conn->cgi = NULL; //mark for destruction. } - xmitSendBuff(conn); + httpdFlush(conn); } static const char *httpNotFoundHeader = "HTTP/1.0 404 Not Found\r\nConnection: close\r\n" @@ -366,7 +373,7 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) { //generate a built-in 404 to handle this. DBG("%s%s not found. 404!\n", connStr, conn->url); httpdSend(conn, httpNotFoundHeader, -1); - xmitSendBuff(conn); + httpdFlush(conn); conn->cgi = NULL; //mark for destruction. if (conn->post) conn->post->len = 0; // skip any remaining receives return; @@ -378,12 +385,12 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) { r = conn->cgi(conn); if (r == HTTPD_CGI_MORE) { //Yep, it's happy to do so and has more data to send. - xmitSendBuff(conn); + httpdFlush(conn); return; } else if (r == HTTPD_CGI_DONE) { //Yep, it's happy to do so and already is done sending data. - xmitSendBuff(conn); + httpdFlush(conn); conn->cgi = NULL; //mark for destruction. if (conn->post) conn->post->len = 0; // skip any remaining receives return; @@ -485,8 +492,7 @@ static void ICACHE_FLASH_ATTR httpdRecvCb(void *arg, char *data, unsigned short if (conn == NULL) return; // aborted connection char sendBuff[MAX_SENDBUFF_LEN]; - conn->priv->sendBuff = sendBuff; - conn->priv->sendBuffLen = 0; + httpdSetOutputBuffer(conn, sendBuff, sizeof(sendBuff)); //This is slightly evil/dirty: we abuse conn->post->len as a state variable for where in the http communications we are: //<0 (-1): Post len unknown because we're still receiving headers diff --git a/httpd/httpd.h b/httpd/httpd.h index cca6f32..33a0700 100644 --- a/httpd/httpd.h +++ b/httpd/httpd.h @@ -59,10 +59,12 @@ int httpdUrlDecode(char *val, int valLen, char *ret, int retLen); int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen); void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port); const char *httpdGetMimetype(char *url); +void ICACHE_FLASH_ATTR httpdSetOutputBuffer(HttpdConnData *conn, char *buff, short max); void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code); void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val); void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn); int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen); int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len); +void ICACHE_FLASH_ATTR httpdFlush(HttpdConnData *conn); #endif From f84ffdc98951f0b46c7d0b9b0d47b3e8f24619db Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 20:03:42 -0700 Subject: [PATCH 3/8] Allow syslog to be disabled, as in #128 --- Makefile | 2 +- esp-link/cgiservices.c | 20 ++++++++++++++------ esp-link/main.c | 14 ++++++++++---- html/services.js | 3 ++- serial/serbridge.c | 4 ++++ 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 4138886..fb58cb1 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ LED_SERIAL_PIN ?= 14 # --------------- esp-link modules config options --------------- # Optional Modules mqtt -MODULES ?= mqtt rest syslog +MODULES ?= mqtt rest #syslog # --------------- esphttpd config options --------------- diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 6b3f553..200039d 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -2,9 +2,11 @@ #include "cgiwifi.h" #include "cgi.h" #include "config.h" -#include "syslog.h" #include "sntp.h" #include "cgimqtt.h" +#ifdef SYSLOG +#include "syslog.h" +#endif #ifdef CGISERVICES_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -92,10 +94,10 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { } void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { - if (flashConfig.sntp_server[0] != '\0') { + if (flashConfig.sntp_server[0] != '\0') { sntp_stop(); if (true == sntp_set_timezone(flashConfig.timezone_offset)) { - sntp_setservername(0, flashConfig.sntp_server); + sntp_setservername(0, flashConfig.sntp_server); sntp_init(); } DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset); @@ -107,23 +109,27 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - os_sprintf(buff, + os_sprintf(buff, "{ " +#ifdef SYSLOG "\"syslog_host\": \"%s\", " "\"syslog_minheap\": %d, " "\"syslog_filter\": %d, " "\"syslog_showtick\": \"%s\", " "\"syslog_showdate\": \"%s\", " +#endif "\"timezone_offset\": %d, " "\"sntp_server\": \"%s\", " "\"mdns_enable\": \"%s\", " "\"mdns_servername\": \"%s\"" - " }", + " }", +#ifdef SYSLOG flashConfig.syslog_host, flashConfig.syslog_minheap, flashConfig.syslog_filter, flashConfig.syslog_showtick ? "enabled" : "disabled", flashConfig.syslog_showdate ? "enabled" : "disabled", +#endif flashConfig.timezone_offset, flashConfig.sntp_server, flashConfig.mdns_enable ? "enabled" : "disabled", @@ -151,9 +157,11 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { syslog |= getBoolArg(connData, "syslog_showdate", &flashConfig.syslog_showdate); if (syslog < 0) return HTTPD_CGI_DONE; +#ifdef SYSLOG if (syslog > 0) { syslog_init(flashConfig.syslog_host); } +#endif int8_t sntp = 0; sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset); @@ -168,7 +176,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { int8_t mdns = 0; mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); if (mdns < 0) return HTTPD_CGI_DONE; - + if (mdns > 0) { if (flashConfig.mdns_enable){ DBG("Services: MDNS Enabled\n"); diff --git a/esp-link/main.c b/esp-link/main.c index bf8c6ef..ba2cf8d 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -29,13 +29,19 @@ #include "config.h" #include "log.h" #include "gpio.h" -#include "syslog.h" #include "cgiservices.h" -#define NOTICE(format, ...) do { \ - LOG_NOTICE(format, ## __VA_ARGS__ ); \ - os_printf(format "\n", ## __VA_ARGS__); \ +#ifdef SYSLOG +#include "syslog.h" +#define NOTICE(format, ...) do { \ + LOG_NOTICE(format, ## __VA_ARGS__ ); \ + os_printf(format "\n", ## __VA_ARGS__); \ } while ( 0 ) +#else +#define NOTICE(format, ...) do { \ + os_printf(format "\n", ## __VA_ARGS__); \ +} while ( 0 ) +#endif /* This is the main url->function dispatching data struct. diff --git a/html/services.js b/html/services.js index 17075ff..aedeea3 100644 --- a/html/services.js +++ b/html/services.js @@ -51,7 +51,8 @@ function displayServices(data) { $("#sntp-spinner").setAttribute("hidden", ""); $("#mdns-spinner").setAttribute("hidden", ""); - $("#Syslog-form").removeAttribute("hidden"); + if (data.syslog_host !== undefined) + $("#Syslog-form").removeAttribute("hidden"); $("#SNTP-form").removeAttribute("hidden"); $("#mDNS-form").removeAttribute("hidden"); diff --git a/serial/serbridge.c b/serial/serbridge.c index 1e82e3d..66b180c 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -10,7 +10,11 @@ #include "console.h" #include "slip.h" #include "cmd.h" +#ifdef SYSLOG #include "syslog.h" +#else +#define syslog(X1...) +#endif #define SKIP_AT_RESET From 52843c6316b28b4c76b4875a98e2725de0c446c9 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 20:07:40 -0700 Subject: [PATCH 4/8] Fix some type casts per #129 --- esp-link/cgimqtt.c | 12 ++++++------ esp-link/cgiservices.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/esp-link/cgimqtt.c b/esp-link/cgimqtt.c index 88aa6ed..9e71b1a 100644 --- a/esp-link/cgimqtt.c +++ b/esp-link/cgimqtt.c @@ -95,11 +95,11 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { if (mqtt_server < 0) return HTTPD_CGI_DONE; mqtt_server |= getBoolArg(connData, "mqtt-clean-session", - &flashConfig.mqtt_clean_session); + (bool *)&flashConfig.mqtt_clean_session); if (mqtt_server < 0) return HTTPD_CGI_DONE; int8_t mqtt_en_chg = getBoolArg(connData, "mqtt-enable", - &flashConfig.mqtt_enable); + (bool *)&flashConfig.mqtt_enable); char buff[16]; @@ -134,7 +134,7 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { mqtt_client_init(); // if just enable changed we just need to bounce the client - } + } else if (mqtt_en_chg > 0) { DBG("MQTT server enable=%d changed\n", flashConfig.mqtt_enable); if (flashConfig.mqtt_enable && strlen(flashConfig.mqtt_host) > 0) @@ -145,16 +145,16 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { // no action required if mqtt status settings change, they just get picked up at the // next status tick - if (getBoolArg(connData, "mqtt-status-enable", &flashConfig.mqtt_status_enable) < 0) + if (getBoolArg(connData, "mqtt-status-enable", (bool *)&flashConfig.mqtt_status_enable) < 0) return HTTPD_CGI_DONE; if (getStringArg(connData, "mqtt-status-topic", flashConfig.mqtt_status_topic, sizeof(flashConfig.mqtt_status_topic)) < 0) return HTTPD_CGI_DONE; // if SLIP-enable is toggled it gets picked-up immediately by the parser - int slip_update = getBoolArg(connData, "slip-enable", &flashConfig.slip_enable); + int slip_update = getBoolArg(connData, "slip-enable", (bool *)&flashConfig.slip_enable); if (slip_update < 0) return HTTPD_CGI_DONE; - if (slip_update > 0) + if (slip_update > 0) DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable); DBG("Saving config\n"); diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 200039d..8d3c678 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -152,9 +152,9 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { if (syslog < 0) return HTTPD_CGI_DONE; syslog |= getUInt8Arg(connData, "syslog_filter", &flashConfig.syslog_filter); if (syslog < 0) return HTTPD_CGI_DONE; - syslog |= getBoolArg(connData, "syslog_showtick", &flashConfig.syslog_showtick); + syslog |= getBoolArg(connData, "syslog_showtick", (bool *)&flashConfig.syslog_showtick); if (syslog < 0) return HTTPD_CGI_DONE; - syslog |= getBoolArg(connData, "syslog_showdate", &flashConfig.syslog_showdate); + syslog |= getBoolArg(connData, "syslog_showdate", (bool *)&flashConfig.syslog_showdate); if (syslog < 0) return HTTPD_CGI_DONE; #ifdef SYSLOG @@ -174,7 +174,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { } int8_t mdns = 0; - mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); + mdns |= getBoolArg(connData, "mdns_enable", (bool *)&flashConfig.mdns_enable); if (mdns < 0) return HTTPD_CGI_DONE; if (mdns > 0) { From 3403e583f28f9a0d4f35c6a6266b989d3a666f7d Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 22:40:09 -0700 Subject: [PATCH 5/8] Fix not showing syslog card when disabled --- html/services.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/html/services.js b/html/services.js index aedeea3..3f16975 100644 --- a/html/services.js +++ b/html/services.js @@ -51,8 +51,12 @@ function displayServices(data) { $("#sntp-spinner").setAttribute("hidden", ""); $("#mdns-spinner").setAttribute("hidden", ""); - if (data.syslog_host !== undefined) + if (data.syslog_host !== undefined) { $("#Syslog-form").removeAttribute("hidden"); + } else { + # syslog disabled... + $("#Syslog-form").parentNode.setAttribute("hidden", ""); + } $("#SNTP-form").removeAttribute("hidden"); $("#mDNS-form").removeAttribute("hidden"); From ff51a16b98bbc8fa1495829f51ab0a4ca8acd211 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 22:41:27 -0700 Subject: [PATCH 6/8] Transfer vcxproj from #137 --- esp-link.vcxproj | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/esp-link.vcxproj b/esp-link.vcxproj index 4a1ef3a..1596844 100644 --- a/esp-link.vcxproj +++ b/esp-link.vcxproj @@ -1,4 +1,4 @@ - + @@ -72,6 +72,7 @@ + @@ -110,8 +111,14 @@ + + + + + + @@ -121,6 +128,7 @@ + {A92F0CAA-F89B-4F78-AD2A-A042429BD87F} @@ -140,7 +148,7 @@ __ets__;_STDINT_H;ICACHE_FLASH;__MINGW32__;__WIN32__;MQTT;REST;SYSLOG;FIRMWARE_SIZE - .\syslog;.\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.5.0\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include + .\syslog;.\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.5.2\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include @@ -168,4 +176,4 @@ - \ No newline at end of file + From a9321f421ba3b786c6dd18bbe1cb7f2aaa6b44f1 Mon Sep 17 00:00:00 2001 From: dima-ch Date: Sun, 19 Jun 2016 08:47:24 +0300 Subject: [PATCH 7/8] fix html special symbols in console output (#141) --- html/console.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/html/console.js b/html/console.js index 58398ad..a1eba8f 100644 --- a/html/console.js +++ b/html/console.js @@ -31,7 +31,11 @@ function updateText(resp) { if (resp.start > el.textEnd) { el.innerHTML = el.innerHTML.concat("\r\n/g, '>') + .replace(/"/g, '"')); el.textEnd = resp.start + resp.len; delay = 500; From 107a24590c72e35e947876ef139acea28d0747b8 Mon Sep 17 00:00:00 2001 From: mroavi Date: Sun, 19 Jun 2016 07:49:27 +0200 Subject: [PATCH 8/8] Fixes the Makefile's wifi station hardcoding functionality when starting in SOFTAP_MODE (#150) * Bug fixed * Change to mode STATIONAP_MODE at startup only if STA_SSID and STA_PASS are defined. --- esp-link/cgiwifi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 6b88167..9dc694a 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -851,6 +851,8 @@ void ICACHE_FLASH_ATTR wifiInit() { os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32); os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64); + wifi_set_opmode(3); + DBG("Wifi pre-config trying to connect to AP %s pw %s\n",(char*)stconf.ssid, (char*)stconf.password); // wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky