diff --git a/Makefile b/Makefile index fc10531..e07bde7 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ # # Makefile heavily adapted to esp-link and wireless flashing by Thorsten von Eicken # Original from esphttpd and others... +#VERBOSE=1 # --------------- toolchain configuration --------------- @@ -128,6 +129,8 @@ GZIP_COMPRESSION ?= yes COMPRESS_W_YUI ?= yes YUI-COMPRESSOR ?= yuicompressor-2.4.8.jar +# Optional Modules +MODULES ?= # -------------- End of config options ------------- @@ -142,6 +145,17 @@ TARGET = httpd # espressif tool to concatenate sections for OTA upload using bootloader v1.2+ APPGEN_TOOL ?= gen_appbin.py +CFLAGS= + +# set defines for optional modules +ifneq (,$(findstring mqtt,$(MODULES))) + CFLAGS += -DMQTT +endif + +ifneq (,$(findstring rest,$(MODULES))) + CFLAGS += -DREST +endif + # which modules (subdirectories) of the project to include in compiling LIBRARIES_DIR = libraries MODULES = espfs httpd user serial cmd mqtt esp-link @@ -152,8 +166,9 @@ EXTRA_INCDIR = include . include/json LIBS = c gcc hal phy pp net80211 wpa main lwip json # compiler flags using during compilation of source files -CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ +CFLAGS += -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections \ + -Wno-unused-function \ -D__ets__ -DICACHE_FLASH -D_STDINT_H -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \ -DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \ -DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_PIN) \ diff --git a/esp-link.vcxproj b/esp-link.vcxproj index c3bef32..029fbb7 100644 --- a/esp-link.vcxproj +++ b/esp-link.vcxproj @@ -39,12 +39,12 @@ build - espmake flash + espmake all wiflash espmake clean all espmake clean - espmake all wiflash + espmake clean all wiflash espmake clean all espmake clean @@ -65,8 +65,8 @@ - - + + @@ -111,8 +111,8 @@ - - + + diff --git a/esp-link/cgi.c b/esp-link/cgi.c index 8f87d38..73b0aa4 100644 --- a/esp-link/cgi.c +++ b/esp-link/cgi.c @@ -12,11 +12,15 @@ Some random cgi routines. * Heavily modified and enhanced by Thorsten von Eicken in 2015 * ---------------------------------------------------------------------------- */ - - -#include #include "cgi.h" -#include "espfs.h" +static char* chipIdStr = ""; +char* ICACHE_FLASH_ATTR system_get_chip_id_str(){ + if (os_strlen(chipIdStr) == 0) { + chipIdStr = (char*)os_zalloc(9); + os_sprintf(chipIdStr, "%06x", system_get_chip_id()); + } + return chipIdStr; +} void ICACHE_FLASH_ATTR jsonHeader(HttpdConnData *connData, int code) { @@ -28,6 +32,44 @@ jsonHeader(HttpdConnData *connData, int code) { httpdEndHeaders(connData); } +uint8_t ICACHE_FLASH_ATTR +UTILS_StrToIP(const char* str, void *ip){ + /* The count of the number of bytes processed. */ + int i; + /* A pointer to the next digit to process. */ + const char * start; + + start = str; + for (i = 0; i < 4; i++) { + /* The digit being processed. */ + char c; + /* The value of this byte. */ + int n = 0; + while (1) { + c = *start; + start++; + if (c >= '0' && c <= '9') { + n *= 10; + n += c - '0'; + } + /* We insist on stopping at "." if we are still parsing + the first, second, or third numbers. If we have reached + the end of the numbers, we will allow any character. */ + else if ((i < 3 && c == '.') || i == 3) { + break; + } + else { + return 0; + } + } + if (n >= 256) { + return 0; + } + ((uint8_t*)ip)[i] = n; + } + return 1; +} + #define TOKEN(x) (os_strcmp(token, x) == 0) #if 0 // Handle system information variables and print their value, returns the number of diff --git a/esp-link/cgi.h b/esp-link/cgi.h index b5690cf..beee16b 100644 --- a/esp-link/cgi.h +++ b/esp-link/cgi.h @@ -1,9 +1,12 @@ #ifndef CGI_H #define CGI_H +#include #include "httpd.h" void jsonHeader(HttpdConnData *connData, int code); int cgiMenu(HttpdConnData *connData); +uint8_t UTILS_StrToIP(const char* str, void *ip); +char* system_get_chip_id_str(); #endif diff --git a/include/esp8266.h b/include/esp8266.h index 454b849..3e7eeb9 100644 --- a/include/esp8266.h +++ b/include/esp8266.h @@ -19,14 +19,6 @@ #include "espmissingincludes.h" #include "uart_hw.h" -extern char* esp_link_version; - -void ICACHE_FLASH_ATTR init(void); -inline char* ICACHE_FLASH_ATTR system_get_chip_id_str(){ - char *chipId = (char*)os_zalloc(9); - os_sprintf(chipId, "%06x", system_get_chip_id()); - return chipId; -} #ifdef __WIN32__ #include <_mingw.h> diff --git a/include/user_config.h b/include/user_config.h index de558e3..0672687 100644 --- a/include/user_config.h +++ b/include/user_config.h @@ -1,8 +1,13 @@ #ifndef _USER_CONFIG_H_ #define _USER_CONFIG_H_ - +#include +#ifdef __WIN32__ +#include <_mingw.h> +#endif +//#define CMD_DBG #define MQTT_RECONNECT_TIMEOUT 5 // seconds -#define MQTT_BUF_SIZE 1024 +#define MQTT_BUF_SIZE 512 +#define QUEUE_BUFFER_SIZE 512 #define MQTT_HOST "10.0.0.220" // "mqtt.yourdomain.com" or ip "10.0.0.1" #define MQTT_PORT 1883 @@ -17,4 +22,12 @@ #define PROTOCOL_NAMEv31 // MQTT version 3.1 compatible with Mosquitto v0.15/ //PROTOCOL_NAMEv311 // MQTT version 3.11 compatible with https://eclipse.org/paho/clients/testing/ +extern char* esp_link_version; + +extern uint8_t UTILS_StrToIP(const char* str, void *ip); + +extern void ICACHE_FLASH_ATTR init(void); + +extern char* ICACHE_FLASH_ATTR system_get_chip_id_str(); + #endif \ No newline at end of file diff --git a/cmd/mqtt_cmd.c b/mqtt/mqtt_cmd.c similarity index 100% rename from cmd/mqtt_cmd.c rename to mqtt/mqtt_cmd.c diff --git a/cmd/mqtt_cmd.h b/mqtt/mqtt_cmd.h similarity index 100% rename from cmd/mqtt_cmd.h rename to mqtt/mqtt_cmd.h diff --git a/cmd/rest.c b/rest/rest.c similarity index 93% rename from cmd/rest.c rename to rest/rest.c index 3556681..a9cd298 100644 --- a/cmd/rest.c +++ b/rest/rest.c @@ -392,42 +392,3 @@ fail: os_printf("\n"); return 0; } - -uint8_t ICACHE_FLASH_ATTR -UTILS_StrToIP(const char* str, void *ip) -{ - /* The count of the number of bytes processed. */ - int i; - /* A pointer to the next digit to process. */ - const char * start; - - start = str; - for (i = 0; i < 4; i++) { - /* The digit being processed. */ - char c; - /* The value of this byte. */ - int n = 0; - while (1) { - c = * start; - start++; - if (c >= '0' && c <= '9') { - n *= 10; - n += c - '0'; - } - /* We insist on stopping at "." if we are still parsing - the first, second, or third numbers. If we have reached - the end of the numbers, we will allow any character. */ - else if ((i < 3 && c == '.') || i == 3) { - break; - } - else { - return 0; - } - } - if (n >= 256) { - return 0; - } - ((uint8_t*)ip)[i] = n; - } - return 1; -} diff --git a/cmd/rest.h b/rest/rest.h similarity index 93% rename from cmd/rest.h rename to rest/rest.h index 9c6cd5c..7161e1f 100644 --- a/cmd/rest.h +++ b/rest/rest.h @@ -36,6 +36,5 @@ typedef struct { uint32_t REST_Setup(CmdPacket *cmd); uint32_t REST_Request(CmdPacket *cmd); uint32_t REST_SetHeader(CmdPacket *cmd); -uint8_t UTILS_StrToIP(const char* str, void *ip); #endif /* MODULES_INCLUDE_API_H_ */