diff --git a/.gitignore b/.gitignore index e462231..e90d818 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ esp-link.sdf espfs/mkespfsimage/mman-win32/libmman.a .localhistory/ tools/ +local.conf *.tgz diff --git a/Makefile b/Makefile index b3d9f1f..5ea80d9 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,12 @@ # `VERBOSE=1 make ...` will print debug info # `ESP_HOSTNAME=my.esp.example.com make wiflash` is an easy way to override a variable # +# optional local configuration file +-include local.conf # Makefile heavily adapted to esp-link and wireless flashing by Thorsten von Eicken # Lots of work, in particular to support windows, by brunnels # Original from esphttpd and others... -#VERBOSE=1 +# VERBOSE=1 # --------------- toolchain configuration --------------- @@ -63,7 +65,7 @@ LED_SERIAL_PIN ?= 14 CHANGE_TO_STA ?= yes # Optional Modules -MODULES ?= mqtt rest +MODULES ?= mqtt rest syslog # --------------- esphttpd config options --------------- @@ -94,6 +96,25 @@ YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar # -------------- End of config options ------------- +ifeq ("$(FLASH_SIZE)","512KB") +# Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11 +ESP_SPI_SIZE ?= 0 # 0->512KB +ESP_FLASH_MODE ?= 0 # 0->QIO +ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz +ESP_FLASH_MAX ?= 241664 # max bin file for 512KB flash: 236KB + +else +# Winbond 25Q32 4MB flash, typ for esp-12 +# Here we're using two partitions of approx 0.5MB because that's what's easily available in terms +# of linker scripts in the SDK. Ideally we'd use two partitions of approx 1MB, the remaining 2MB +# cannot be used for code. +ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB) +ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO +ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz +ESP_FLASH_MAX ?= 503808 # max bin file for 512KB flash partition: 492KB +#ESP_FLASH_MAX ?= 1028096 # max bin file for 1MB flash partition: 1004KB +endif + HTML_PATH = $(abspath ./html)/ WIFI_PATH = $(HTML_PATH)wifi/ @@ -178,6 +199,10 @@ ifneq (,$(findstring rest,$(MODULES))) CFLAGS += -DREST endif +ifneq (,$(findstring syslog,$(MODULES))) + CFLAGS += -DSYSLOG +endif + # which modules (subdirectories) of the project to include in compiling LIBRARIES_DIR = libraries MODULES += espfs httpd user serial cmd esp-link @@ -335,7 +360,7 @@ flash: all $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \ 0x00000 "$(SDK_BASE)/bin/boot_v1.4(b1).bin" 0x01000 $(FW_BASE)/user1.bin \ $(ET_BLANK) $(SDK_BASE)/bin/blank.bin - + tools/$(HTML_COMPRESSOR): $(Q) mkdir -p tools ifeq ($(OS),Windows_NT) diff --git a/esp-link.vcxproj b/esp-link.vcxproj index 5d723c6..369d0cb 100644 --- a/esp-link.vcxproj +++ b/esp-link.vcxproj @@ -18,6 +18,7 @@ + @@ -26,6 +27,7 @@ + @@ -45,6 +47,7 @@ + @@ -54,6 +57,7 @@ + @@ -62,6 +66,7 @@ + @@ -84,8 +89,10 @@ + + @@ -99,6 +106,8 @@ + + @@ -106,6 +115,7 @@ + @@ -131,8 +141,8 @@ - __ets__;_STDINT_H;ICACHE_FLASH;__MINGW32__;__WIN32__;MQTT;REST - .\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 + __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 diff --git a/esp-link/cgi.c b/esp-link/cgi.c index ba08c00..da54997 100644 --- a/esp-link/cgi.c +++ b/esp-link/cgi.c @@ -13,40 +13,39 @@ Some random cgi routines. * ---------------------------------------------------------------------------- */ - #include #include "cgi.h" #include "config.h" -void ICACHE_FLASH_ATTR -noCacheHeaders(HttpdConnData *connData, int code) { +#ifdef CGI_DBG +#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) +#else +#define DBG(format, ...) do { } while(0) +#endif + +void ICACHE_FLASH_ATTR noCacheHeaders(HttpdConnData *connData, int code) { httpdStartResponse(connData, code); httpdHeader(connData, "Cache-Control", "no-cache, no-store, must-revalidate"); httpdHeader(connData, "Pragma", "no-cache"); httpdHeader(connData, "Expires", "0"); } -void ICACHE_FLASH_ATTR -jsonHeader(HttpdConnData *connData, int code) { +void ICACHE_FLASH_ATTR jsonHeader(HttpdConnData *connData, int code) { noCacheHeaders(connData, code); httpdHeader(connData, "Content-Type", "application/json"); httpdEndHeaders(connData); } -void ICACHE_FLASH_ATTR -errorResponse(HttpdConnData *connData, int code, char *message) { +void ICACHE_FLASH_ATTR errorResponse(HttpdConnData *connData, int code, char *message) { noCacheHeaders(connData, code); httpdEndHeaders(connData); httpdSend(connData, message, -1); -#ifdef CGI_DBG - os_printf("HTTP %d error response: \"%s\"\n", code, message); -#endif + DBG("HTTP %d error response: \"%s\"\n", code, message); } // look for the HTTP arg 'name' and store it at 'config' with max length 'max_len' (incl // terminating zero), returns -1 on error, 0 if not found, 1 if found and OK -int8_t ICACHE_FLASH_ATTR -getStringArg(HttpdConnData *connData, char *name, char *config, int max_len) { +int8_t ICACHE_FLASH_ATTR getStringArg(HttpdConnData *connData, char *name, char *config, int max_len) { char buff[128]; int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff)); if (len < 0) return 0; // not found, skip @@ -55,19 +54,50 @@ getStringArg(HttpdConnData *connData, char *name, char *config, int max_len) { errorResponse(connData, 400, buff); return -1; } - strcpy(config, buff); + os_strcpy(config, buff); return 1; } // look for the HTTP arg 'name' and store it at 'config' as an 8-bit integer // returns -1 on error, 0 if not found, 1 if found and OK -int8_t ICACHE_FLASH_ATTR -getInt8Arg(HttpdConnData *connData, char *name, int8_t *config) { +int8_t ICACHE_FLASH_ATTR getInt8Arg(HttpdConnData *connData, char *name, int8_t *config) { + char buff[16]; + int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff)); + if (len < 0) return 0; // not found, skip + int m = atoi(buff); + if (len > 5 || m < -127 || m > 127) { + os_sprintf(buff, "Value for %s out of range", name); + errorResponse(connData, 400, buff); + return -1; + } + *config = m; + return 1; +} + +// look for the HTTP arg 'name' and store it at 'config' as an unsigned 8-bit integer +// returns -1 on error, 0 if not found, 1 if found and OK +int8_t ICACHE_FLASH_ATTR getUInt8Arg(HttpdConnData *connData, char *name, uint8_t *config) { + char buff[16]; + int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff)); + if (len < 0) return 0; // not found, skip + int m = atoi(buff); + if (len > 4 || m < 0 || m > 255) { + os_sprintf(buff, "Value for %s out of range", name); + errorResponse(connData, 400, buff); + return -1; + } + *config = m; + return 1; +} + +// look for the HTTP arg 'name' and store it at 'config' as an unsigned 16-bit integer +// returns -1 on error, 0 if not found, 1 if found and OK +int8_t ICACHE_FLASH_ATTR getUInt16Arg(HttpdConnData *connData, char *name, uint16_t *config) { char buff[16]; int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff)); if (len < 0) return 0; // not found, skip int m = atoi(buff); - if (len >= 6 || m < -128 || m > 255) { + if (len > 6 || m < 0 || m > 65535) { os_sprintf(buff, "Value for %s out of range", name); errorResponse(connData, 400, buff); return -1; @@ -76,27 +106,27 @@ getInt8Arg(HttpdConnData *connData, char *name, int8_t *config) { return 1; } -int8_t ICACHE_FLASH_ATTR -getBoolArg(HttpdConnData *connData, char *name, bool*config) { - char buff[64]; +int8_t ICACHE_FLASH_ATTR getBoolArg(HttpdConnData *connData, char *name, bool *config) { + char buff[16]; int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff)); if (len < 0) return 0; // not found, skip - if (strcmp(buff, "1") == 0 || strcmp(buff, "true") == 0) { + if (os_strcmp(buff, "1") == 0 || os_strcmp(buff, "true") == 0) { *config = true; return 1; - } - if (strcmp(buff, "0") == 0 || strcmp(buff, "false") == 0) { + } + + if (os_strcmp(buff, "0") == 0 || os_strcmp(buff, "false") == 0) { *config = false; return 1; - } + } + os_sprintf(buff, "Invalid value for %s", name); errorResponse(connData, 400, buff); return -1; } -uint8_t ICACHE_FLASH_ATTR -UTILS_StrToIP(const char* str, void *ip){ +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. */ @@ -133,8 +163,8 @@ UTILS_StrToIP(const char* str, void *ip){ return 1; } -#define TOKEN(x) (os_strcmp(token, x) == 0) #if 0 +#define TOKEN(x) (os_strcmp(token, x) == 0) // Handle system information variables and print their value, returns the number of // characters appended to buff int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) { @@ -172,16 +202,23 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) { os_strncpy(name, flashConfig.hostname, 12); name[12] = 0; // construct json response - os_sprintf(buff, - "{\"menu\": [\"Home\", \"/home.html\", " - "\"Wifi\", \"/wifi/wifi.html\"," - "\"\xC2\xB5" "C Console\", \"/console.html\", " + os_sprintf(buff, + "{ " + "\"menu\": [ " + "\"Home\", \"/home.html\", " + "\"Wifi\", \"/wifi/wifi.html\", " + "\"µC Console\", \"/console.html\", " + "\"Services\", \"/services.html\", " #ifdef MQTT - "\"REST/MQTT\", \"/mqtt.html\"," + "\"REST/MQTT\", \"/mqtt.html\", " #endif - "\"Debug log\", \"/log.html\" ],\n" - " \"version\": \"%s\"," - "\"name\":\"%s\"}", esp_link_version, name); + "\"Debug log\", \"/log.html\"" + " ], " + "\"version\": \"%s\", " + "\"name\": \"%s\"" + " }", + esp_link_version, name); + httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; } diff --git a/esp-link/cgi.h b/esp-link/cgi.h index e64b301..cb897b0 100644 --- a/esp-link/cgi.h +++ b/esp-link/cgi.h @@ -12,16 +12,24 @@ void errorResponse(HttpdConnData *connData, int code, char *message); // 'max_len' (incl terminating zero), returns -1 on error, 0 if not found, 1 if found int8_t getStringArg(HttpdConnData *connData, char *name, char *config, int max_len); -// Get the HTTP query-string param 'name' and store it as a int8 value at 'config', +// Get the HTTP query-string param 'name' and store it as a int8_t value at 'config', // supports signed and unsigned, returns -1 on error, 0 if not found, 1 if found int8_t getInt8Arg(HttpdConnData *connData, char *name, int8_t *config); +// Get the HTTP query-string param 'name' and store it as a uint8_t value at 'config', +// supports signed and unsigned, returns -1 on error, 0 if not found, 1 if found +int8_t getUInt8Arg(HttpdConnData *connData, char *name, uint8_t *config); + +// Get the HTTP query-string param 'name' and store it as a uint16_t value at 'config', +// supports signed and unsigned, returns -1 on error, 0 if not found, 1 if found +int8_t getUInt16Arg(HttpdConnData *connData, char *name, uint16_t *config); + // Get the HTTP query-string param 'name' and store it boolean value at 'config', // supports 1/true and 0/false, returns -1 on error, 0 if not found, 1 if found -int8_t getBoolArg(HttpdConnData *connData, char *name, bool*config); +int8_t getBoolArg(HttpdConnData *connData, char *name, bool *config); int cgiMenu(HttpdConnData *connData); -uint8_t UTILS_StrToIP(const char* str, void *ip); +uint8_t UTILS_StrToIP(const char *str, void *ip); #endif diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 2758aec..d272465 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -18,7 +18,12 @@ Some flash handling cgi routines. Used for reading the existing flash and updati #include #include "cgi.h" #include "cgiflash.h" -#include "espfs.h" + +#ifdef CGIFLASH_DBG +#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) +#else +#define DBG(format, ...) do { } while(0) +#endif // Check that the header of the firmware blob looks like actual firmware... static char* ICACHE_FLASH_ATTR check_header(void *buf) { @@ -58,10 +63,7 @@ int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) { httpdEndHeaders(connData); char *next = id == 1 ? "user1.bin" : "user2.bin"; httpdSend(connData, next, -1); -#ifdef CGIFLASH_DBG - os_printf("Next firmware: %s (got %d)\n", next, id); -#endif - + DBG("Next firmware: %s (got %d)\n", next, id); return HTTPD_CGI_DONE; } @@ -103,9 +105,7 @@ int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) { // return an error if there is one if (err != NULL) { -#ifdef CGIFLASH_DBG - os_printf("Error %d: %s\n", code, err); -#endif + DBG("Error %d: %s\n", code, err); httpdStartResponse(connData, code); httpdHeader(connData, "Content-Type", "text/plain"); //httpdHeader(connData, "Content-Length", strlen(err)+2); @@ -124,14 +124,12 @@ int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) { // erase next flash block if necessary if (address % SPI_FLASH_SEC_SIZE == 0){ -#ifdef CGIFLASH_DBG - os_printf("Flashing 0x%05x (id=%d)\n", address, 2-id); -#endif + DBG("Flashing 0x%05x (id=%d)\n", address, 2 - id); spi_flash_erase_sector(address/SPI_FLASH_SEC_SIZE); } // Write the data - //os_printf("Writing %d bytes at 0x%05x (%d of %d)\n", connData->post->buffSize, address, + //DBG("Writing %d bytes at 0x%05x (%d of %d)\n", connData->post->buffSize, address, // connData->post->received, connData->post->len); spi_flash_write(address, (uint32 *)connData->post->buff, connData->post->buffLen); @@ -150,10 +148,10 @@ static ETSTimer flash_reboot_timer; int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - if (!canOTA()) { - errorResponse(connData, 400, flash_too_small); - return HTTPD_CGI_DONE; - } + if (!canOTA()) { + errorResponse(connData, 400, flash_too_small); + return HTTPD_CGI_DONE; + } // sanity-check that the 'next' partition actually contains something that looks like // valid firmware @@ -161,15 +159,11 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { int address = id == 1 ? 4*1024 // either start after 4KB boot partition : 4*1024 + FIRMWARE_SIZE + 16*1024 + 4*1024; // 4KB boot, fw1, 16KB user param, 4KB reserved uint32 buf[8]; -#ifdef CGIFLASH_DBG - os_printf("Checking %p\n", (void *)address); -#endif + DBG("Checking %p\n", (void *)address); spi_flash_read(address, buf, sizeof(buf)); char *err = check_header(buf); if (err != NULL) { -#ifdef CGIFLASH_DBG - os_printf("Error %d: %s\n", 400, err); -#endif + DBG("Error %d: %s\n", 400, err); httpdStartResponse(connData, 400); httpdHeader(connData, "Content-Type", "text/plain"); //httpdHeader(connData, "Content-Length", strlen(err)+2); @@ -190,3 +184,18 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { os_timer_arm(&flash_reboot_timer, 2000, 1); return HTTPD_CGI_DONE; } + +int ICACHE_FLASH_ATTR cgiReboot(HttpdConnData *connData) { + if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. + + httpdStartResponse(connData, 200); + httpdHeader(connData, "Content-Length", "0"); + httpdEndHeaders(connData); + + // Schedule a reboot + system_upgrade_flag_set(UPGRADE_FLAG_FINISH); + os_timer_disarm(&flash_reboot_timer); + os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL); + os_timer_arm(&flash_reboot_timer, 2000, 1); + return HTTPD_CGI_DONE; +} \ No newline at end of file diff --git a/esp-link/cgiflash.h b/esp-link/cgiflash.h index 15c60c2..d8a239d 100644 --- a/esp-link/cgiflash.h +++ b/esp-link/cgiflash.h @@ -7,5 +7,6 @@ int cgiReadFlash(HttpdConnData *connData); int cgiGetFirmwareNext(HttpdConnData *connData); int cgiUploadFirmware(HttpdConnData *connData); int cgiRebootFirmware(HttpdConnData *connData); +int cgiReboot(HttpdConnData *connData); #endif diff --git a/esp-link/cgimqtt.c b/esp-link/cgimqtt.c index de98d57..88aa6ed 100644 --- a/esp-link/cgimqtt.c +++ b/esp-link/cgimqtt.c @@ -16,6 +16,12 @@ char *mqttState(void) { #include "mqtt_client.h" #include "cgimqtt.h" +#ifdef CGIMQTT_DBG +#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) +#else +#define DBG(format, ...) do { } while(0) +#endif + char *mqttState(void) { return mqtt_states[mqttClient.connState]; } @@ -69,7 +75,6 @@ int ICACHE_FLASH_ATTR cgiMqttGet(HttpdConnData *connData) { return HTTPD_CGI_DONE; } -// Cgi to change choice of pin assignments int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; @@ -124,17 +129,14 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { // if server setting changed, we need to "make it so" if (mqtt_server) { -#ifdef CGIMQTT_DBG - os_printf("MQTT server settings changed, enable=%d\n", flashConfig.mqtt_enable); -#endif + DBG("MQTT server settings changed, enable=%d\n", flashConfig.mqtt_enable); MQTT_Free(&mqttClient); // safe even if not connected mqtt_client_init(); // if just enable changed we just need to bounce the client - } else if (mqtt_en_chg > 0) { -#ifdef CGIMQTT_DBG - os_printf("MQTT server enable=%d changed\n", flashConfig.mqtt_enable); -#endif + } + 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) MQTT_Reconnect(&mqttClient); else @@ -152,11 +154,11 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { // if SLIP-enable is toggled it gets picked-up immediately by the parser int slip_update = getBoolArg(connData, "slip-enable", &flashConfig.slip_enable); if (slip_update < 0) return HTTPD_CGI_DONE; -#ifdef CGIMQTT_DBG - if (slip_update > 0) os_printf("SLIP-enable changed: %d\n", flashConfig.slip_enable); + if (slip_update > 0) + DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable); + + DBG("Saving config\n"); - os_printf("Saving config\n"); -#endif if (configSave()) { httpdStartResponse(connData, 200); httpdEndHeaders(connData); @@ -178,4 +180,4 @@ int ICACHE_FLASH_ATTR cgiMqtt(HttpdConnData *connData) { return HTTPD_CGI_DONE; } } -#endif // MQTT +#endif diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c new file mode 100644 index 0000000..775461e --- /dev/null +++ b/esp-link/cgiservices.c @@ -0,0 +1,205 @@ +#include +#include "cgiwifi.h" +#include "cgi.h" +#include "config.h" +#include "syslog.h" +#include "sntp.h" +#include "cgimqtt.h" + +#ifdef CGISERVICES_DBG +#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) +#else +#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) +int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { + if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. + + int8_t n = getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname)); + int8_t d = getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr)); + + if (n < 0 || d < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response + + if (n > 0) { + // schedule hostname change-over + os_timer_disarm(&reassTimer); + os_timer_setfn(&reassTimer, configWifiIP, NULL); + os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + } + + if (configSave()) { + httpdStartResponse(connData, 204); + httpdEndHeaders(connData); + } + else { + httpdStartResponse(connData, 500); + httpdEndHeaders(connData); + httpdSend(connData, "Failed to save config", -1); + } + return HTTPD_CGI_DONE; +} + +// Cgi to return various System information +int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { + char buff[1024]; + + if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. + + uint8 part_id = system_upgrade_userbin_check(); + uint32_t fid = spi_flash_get_id(); + struct rst_info *rst_info = system_get_rst_info(); + + os_sprintf(buff, + "{ " + "\"name\": \"%s\", " + "\"reset cause\": \"%d=%s\", " + "\"size\": \"%s\", " + "\"id\": \"0x%02lX 0x%04lX\", " + "\"partition\": \"%s\", " + "\"slip\": \"%s\", " + "\"mqtt\": \"%s/%s\", " + "\"baud\": \"%ld\", " + "\"description\": \"%s\"" + " }", + flashConfig.hostname, + rst_info->reason, + rst_codes[rst_info->reason], + flash_maps[system_get_flash_size_map()], + fid & 0xff, (fid & 0xff00) | ((fid >> 16) & 0xff), + part_id ? "user2.bin" : "user1.bin", + flashConfig.slip_enable ? "enabled" : "disabled", + flashConfig.mqtt_enable ? "enabled" : "disabled", + mqttState(), + flashConfig.baud_rate, + flashConfig.sys_descr + ); + + jsonHeader(connData, 200); + httpdSend(connData, buff, -1); + return HTTPD_CGI_DONE; +} + +static void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { + if (flashConfig.sntp_server[0]) { + DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset); + sntp_stop(); + sntp_setservername(0, flashConfig.sntp_server); + sntp_set_timezone(flashConfig.timezone_offset); + sntp_init(); + } +} + +int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { + char buff[1024]; + + if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. + + os_sprintf(buff, + "{ " + "\"syslog_enable\": \"%s\", " + "\"syslog_host\": \"%s\", " + "\"syslog_minheap\": %d, " + "\"syslog_filter\": %d, " + "\"syslog_showtick\": \"%s\", " + "\"syslog_showdate\": \"%s\", " + "\"timezone_offset\": %d, " + "\"sntp_server\": \"%s\", " + "\"mdns_enable\": \"%s\", " + "\"mdns_servername\": \"%s\"" + " }", + flashConfig.syslog_enable ? "enabled" : "disabled", + flashConfig.syslog_host, + flashConfig.syslog_minheap, + flashConfig.syslog_filter, + flashConfig.syslog_showtick ? "enabled" : "disabled", + flashConfig.syslog_showdate ? "enabled" : "disabled", + flashConfig.timezone_offset, + flashConfig.sntp_server, + flashConfig.mdns_enable ? "enabled" : "disabled", + flashConfig.mdns_servername + ); + + jsonHeader(connData, 200); + httpdSend(connData, buff, -1); + return HTTPD_CGI_DONE; +} + +int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { + if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. + + int8_t syslog = 0; + + syslog |= getBoolArg(connData, "syslog_enable", &flashConfig.syslog_enable); + if (syslog < 0) return HTTPD_CGI_DONE; + syslog |= getStringArg(connData, "syslog_host", flashConfig.syslog_host, sizeof(flashConfig.syslog_host)); + if (syslog < 0) return HTTPD_CGI_DONE; + syslog |= getUInt16Arg(connData, "syslog_minheap", &flashConfig.syslog_minheap); + 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); + if (syslog < 0) return HTTPD_CGI_DONE; + syslog |= getBoolArg(connData, "syslog_showdate", &flashConfig.syslog_showdate); + if (syslog < 0) return HTTPD_CGI_DONE; + + int8_t sntp = 0; + sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset); + if (sntp < 0) return HTTPD_CGI_DONE; + sntp |= getStringArg(connData, "sntp_server", flashConfig.sntp_server, sizeof(flashConfig.sntp_server)); + if (sntp < 0) return HTTPD_CGI_DONE; + + int8_t mdns = 0; + mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); + if (mdns < 0) return HTTPD_CGI_DONE; + mdns |= getStringArg(connData, "mdns_servername", flashConfig.mdns_servername, sizeof(flashConfig.mdns_servername)); + if (mdns < 0) return HTTPD_CGI_DONE; + + if (syslog > 0) { + if (!flashConfig.syslog_enable) { + flashConfig.syslog_host[0] = '\0'; + } + syslog_init(flashConfig.syslog_host); + } + + if (sntp > 0) { + cgiServicesSNTPInit(); + } + + if (mdns > 0) { + espconn_mdns_disable(); + if (flashConfig.mdns_enable) { + struct ip_info ipconfig; + wifi_get_ip_info(STATION_IF, &ipconfig); + mdns_started = false; + if (wifiState == wifiGotIP && ipconfig.ip.addr != 0) { + wifiStartMDNS(ipconfig.ip); + } + } + else { + mdns_started = true; + } + } + + if (configSave()) { + httpdStartResponse(connData, 204); + httpdEndHeaders(connData); + } + else { + httpdStartResponse(connData, 500); + httpdEndHeaders(connData); + httpdSend(connData, "Failed to save config", -1); + } + return HTTPD_CGI_DONE; +} diff --git a/esp-link/cgiservices.h b/esp-link/cgiservices.h new file mode 100644 index 0000000..7c34af2 --- /dev/null +++ b/esp-link/cgiservices.h @@ -0,0 +1,15 @@ +#ifndef CGISERVICES_H +#define CGISERVICES_H + +#include "httpd.h" + +int cgiSystemSet(HttpdConnData *connData); +int cgiSystemInfo(HttpdConnData *connData); + +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 9fe6fe1..1efa5d5 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -13,14 +13,12 @@ Cgi/template routines for the /wifi url. * ---------------------------------------------------------------------------- */ - #include #include "cgiwifi.h" #include "cgi.h" #include "status.h" #include "config.h" #include "log.h" -#include "sntp.h" #ifdef CGIWIFI_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -28,8 +26,7 @@ Cgi/template routines for the /wifi url. #define DBG(format, ...) do { } while(0) #endif -static void wifiStartMDNS(struct ip_addr); -static void wifiStartSNTP(); +bool mdns_started = false; // ===== wifi status change callbacks static WifiStateChangeCb wifi_state_change_cb[4]; @@ -85,7 +82,6 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) { IP2STR(&evt->event_info.got_ip.gw)); statusWifiUpdate(wifiState); wifiStartMDNS(evt->event_info.got_ip.ip); - wifiStartSNTP(); break; case EVENT_SOFTAPMODE_STACONNECTED: DBG("Wifi AP: station " MACSTR " joined, AID = %d\n", @@ -104,8 +100,7 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) { } } -void ICACHE_FLASH_ATTR -wifiAddStateChangeCb(WifiStateChangeCb cb) { +void ICACHE_FLASH_ATTR wifiAddStateChangeCb(WifiStateChangeCb cb) { for (int i = 0; i < 4; i++) { if (wifi_state_change_cb[i] == cb) return; if (wifi_state_change_cb[i] == NULL) { @@ -116,56 +111,18 @@ wifiAddStateChangeCb(WifiStateChangeCb cb) { DBG("WIFI: max state change cb count exceeded\n"); } -static bool mdns_started = false; - -static ICACHE_FLASH_ATTR -void wifiStartMDNS(struct ip_addr ip) { +void ICACHE_FLASH_ATTR wifiStartMDNS(struct ip_addr ip) { if (!mdns_started) { struct mdns_info *mdns_info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info)); mdns_info->host_name = flashConfig.hostname; - mdns_info->server_name = "arduino"; // service name + mdns_info->server_name = flashConfig.mdns_servername; // service name mdns_info->server_port = 80; // service port mdns_info->ipAddr = ip.addr; - espconn_mdns_init(mdns_info); + espconn_mdns_init(mdns_info); mdns_started = true; } } -static bool sntp_started = false; - -static ETSTimer sntp_timer; - -void ICACHE_FLASH_ATTR -user_check_sntp_stamp(void *arg){ - uint32 current_stamp; - current_stamp = sntp_get_current_timestamp(); - if (current_stamp == 0){ - os_timer_arm(&sntp_timer, 100, 0); - } - else{ - os_timer_disarm(&sntp_timer); - os_printf("sntp: %d, %s \n", current_stamp, sntp_get_real_time(current_stamp)); - } -} - -static ICACHE_FLASH_ATTR -void wifiStartSNTP() { - if (!sntp_started) { - ip_addr_t *addr = (ip_addr_t *)os_zalloc(sizeof(ip_addr_t)); - sntp_setservername(0, "us.pool.ntp.org"); // set server 0 by domain name - sntp_setservername(1, "ntp.sjtu.edu.cn"); // set server 1 by domain name - IP4_ADDR(addr, 210, 72, 145, 44); - sntp_setserver(2, addr); // set server 2 by IP address - sntp_init(); - os_free(addr); - - os_timer_disarm(&sntp_timer); - os_timer_setfn(&sntp_timer, (os_timer_func_t *)user_check_sntp_stamp, NULL); - os_timer_arm(&sntp_timer, 100, 0); - sntp_started = true; - } -} - // ===== wifi scanning //WiFi access point data @@ -398,7 +355,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { return HTTPD_CGI_DONE; } -static bool parse_ip(char *buff, ip_addr_t *ip_ptr) { +static bool ICACHE_FLASH_ATTR parse_ip(char *buff, ip_addr_t *ip_ptr) { char *next = buff; // where to start parsing next integer int found = 0; // number of integers parsed uint32_t ip = 0; // the ip addres parsed diff --git a/esp-link/cgiwifi.h b/esp-link/cgiwifi.h index 37a02d6..e2e98bc 100644 --- a/esp-link/cgiwifi.h +++ b/esp-link/cgiwifi.h @@ -16,7 +16,9 @@ int cgiWiFiSpecial(HttpdConnData *connData); void configWifiIP(); void wifiInit(void); void wifiAddStateChangeCb(WifiStateChangeCb cb); +void wifiStartMDNS(struct ip_addr); extern uint8_t wifiState; +extern bool mdns_started; #endif diff --git a/esp-link/config.c b/esp-link/config.c index 2b756c1..f6957b2 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -9,21 +9,28 @@ FlashConfig flashConfig; FlashConfig flashDefault = { - 33, 0, 0, - MCU_RESET_PIN, MCU_ISP_PIN, LED_CONN_PIN, LED_SERIAL_PIN, - 115200, - "esp-link\0", // hostname - 0, 0x00ffffff, 0, // static ip, netmask, gateway - 0, // log mode - 0, // swap uart (don't by default) - 1, 0, // tcp_enable, rssi_enable - "\0", // api_key - 0, 0, 0, // slip_enable, mqtt_enable, mqtt_status_enable - 2, 1, // mqtt_timeout, mqtt_clean_session - 1883, 60, // mqtt port, mqtt_keepalive - "\0", "\0", "\0", "\0", "\0", // mqtt host, client_id, user, password, status-topic - "\0", // system description - 1, // rx_pullup + .seq = 33, .magic = 0, .crc = 0, + .reset_pin = MCU_RESET_PIN, .isp_pin = MCU_ISP_PIN, + .conn_led_pin = LED_CONN_PIN, .ser_led_pin = LED_SERIAL_PIN, + .baud_rate = 115200, + .hostname = "esp-link\0", + .staticip = 0, + .netmask = 0x00ffffff, + .gateway = 0, + .log_mode = 0, + .swap_uart = 0, + .tcp_enable = 1, .rssi_enable = 0, + .api_key = "", + .slip_enable = 0, .mqtt_enable = 0, .mqtt_status_enable = 0, + .mqtt_timeout = 2, .mqtt_clean_session = 1, + .mqtt_port = 1883, .mqtt_keepalive = 60, + .mqtt_host = "\0", .mqtt_clientid = "\0", + .mqtt_username= "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0", + .sys_descr = "\0", + .rx_pullup = 1, + .mdns_enable = 1, .mdns_servername = "http\0", + .sntp_server = "us.pool.ntp.org\0", .timezone_offset = 0, + .syslog_enable= 0, .syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0, }; typedef union { diff --git a/esp-link/config.h b/esp-link/config.h index 9b20df3..fafdab7 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -21,10 +21,23 @@ typedef struct { mqtt_timeout, // MQTT send timeout mqtt_clean_session; // MQTT clean session uint16_t mqtt_port, mqtt_keepalive; // MQTT Host port, MQTT Keepalive timer - char mqtt_host[32], mqtt_clientid[48], mqtt_username[32], mqtt_password[32]; - char mqtt_status_topic[32]; + char mqtt_host[32], + mqtt_clientid[48], + mqtt_username[32], + mqtt_password[32], + mqtt_status_topic[32]; char sys_descr[129]; // system description int8_t rx_pullup; // internal pull-up on RX pin + uint8_t mdns_enable; + char mdns_servername[32], + sntp_server[32]; + int8_t timezone_offset; + uint8_t syslog_enable; + char syslog_host[32]; + uint16_t syslog_minheap; // min. heap to allow queuing + uint8_t syslog_filter, // min. severity + syslog_showtick, // show system tick (µs) + syslog_showdate; // populate SYSLOG date field } FlashConfig; extern FlashConfig flashConfig; diff --git a/esp-link/main.c b/esp-link/main.c index 6819046..7e1ed1c 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -9,7 +9,6 @@ * ---------------------------------------------------------------------------- */ - #include #include "httpd.h" #include "httpdespfs.h" @@ -30,9 +29,13 @@ #include "config.h" #include "log.h" #include "gpio.h" +#include "syslog.h" +#include "cgiservices.h" -static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData); -static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData); +#define NOTICE(format, ...) do { \ + LOG_NOTICE(format, ## __VA_ARGS__ ); \ + os_printf(format "\n", ## __VA_ARGS__); \ +} while ( 0 ) /* This is the main url->function dispatching data struct. @@ -54,6 +57,7 @@ HttpdBuiltInUrl builtInUrls[] = { { "/pgm/upload", cgiOptibootData, NULL }, { "/log/text", ajaxLog, NULL }, { "/log/dbg", ajaxLogDbg, NULL }, + { "/log/reboot", cgiReboot, NULL }, { "/console/reset", ajaxConsoleReset, NULL }, { "/console/baud", ajaxConsoleBaud, NULL }, { "/console/text", ajaxConsole, NULL }, @@ -70,11 +74,12 @@ HttpdBuiltInUrl builtInUrls[] = { { "/wifi/special", cgiWiFiSpecial, 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 - +#endif { "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem { NULL, NULL, NULL } }; @@ -94,69 +99,6 @@ char* esp_link_version = VERS_STR(VERSION); // address of espfs binary blob extern uint32_t _binary_espfs_img_start; -static char *rst_codes[] = { - "normal", "wdt reset", "exception", "soft wdt", "restart", "deep sleep", "external", -}; -static char *flash_maps[] = { - "512KB:256/256", "256KB", "1MB:512/512", "2MB:512/512", "4MB:512/512", - "2MB:1024/1024", "4MB:1024/1024" -}; - -// Cgi to return various System information -static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { - char buff[1024]; - - if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - - uint8 part_id = system_upgrade_userbin_check(); - uint32_t fid = spi_flash_get_id(); - struct rst_info *rst_info = system_get_rst_info(); - - os_sprintf(buff, "{\"name\": \"%s\", \"reset cause\": \"%d=%s\", " - "\"size\": \"%s\"," "\"id\": \"0x%02lX 0x%04lX\"," "\"partition\": \"%s\"," - "\"slip\": \"%s\"," "\"mqtt\": \"%s/%s\"," "\"baud\": \"%ld\"," - "\"description\": \"%s\"" "}", - flashConfig.hostname, rst_info->reason, rst_codes[rst_info->reason], - flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff), - part_id ? "user2.bin" : "user1.bin", - flashConfig.slip_enable ? "enabled" : "disabled", - flashConfig.mqtt_enable ? "enabled" : "disabled", - mqttState(), flashConfig.baud_rate, flashConfig.sys_descr - ); - - jsonHeader(connData, 200); - httpdSend(connData, buff, -1); - return HTTPD_CGI_DONE; -} - -static ETSTimer reassTimer; - -// Cgi to update system info (name/description) -static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { - if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - - int8_t n = getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname)); - int8_t d = getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr)); - if (n < 0 || d < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response - - if (n > 0) { - // schedule hostname change-over - os_timer_disarm(&reassTimer); - os_timer_setfn(&reassTimer, configWifiIP, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it - } - - if (configSave()) { - httpdStartResponse(connData, 204); - httpdEndHeaders(connData); - } else { - httpdStartResponse(connData, 500); - httpdEndHeaders(connData); - httpdSend(connData, "Failed to save config", -1); - } - return HTTPD_CGI_DONE; -} - extern void app_init(void); extern void mqtt_client_init(void); @@ -168,7 +110,7 @@ void user_rf_pre_init(void) { // Main routine to initialize esp-link. void user_init(void) { // get the flash config so we know how to init things - //configWipe(); // uncomment to reset the config for testing purposes +// configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); // init gpio pin registers gpio_init(); @@ -225,18 +167,24 @@ void user_init(void) { #endif struct rst_info *rst_info = system_get_rst_info(); - os_printf("Reset cause: %d=%s\n", rst_info->reason, rst_codes[rst_info->reason]); - os_printf("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x\n", + NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]); + NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x", rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->excvaddr, rst_info->depc); uint32_t fid = spi_flash_get_id(); - os_printf("Flash map %s, manuf 0x%02lX chip 0x%04lX\n", flash_maps[system_get_flash_size_map()], + NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); + NOTICE("** esp-link ready"); + + //enableSNTP(); - os_printf("** esp-link ready\n"); #ifdef MQTT + NOTICE("initializing MQTT"); mqtt_client_init(); #endif + NOTICE("initializing user application"); app_init(); + + NOTICE("waiting for work to do..."); } diff --git a/esp-link/task.c b/esp-link/task.c new file mode 100644 index 0000000..879a694 --- /dev/null +++ b/esp-link/task.c @@ -0,0 +1,78 @@ +/* + * task.c + * + * Copyright 2015 Susi's Strolch + * + * For license information see projects "License.txt" + * + * Not sure if it's save to use ICACHE_FLASH_ATTR, so we're running from RAM + */ + +#undef USRTASK_DBG + +#include "esp8266.h" +#include + +#define MAXUSRTASKS 8 + +#ifdef USRTASK_DBG +#define DBG_USRTASK(format, ...) os_printf(format, ## __VA_ARGS__) +#else +#define DBG_USRTASK(format, ...) do { } while(0) +#endif + +LOCAL os_event_t *_task_queue = NULL; // system_os_task queue +LOCAL os_task_t *usr_task_queue = NULL; // user task queue + +// it seems save to run the usr_event_handler from RAM, so no ICACHE_FLASH_ATTR here... + +LOCAL void usr_event_handler(os_event_t *e) +{ + DBG_USRTASK("usr_event_handler: event %p (sig=%d, par=%p)\n", e, (int)e->sig, (void *)e->par); + if (usr_task_queue[e->sig] == NULL || e->sig < 0 || e->sig >= MAXUSRTASKS) { + os_printf("usr_event_handler: task %d %s\n", (int)e->sig, + usr_task_queue[e->sig] == NULL ? "not registered" : "out of range"); + return; + } + (usr_task_queue[e->sig])(e); +} + +LOCAL void init_usr_task() { + if (_task_queue == NULL) + _task_queue = (os_event_t *)os_zalloc(sizeof(os_event_t) * _task_queueLen); + + if (usr_task_queue == NULL) + usr_task_queue = (os_task_t *)os_zalloc(sizeof(os_task_t) * MAXUSRTASKS); + + system_os_task(usr_event_handler, _taskPrio, _task_queue, _task_queueLen); +} + +// public functions +bool post_usr_task(uint8_t task, os_param_t par) +{ + return system_os_post(_taskPrio, task, par); +} + +uint8_t register_usr_task (os_task_t event) +{ + int task; + + DBG_USRTASK("register_usr_task: %p\n", event); + if (_task_queue == NULL || usr_task_queue == NULL) + init_usr_task(); + + for (task = 0; task < MAXUSRTASKS; task++) { + if (usr_task_queue[task] == event) + return task; // task already registered - bail out... + } + + for (task = 0; task < MAXUSRTASKS; task++) { + if (usr_task_queue[task] == NULL) { + DBG_USRTASK("register_usr_task: assign task #%d\n", task); + usr_task_queue[task] = event; + break; + } + } + return task; +} + diff --git a/esp-link/task.h b/esp-link/task.h new file mode 100644 index 0000000..2dfd5d8 --- /dev/null +++ b/esp-link/task.h @@ -0,0 +1,20 @@ +/* + * task.h + * + * Copyright 2015 Susi's Strolch + * + * For license information see projects "License.txt" + * + * + */ + +#ifndef USRTASK_H +#define USRTASK_H + +#define _taskPrio 1 +#define _task_queueLen 64 + +uint8_t register_usr_task (os_task_t event); +bool post_usr_task(uint8_t task, os_param_t par); + +#endif diff --git a/html/console.html b/html/console.html index e638af4..6f81aca 100644 --- a/html/console.html +++ b/html/console.html @@ -5,7 +5,8 @@

- Reset µC + Reset µC + Clear Log   Baud: -   Fmt: 8N1

@@ -85,6 +73,12 @@ ); }); + $("#clear-button").addEventListener("click", function(e) { + e.preventDefault(); + var co = $("#console"); + co.innerHTML = ""; + }); + ajaxJson('GET', "/console/baud", function(data) { $("#baud-sel").value = data.rate; }, function(s, st) { showNotification(st); } diff --git a/html/console.js b/html/console.js index e85d6d7..58398ad 100644 --- a/html/console.js +++ b/html/console.js @@ -21,7 +21,7 @@ function updateText(resp) { var delay = 3000; if (resp != null && resp.len > 0) { - console.log("updateText got", resp.len, "chars at", resp.start); +// console.log("updateText got", resp.len, "chars at", resp.start); var isScrolledToBottom = el.scrollHeight - el.clientHeight <= el.scrollTop + 1; //console.log("isScrolledToBottom="+isScrolledToBottom, "scrollHeight="+el.scrollHeight, // "clientHeight="+el.clientHeight, "scrollTop="+el.scrollTop, diff --git a/html/favicon.ico b/html/favicon.ico index bf372a1..fe24a7b 100755 Binary files a/html/favicon.ico and b/html/favicon.ico differ diff --git a/html/home.html b/html/home.html index ef99429..33cbe27 100644 --- a/html/home.html +++ b/html/home.html @@ -59,20 +59,21 @@