pull/137/head
Benjamin Runnels 9 years ago
commit fd296e37d7
  1. 25
      Makefile
  2. 2
      README.adoc
  3. 4
      cmd/cmd.c
  4. 2
      cmd/handlers.c
  5. 6
      esp-link/cgi.c
  6. 2
      esp-link/cgi.h
  7. 4
      esp-link/cgiflash.c
  8. 12
      esp-link/cgioptiboot.c
  9. 2
      esp-link/cgipins.c
  10. 4
      esp-link/cgiservices.c
  11. 68
      esp-link/cgiwifi.c
  12. 2
      esp-link/config.c
  13. 10
      esp-link/config.h
  14. 10
      esp-link/main.c
  15. 26
      html/ui.js
  16. 23
      html/wifi/wifiAp.js
  17. 6
      html/wifi/wifiSta.js
  18. 104
      include/c_types.h
  19. 2
      include/user_config.h
  20. 13
      mqtt/mqtt.c
  21. 6
      mqtt/mqtt_cmd.c
  22. 15
      rest/rest.c
  23. 6
      serial/console.c
  24. 15
      syslog/syslog.c

@ -54,9 +54,26 @@ ESP_HOSTNAME ?= esp-link
# Typically you'll install https://github.com/pfalcon/esp-open-sdk # Typically you'll install https://github.com/pfalcon/esp-open-sdk
XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute # Firmware version
# Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5 # WARNING: if you change this expect to make code adjustments elsewhere, don't expect
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.5.1) # that esp-link will magically work with a different version of the SDK!!!
SDK_VERS ?= esp_iot_sdk_v1.5.2
# Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
# http://bbs.espressif.com/viewforum.php?f=46
SDK_BASE ?= $(wildcard ../$(SDK_VERS))
# If the firmware isn't there, see whether it got downloaded as part of esp-open-sdk
ifeq ($(SDK_BASE),)
SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
endif
# Clean up SDK path
SDK_BASE := $(abspath $(SDK_BASE))
$(warning Using SDK from $(SDK_BASE))
# Path to bootloader file
BOOTFILE ?= $(SDK_BASE/bin/boot_v1.5.bin)
# Esptool.py path and port, only used for 1-time serial flashing # Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool # Typically you'll use https://github.com/themadinventor/esptool
@ -215,7 +232,7 @@ LIBS = c gcc hal phy pp net80211 wpa main lwip crypto
# compiler flags using during compilation of source files # 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 \ -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections \
-D__ets__ -DICACHE_FLASH -D_STDINT_H -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \ -D__ets__ -DICACHE_FLASH -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \
-DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \ -DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \
-DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_PIN) \ -DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_PIN) \
-DVERSION="$(VERSION)" -DVERSION="$(VERSION)"

@ -20,7 +20,7 @@ The firmware includes a tiny HTTP server based on
http://www.esp8266.com/viewforum.php?f=34[esphttpd] http://www.esp8266.com/viewforum.php?f=34[esphttpd]
with a simple web interface, many thanks to Jeroen Domburg for making it available! with a simple web interface, many thanks to Jeroen Domburg for making it available!
The REST and MQTT functionality are loosely based on https://github.com/tuanpmt/espduino The REST and MQTT functionality are loosely based on https://github.com/tuanpmt/espduino
but significantly reqritten and no longer protocol compatible, thanks to tuanpmt for the but significantly rewritten and no longer protocol compatible, thanks to tuanpmt for the
inspiration! inspiration!
Many thanks to https://github.com/brunnels for contributions in particular around the espduino Many thanks to https://github.com/brunnels for contributions in particular around the espduino

@ -43,7 +43,7 @@ static uint16_t resp_crc;
// Start a response, returns the partial CRC // Start a response, returns the partial CRC
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
cmdResponseStart(uint16_t cmd, uint32_t value, uint16_t argc) { cmdResponseStart(uint16_t cmd, uint32_t value, uint16_t argc) {
DBG("cmdResponse: cmd=%d val=%ld argc=%d\n", cmd, value, argc); DBG("cmdResponse: cmd=%d val=%d argc=%d\n", cmd, value, argc);
uart0_write_char(SLIP_END); uart0_write_char(SLIP_END);
cmdProtoWriteBuf((uint8_t*)&cmd, 2); cmdProtoWriteBuf((uint8_t*)&cmd, 2);
@ -107,7 +107,7 @@ cmdParsePacket(uint8_t *buf, short len) {
uint8_t *data_ptr = (uint8_t*)&packet->args; uint8_t *data_ptr = (uint8_t*)&packet->args;
uint8_t *data_limit = data_ptr+len; uint8_t *data_limit = data_ptr+len;
DBG("cmdParsePacket: cmd=%d argc=%d value=%lu\n", DBG("cmdParsePacket: cmd=%d argc=%d value=%u\n",
packet->cmd, packet->cmd,
packet->argc, packet->argc,
packet->value packet->value

@ -62,7 +62,7 @@ cmdAddCb(char* name, uint32_t cb) {
os_strncpy(callbacks[i].name, name, sizeof(callbacks[i].name)); os_strncpy(callbacks[i].name, name, sizeof(callbacks[i].name));
callbacks[i].name[CMD_CBNLEN-1] = 0; // strncpy doesn't null terminate callbacks[i].name[CMD_CBNLEN-1] = 0; // strncpy doesn't null terminate
callbacks[i].callback = cb; callbacks[i].callback = cb;
DBG("cmdAddCb: '%s'->0x%lx added at %d\n", callbacks[i].name, cb, i); DBG("cmdAddCb: '%s'->0x%x added at %d\n", callbacks[i].name, cb, i);
return 1; return 1;
} }
} }

@ -106,18 +106,18 @@ int8_t ICACHE_FLASH_ATTR getUInt16Arg(HttpdConnData *connData, char *name, uint1
return 1; return 1;
} }
int8_t ICACHE_FLASH_ATTR getBoolArg(HttpdConnData *connData, char *name, bool *config) { int8_t ICACHE_FLASH_ATTR getBoolArg(HttpdConnData *connData, char *name, uint8_t *config) {
char buff[16]; char buff[16];
int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff)); int len = httpdFindArg(connData->getArgs, name, buff, sizeof(buff));
if (len < 0) return 0; // not found, skip if (len < 0) return 0; // not found, skip
if (os_strcmp(buff, "1") == 0 || os_strcmp(buff, "true") == 0) { if (os_strcmp(buff, "1") == 0 || os_strcmp(buff, "true") == 0) {
*config = true; *config = 1;
return 1; return 1;
} }
if (os_strcmp(buff, "0") == 0 || os_strcmp(buff, "false") == 0) { if (os_strcmp(buff, "0") == 0 || os_strcmp(buff, "false") == 0) {
*config = false; *config = 0;
return 1; return 1;
} }

@ -26,7 +26,7 @@ int8_t getUInt16Arg(HttpdConnData *connData, char *name, uint16_t *config);
// Get the HTTP query-string param 'name' and store it boolean value at '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 // 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, uint8_t *config);
int cgiMenu(HttpdConnData *connData); int cgiMenu(HttpdConnData *connData);

@ -30,7 +30,7 @@ static char* ICACHE_FLASH_ATTR check_header(void *buf) {
uint8_t *cd = (uint8_t *)buf; uint8_t *cd = (uint8_t *)buf;
#ifdef CGIFLASH_DBG #ifdef CGIFLASH_DBG
uint32_t *buf32 = buf; uint32_t *buf32 = buf;
os_printf("%p: %08lX %08lX %08lX %08lX\n", buf, buf32[0], buf32[1], buf32[2], buf32[3]); os_printf("%p: %08X %08X %08X %08X\n", buf, buf32[0], buf32[1], buf32[2], buf32[3]);
#endif #endif
if (cd[0] != 0xEA) return "IROM magic missing"; if (cd[0] != 0xEA) return "IROM magic missing";
if (cd[1] != 4 || cd[2] > 3 || (cd[3]>>4) > 6) return "bad flash header"; if (cd[1] != 4 || cd[2] > 3 || (cd[3]>>4) > 6) return "bad flash header";
@ -197,4 +197,4 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) {
os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL);
os_timer_arm(&flash_reboot_timer, 2000, 1); os_timer_arm(&flash_reboot_timer, 2000, 1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }

@ -153,7 +153,7 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) {
if (!errMessage[0] && progState >= stateProg) { if (!errMessage[0] && progState >= stateProg) {
char buf[64]; char buf[64];
DBG("OB got sync\n"); DBG("OB got sync\n");
os_sprintf(buf, "SYNC at %ld baud: bootloader v%d.%d", os_sprintf(buf, "SYNC at %d baud: bootloader v%d.%d",
baudRate, optibootVers>>8, optibootVers&0xff); baudRate, optibootVers>>8, optibootVers&0xff);
httpdSend(connData, buf, -1); httpdSend(connData, buf, -1);
} else if (errMessage[0] && progState == stateSync) { } else if (errMessage[0] && progState == stateSync) {
@ -314,7 +314,7 @@ int ICACHE_FLASH_ATTR cgiOptibootData(HttpdConnData *connData) {
float dt = ((system_get_time() - optibootData->startTime)/1000)/1000.0; // in seconds float dt = ((system_get_time() - optibootData->startTime)/1000)/1000.0; // in seconds
uint16_t pgmDone = optibootData->pgmDone; uint16_t pgmDone = optibootData->pgmDone;
optibootInit(); optibootInit();
os_sprintf(errMessage, "Success. %d bytes at %ld baud in %d.%ds, %dB/s %d%% efficient", os_sprintf(errMessage, "Success. %d bytes at %d baud in %d.%ds, %dB/s %d%% efficient",
pgmDone, baudRate, (int)dt, (int)(dt*10)%10, (int)(pgmDone/dt), pgmDone, baudRate, (int)dt, (int)(dt*10)%10, (int)(pgmDone/dt),
(int)(100.0*(10.0*pgmDone/baudRate)/dt)); (int)(100.0*(10.0*pgmDone/baudRate)/dt));
} else { } else {
@ -387,7 +387,7 @@ static bool ICACHE_FLASH_ATTR processRecord(char *buf, short len) {
optibootData->eof = true; optibootData->eof = true;
break; break;
case 0x04: // address case 0x04: // address
DBG("OB address 0x%lx\n", getHexValue(buf+8, 4) << 16); DBG("OB address 0x%x\n", getHexValue(buf+8, 4) << 16);
// program any remaining partial page // program any remaining partial page
if (optibootData->pageLen > 0) if (optibootData->pageLen > 0)
if (!programPage()) return false; if (!programPage()) return false;
@ -435,7 +435,7 @@ static bool ICACHE_FLASH_ATTR programPage(void) {
uint16_t pgmLen = optibootData->pageLen; uint16_t pgmLen = optibootData->pageLen;
if (pgmLen > optibootData->pgmSz) pgmLen = optibootData->pgmSz; if (pgmLen > optibootData->pgmSz) pgmLen = optibootData->pgmSz;
DBG("OB pgm %d@0x%lx\n", pgmLen, optibootData->address); DBG("OB pgm %d@0x%x\n", pgmLen, optibootData->address);
// send address to optiboot (little endian format) // send address to optiboot (little endian format)
#ifdef DBG_GPIO5 #ifdef DBG_GPIO5
@ -525,7 +525,7 @@ static void ICACHE_FLASH_ATTR optibootTimerCB(void *arg) {
return; return;
} }
// time to switch baud rate and issue a reset // time to switch baud rate and issue a reset
DBG("OB no sync response @%ld baud\n", baudRate); DBG("OB no sync response @%d baud\n", baudRate);
setBaud(); setBaud();
serbridgeReset(); serbridgeReset();
progState = stateInit; progState = stateInit;
@ -539,7 +539,7 @@ static void ICACHE_FLASH_ATTR optibootTimerCB(void *arg) {
return; return;
default: // we're trying to get some info from optiboot and it should have responded! default: // we're trying to get some info from optiboot and it should have responded!
optibootInit(); // abort optibootInit(); // abort
os_sprintf(errMessage, "No response in state %s(%d) @%ld baud\n", os_sprintf(errMessage, "No response in state %s(%d) @%d baud\n",
progStates[progState], progState, baudRate); progStates[progState], progState, baudRate);
DBG("OB %s\n", errMessage); DBG("OB %s\n", errMessage);
return; // do not re-arm timer return; // do not re-arm timer

@ -49,7 +49,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) {
int8_t ok = 0; int8_t ok = 0;
int8_t reset, isp, conn, ser; int8_t reset, isp, conn, ser;
bool swap, rxpup; uint8_t swap, rxpup;
ok |= getInt8Arg(connData, "reset", &reset); ok |= getInt8Arg(connData, "reset", &reset);
ok |= getInt8Arg(connData, "isp", &isp); ok |= getInt8Arg(connData, "isp", &isp);
ok |= getInt8Arg(connData, "conn", &conn); ok |= getInt8Arg(connData, "conn", &conn);

@ -66,11 +66,11 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
"\"name\": \"%s\", " "\"name\": \"%s\", "
"\"reset cause\": \"%d=%s\", " "\"reset cause\": \"%d=%s\", "
"\"size\": \"%s\", " "\"size\": \"%s\", "
"\"id\": \"0x%02lX 0x%04lX\", " "\"id\": \"0x%02X 0x%04X\", "
"\"partition\": \"%s\", " "\"partition\": \"%s\", "
"\"slip\": \"%s\", " "\"slip\": \"%s\", "
"\"mqtt\": \"%s/%s\", " "\"mqtt\": \"%s/%s\", "
"\"baud\": \"%ld\", " "\"baud\": \"%d\", "
"\"description\": \"%s\"" "\"description\": \"%s\""
" }", " }",
flashConfig.hostname, flashConfig.hostname,

@ -305,9 +305,11 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
int m = wifi_get_opmode() & 0x3; int m = wifi_get_opmode() & 0x3;
DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x); DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);
if(m!=2){ if (m == 2) return; // 2=AP, in AP-only mode we don't do any auto-switching
if ( x == STATION_GOT_IP ) {
if (m != 1) { if ( x == STATION_GOT_IP ) {
// if we got an IP we could switch to STA-only...
if (m != 1) { // 1=STA
#ifdef CHANGE_TO_STA #ifdef CHANGE_TO_STA
// We're happily connected, go to STA mode // We're happily connected, go to STA mode
DBG("Wifi got IP. Going into STA mode..\n"); DBG("Wifi got IP. Going into STA mode..\n");
@ -317,16 +319,16 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
} }
log_uart(false); log_uart(false);
// no more resetTimer at this point, gotta use physical reset to recover if in trouble // no more resetTimer at this point, gotta use physical reset to recover if in trouble
} else { } else {
if (m != 3) { // we don't have an IP address
DBG("Wifi connect failed. Going into STA+AP mode..\n"); if (m != 3) {
wifi_set_opmode(3); DBG("Wifi connect failed. Going into STA+AP mode..\n");
wifi_softap_set_config(&apconf); wifi_set_opmode(3);
wifi_softap_set_config(&apconf);
} }
log_uart(true); log_uart(true);
DBG("Enabling/continuing uart log\n"); DBG("Enabling/continuing uart log\n");
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
}
} }
} }
@ -533,7 +535,7 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
} }
// Set new SSID // Set new SSID
len=httpdFindArg(connData->getArgs, "ap_ssid", buff, sizeof(buff)); len=httpdFindArg(connData->getArgs, "ap_ssid", buff, sizeof(buff));
if(checkString(buff) && len>7 && len<32){ if(checkString(buff) && len>0 && len<=32){
// STRING PREPROCESSING DONE IN CLIENT SIDE // STRING PREPROCESSING DONE IN CLIENT SIDE
os_memset(apconf.ssid, 0, 32); os_memset(apconf.ssid, 0, 32);
os_memcpy(apconf.ssid, buff, len); os_memcpy(apconf.ssid, buff, len);
@ -545,13 +547,11 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
} }
// Set new PASSWORD // Set new PASSWORD
len=httpdFindArg(connData->getArgs, "ap_password", buff, sizeof(buff)); len=httpdFindArg(connData->getArgs, "ap_password", buff, sizeof(buff));
if(checkString(buff) && len>7 && len<64){ os_memset(apconf.password, 0, 64);
if (checkString(buff) && len>7 && len<=64) {
// String preprocessing done in client side, wifiap.js line 31 // String preprocessing done in client side, wifiap.js line 31
os_memset(apconf.password, 0, 64);
os_memcpy(apconf.password, buff, len); os_memcpy(apconf.password, buff, len);
}else if (len == 0){ } else if (len != 0) {
os_memset(apconf.password, 0, 64);
}else{
jsonHeader(connData, 400); jsonHeader(connData, 400);
httpdSend(connData, "PASSWORD not valid or out of range", -1); httpdSend(connData, "PASSWORD not valid or out of range", -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
@ -733,11 +733,17 @@ int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
uint8_t chan = wifi_get_channel(); uint8_t chan = wifi_get_channel();
len = os_sprintf(buff, len = os_sprintf(buff,
"\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", " "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", "
"\"rssi\": \"%ddB\", \"warn\": \"%s\", \"apwarn\": \"%s\",\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", " "\"phy\": \"%s\", \"rssi\": \"%ddB\", \"warn\": \"%s\", \"apwarn\": \"%s\", "
"\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", \"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"", "\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", "
mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn, "\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", "
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], chan, (char*)apconf.ssid,(char*)apconf.password,apconf.channel,apconf.max_connection,apconf.ssid_hidden?"enabled":"disabled",apconf.beacon_interval, apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4], apmac_addr[5]); "\"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"",
mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn,
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5],
chan, (char*)apconf.ssid, (char*)apconf.password, apconf.channel, apconf.max_connection,
apconf.ssid_hidden?"enabled":"disabled", apconf.beacon_interval,
apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4],
apmac_addr[5]);
struct ip_info info; struct ip_info info;
if (wifi_get_ip_info(0, &info)) { if (wifi_get_ip_info(0, &info)) {
@ -806,12 +812,9 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) {
// Check string againt invalid characters // Check string againt invalid characters
int ICACHE_FLASH_ATTR checkString(char *str){ int ICACHE_FLASH_ATTR checkString(char *str){
int i = 0; for(int i=0; i<os_strlen(str); i++) {
for(; i < os_strlen(str); i++) // We allow any printable character
{ if (str[i] < '!' || str[i] > '~') {
// Alphanumeric and underscore allowed
if (!(isalnum((unsigned char)str[i]) || str[i] == '_'))
{
DBG("Error: String has non alphanumeric chars\n"); DBG("Error: String has non alphanumeric chars\n");
return 0; return 0;
} }
@ -828,11 +831,12 @@ int ICACHE_FLASH_ATTR checkString(char *str){
*/ */
void ICACHE_FLASH_ATTR wifiInit() { void ICACHE_FLASH_ATTR wifiInit() {
// Check te wifi opmode // Check the wifi opmode
int x = wifi_get_opmode() & 0x3; int x = wifi_get_opmode() & 0x3;
// Set opmode to 3 to let system scan aps, otherwise it won't scan // If STA is enabled switch to STA+AP to allow for recovery, it will then switch to STA-only
wifi_set_opmode(3); // once it gets an IP address
if (x == 1) wifi_set_opmode(3);
// Call both STATION and SOFTAP default config // Call both STATION and SOFTAP default config
wifi_station_get_config_default(&stconf); wifi_station_get_config_default(&stconf);
@ -840,7 +844,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
DBG("Wifi init, mode=%s\n",wifiMode[x]); DBG("Wifi init, mode=%s\n",wifiMode[x]);
// STATION parameters // Change STATION parameters, if defined in the Makefile
#if defined(STA_SSID) && defined(STA_PASS) #if defined(STA_SSID) && defined(STA_PASS)
// Set parameters // Set parameters
if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) { if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) {
@ -855,7 +859,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
} }
#endif #endif
// Change SOFT_AP settings if defined // Change SOFT_AP settings, if defined in Makefile
#if defined(AP_SSID) #if defined(AP_SSID)
// Check if ssid and pass are alphanumeric values // Check if ssid and pass are alphanumeric values
int ssidlen = os_strlen(VERS_STR(AP_SSID)); int ssidlen = os_strlen(VERS_STR(AP_SSID));
@ -909,7 +913,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
// Debug info // Debug info
DBG("Wifi Soft-AP parameters change: %s\n",softap_set_conf? "success":"fail"); DBG("Wifi Soft-AP parameters change: %s\n",softap_set_conf? "success":"fail");
#endif // AP_SSID && AP_PASS #endif // if defined(AP_SSID)
configWifiIP(); configWifiIP();

@ -27,7 +27,7 @@ FlashConfig flashDefault = {
.mqtt_host = "\0", .mqtt_clientid = "\0", .mqtt_host = "\0", .mqtt_clientid = "\0",
.mqtt_username= "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0", .mqtt_username= "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0",
.sys_descr = "\0", .sys_descr = "\0",
.rx_pullup = 1, .rx_pullup = 1,
.sntp_server = "us.pool.ntp.org\0", .sntp_server = "us.pool.ntp.org\0",
.syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0, .syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0,
.mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0 .mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0

@ -13,7 +13,7 @@ typedef struct {
char hostname[32]; // if using DHCP char hostname[32]; // if using DHCP
uint32_t staticip, netmask, gateway; // using DHCP if staticip==0 uint32_t staticip, netmask, gateway; // using DHCP if staticip==0
uint8_t log_mode; // UART log debug mode uint8_t log_mode; // UART log debug mode
int8_t swap_uart; // swap uart0 to gpio 13&15 uint8_t swap_uart; // swap uart0 to gpio 13&15
uint8_t tcp_enable, rssi_enable; // TCP client settings uint8_t tcp_enable, rssi_enable; // TCP client settings
char api_key[48]; // RSSI submission API key (Grovestreams for now) char api_key[48]; // RSSI submission API key (Grovestreams for now)
uint8_t slip_enable, mqtt_enable, // SLIP protocol, MQTT client uint8_t slip_enable, mqtt_enable, // SLIP protocol, MQTT client
@ -21,9 +21,9 @@ typedef struct {
mqtt_timeout, // MQTT send timeout mqtt_timeout, // MQTT send timeout
mqtt_clean_session; // MQTT clean session mqtt_clean_session; // MQTT clean session
uint16_t mqtt_port, mqtt_keepalive; // MQTT Host port, MQTT Keepalive timer uint16_t mqtt_port, mqtt_keepalive; // MQTT Host port, MQTT Keepalive timer
char mqtt_host[32], char mqtt_host[32],
mqtt_clientid[48], mqtt_clientid[48],
mqtt_username[32], mqtt_username[32],
mqtt_password[32], mqtt_password[32],
mqtt_status_topic[32]; mqtt_status_topic[32];
char sys_descr[129]; // system description char sys_descr[129]; // system description
@ -35,7 +35,7 @@ typedef struct {
syslog_showtick, // show system tick (µs) syslog_showtick, // show system tick (µs)
syslog_showdate; // populate SYSLOG date field syslog_showdate; // populate SYSLOG date field
uint8_t mdns_enable; uint8_t mdns_enable;
char mdns_servername[32]; char mdns_servername[32];
int8_t timezone_offset; int8_t timezone_offset;
} FlashConfig; } FlashConfig;
extern FlashConfig flashConfig; extern FlashConfig flashConfig;

@ -73,7 +73,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/wifi/setmode", cgiWiFiSetMode, NULL }, { "/wifi/setmode", cgiWiFiSetMode, NULL },
{ "/wifi/special", cgiWiFiSpecial, NULL }, { "/wifi/special", cgiWiFiSpecial, NULL },
{ "/wifi/apinfo", cgiApSettingsInfo, NULL }, { "/wifi/apinfo", cgiApSettingsInfo, NULL },
{ "/wifi/apchange", cgiApSettingsChange, NULL }, { "/wifi/apchange", cgiApSettingsChange, NULL },
{ "/system/info", cgiSystemInfo, NULL }, { "/system/info", cgiSystemInfo, NULL },
{ "/system/update", cgiSystemSet, NULL }, { "/system/update", cgiSystemSet, NULL },
{ "/services/info", cgiServicesInfo, NULL }, { "/services/info", cgiServicesInfo, NULL },
@ -81,7 +81,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/pins", cgiPins, NULL }, { "/pins", cgiPins, NULL },
#ifdef MQTT #ifdef MQTT
{ "/mqtt", cgiMqtt, NULL }, { "/mqtt", cgiMqtt, NULL },
#endif #endif
{ "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem { "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };
@ -149,10 +149,10 @@ void user_init(void) {
rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
rst_info->excvaddr, rst_info->depc); rst_info->excvaddr, rst_info->depc);
uint32_t fid = spi_flash_get_id(); uint32_t fid = spi_flash_get_id();
NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()], NOTICE("Flash map %s, manuf 0x%02X chip 0x%04X", flash_maps[system_get_flash_size_map()],
fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
NOTICE("** esp-link ready"); NOTICE("** %s: ready, heap=%ld", esp_link_version, (unsigned long)system_get_free_heap_size());
// Init SNTP service // Init SNTP service
cgiServicesSNTPInit(); cgiServicesSNTPInit();
#ifdef MQTT #ifdef MQTT

@ -273,6 +273,7 @@ onLoad(function() {
var v = $("#version"); var v = $("#version");
if (v != null) { v.innerHTML = data.version; } if (v != null) { v.innerHTML = data.version; }
$('title')[0].innerHTML = data["name"];
setEditToClick("system-name", data["name"]); setEditToClick("system-name", data["name"]);
}, function() { setTimeout(getMenu, 1000); }); }, function() { setTimeout(getMenu, 1000); });
}; };
@ -303,19 +304,6 @@ function getWifiInfo() {
//===== System info //===== System info
function setEditToClick(klass, value) {
domForEach($("."+klass), function(div) {
if (div.children.length > 0) {
domForEach(div.children, function(el) {
if (el.nodeName === "INPUT") el.value = value;
else if (el.nodeName !== "DIV") el.innerHTML = value;
});
} else {
div.innerHTML = value;
}
});
}
function showSystemInfo(data) { function showSystemInfo(data) {
Object.keys(data).forEach(function(v) { Object.keys(data).forEach(function(v) {
setEditToClick("system-"+v, data[v]); setEditToClick("system-"+v, data[v]);
@ -366,6 +354,18 @@ function makeAjaxInput(klass, field) {
}); });
} }
function setEditToClick(klass, value) {
domForEach($("."+klass), function(div) {
if (div.children.length > 0) {
domForEach(div.children, function(el) {
if (el.nodeName === "INPUT") el.value = value;
else if (el.nodeName !== "DIV") el.innerHTML = value;
});
} else {
div.innerHTML = value;
}
});
}
//===== Notifications //===== Notifications

@ -26,15 +26,14 @@ function changeApSettings(e) {
if (inputs[i].type == "checkbox") { if (inputs[i].type == "checkbox") {
var val = (inputs[i].checked) ? 1 : 0; var val = (inputs[i].checked) ? 1 : 0;
url += "&" + inputs[i].name + "=" + val; url += "&" + inputs[i].name + "=" + val;
} } else {
else{ var clean = inputs[i].value.replace(/[^!-~]/g, "");
var clean = inputs[i].value.replace(/[^\w]/gi, ""); var comp = clean.localeCompare(inputs[i].value);
var comp = clean.localeCompare(inputs[i].value); if ( comp != 0 ){
if ( comp != 0 ){ showWarning("Invalid characters in " + specials[inputs[i].name]);
showWarning("Invalid characters in " + specials[inputs[i].name]); return;
return; }
} url += "&" + inputs[i].name + "=" + clean;
url += "&" + inputs[i].name + "=" + clean;
} }
}; };
@ -72,8 +71,8 @@ function displayApSettings(data) {
} else el.value = data[v]; } else el.value = data[v];
} }
}); });
$("#AP_Settings-spinner").setAttribute("hidden", ""); $("#AP_Settings-spinner").setAttribute("hidden", "");
$("#AP_Settings-form").removeAttribute("hidden"); $("#AP_Settings-form").removeAttribute("hidden");
showWarning("Don't modify SOFTAP parameters with active connections"); showWarning("Don't modify SOFTAP parameters with active connections");
window.setTimeout(hideWarning(), 2000); window.setTimeout(hideWarning(), 2000);
@ -95,4 +94,4 @@ function undoApAdvanced(){
$("#AP_Settings-on").setAttribute("hidden", ""); $("#AP_Settings-on").setAttribute("hidden", "");
$("#AP_Settings-off").removeAttribute("hidden"); $("#AP_Settings-off").removeAttribute("hidden");
$("#AP_Settings-roff").setAttribute("checked", ""); $("#AP_Settings-roff").setAttribute("checked", "");
} }

@ -14,15 +14,15 @@ function createInputForAp(ap) {
var bars = e("div"); var bars = e("div");
var rssiVal = -Math.floor(ap.rssi/51)*32; var rssiVal = -Math.floor(ap.rssi/51)*32;
bars.className = "lock-icon"; bars.className = "lock-icon";
bars.style.backgroundPosition = "0px "+rssiVal+"px"; bars.style.backgroundPosition = "0px "+(rssiVal-1)+"px";
var rssi = e("div"); var rssi = e("div");
rssi.innerHTML = "" + ap.rssi +"dB"; rssi.innerHTML = "" + ap.rssi +"dB";
var encrypt = e("div"); var encrypt = e("div");
var encVal = "-64"; //assume wpa/wpa2 var encVal = "-65"; //assume wpa/wpa2
if (ap.enc == "0") encVal = "0"; //open if (ap.enc == "0") encVal = "0"; //open
if (ap.enc == "1") encVal = "-32"; //wep if (ap.enc == "1") encVal = "-33"; //wep
encrypt.className = "lock-icon"; encrypt.className = "lock-icon";
encrypt.style.backgroundPosition = "-32px "+encVal+"px"; encrypt.style.backgroundPosition = "-32px "+encVal+"px";

@ -0,0 +1,104 @@
/*
* Copyright (c) 2010 - 2011 Espressif System
*
*/
// Modified for esp-link to confiorm with c99 using the patch included with
// esp-open-sdk https://github.com/pfalcon/esp-open-sdk/blob/master/c_types-c99.patch
// This is included here because otherwise there is a discrepancy between users that use
// the original Espressif SDK vs ones who want to use the SDK included with esp-open-sdk.
// This is a mess, if only Espressif fixed their crap!
#ifndef _C_TYPES_H_
#define _C_TYPES_H_
#include <stdint.h>
#include <stdbool.h>
//typedef unsigned char uint8_t;
typedef signed char sint8_t;
//typedef signed char int8_t;
//typedef unsigned short uint16_t;
typedef signed short sint16_t;
//typedef signed short int16_t;
//typedef unsigned long uint32_t;
typedef signed long sint32_t;
//typedef signed long int32_t;
typedef signed long long sint64_t;
//typedef unsigned long long uint64_t;
typedef unsigned long long u_int64_t;
typedef float real32_t;
typedef double real64_t;
typedef unsigned char uint8;
typedef unsigned char u8;
typedef signed char sint8;
typedef signed char int8;
typedef signed char s8;
typedef unsigned short uint16;
typedef unsigned short u16;
typedef signed short sint16;
typedef signed short s16;
typedef unsigned int uint32;
typedef unsigned int u_int;
typedef unsigned int u32;
typedef signed int sint32;
typedef signed int s32;
typedef int int32;
typedef signed long long sint64;
typedef unsigned long long uint64;
typedef unsigned long long u64;
typedef float real32;
typedef double real64;
#define __le16 u16
typedef unsigned int size_t;
#define __packed __attribute__((packed))
#define LOCAL static
#ifndef NULL
#define NULL (void *)0
#endif /* NULL */
/* probably should not put STATUS here */
typedef enum {
OK = 0,
FAIL,
PENDING,
BUSY,
CANCEL,
} STATUS;
#define BIT(nr) (1UL << (nr))
#define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b))
#define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b))
#define DMEM_ATTR __attribute__((section(".bss")))
#define SHMEM_ATTR
#ifdef ICACHE_FLASH
#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text")))
#define ICACHE_RODATA_ATTR __attribute__((section(".irom.text")))
#else
#define ICACHE_FLASH_ATTR
#define ICACHE_RODATA_ATTR
#endif /* ICACHE_FLASH */
#define STORE_ATTR __attribute__((aligned(4)))
#ifndef __cplusplus
//typedef unsigned char bool;
#define BOOL bool
//#define true (1)
//#define false (0)
#define TRUE true
#define FALSE false
#endif /* !__cplusplus */
#endif /* _C_TYPES_H_ */

@ -19,7 +19,7 @@
#define CONFIG_DBG #define CONFIG_DBG
#define LOG_DBG #define LOG_DBG
#define STATUS_DBG #define STATUS_DBG
#undef HTTPD_DBG #define HTTPD_DBG
#define MQTT_DBG #define MQTT_DBG
#define MQTTCMD_DBG #define MQTTCMD_DBG
#undef PKTBUF_DBG #undef PKTBUF_DBG

@ -497,9 +497,11 @@ mqtt_dns_found(const char* name, ip_addr_t* ipaddr, void* arg) {
if (ipaddr == NULL) { if (ipaddr == NULL) {
os_printf("MQTT: DNS lookup failed\n"); os_printf("MQTT: DNS lookup failed\n");
client->timeoutTick = client->reconTimeout; if (client != NULL) {
if (client->reconTimeout < 128) client->reconTimeout <<= 1; client->timeoutTick = client->reconTimeout;
client->connState = TCP_RECONNECT_REQ; // the timer will kick-off a reconnection if (client->reconTimeout < 128) client->reconTimeout <<= 1;
client->connState = TCP_RECONNECT_REQ; // the timer will kick-off a reconnection
}
return; return;
} }
DBG_MQTT("MQTT: ip %d.%d.%d.%d\n", DBG_MQTT("MQTT: ip %d.%d.%d.%d\n",
@ -508,7 +510,7 @@ mqtt_dns_found(const char* name, ip_addr_t* ipaddr, void* arg) {
*((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 2),
*((uint8 *)&ipaddr->addr + 3)); *((uint8 *)&ipaddr->addr + 3));
if (client->ip.addr == 0 && ipaddr->addr != 0) { if (client != NULL && client->ip.addr == 0 && ipaddr->addr != 0) {
os_memcpy(client->pCon->proto.tcp->remote_ip, &ipaddr->addr, 4); os_memcpy(client->pCon->proto.tcp->remote_ip, &ipaddr->addr, 4);
uint8_t err; uint8_t err;
if (client->security) if (client->security)
@ -705,7 +707,8 @@ MQTT_Connect(MQTT_Client* client) {
os_timer_arm(&client->mqttTimer, 1000, 1); os_timer_arm(&client->mqttTimer, 1000, 1);
// initiate the TCP connection or DNS lookup // initiate the TCP connection or DNS lookup
os_printf("MQTT: Connect to %s:%d %p\n", client->host, client->port, client->pCon); os_printf("MQTT: Connect to %s:%d %p (client=%p)\n",
client->host, client->port, client->pCon, client);
if (UTILS_StrToIP((const char *)client->host, if (UTILS_StrToIP((const char *)client->host,
(void*)&client->pCon->proto.tcp->remote_ip)) { (void*)&client->pCon->proto.tcp->remote_ip)) {
uint8_t err; uint8_t err;

@ -42,7 +42,7 @@ cmdMqttDataCb(MQTT_Client* client, const char* topic, uint32_t topic_len,
const char* data, uint32_t data_len) const char* data, uint32_t data_len)
{ {
MqttCmdCb* cb = (MqttCmdCb*)client->user_data; MqttCmdCb* cb = (MqttCmdCb*)client->user_data;
DBG("MQTT: Data cb=%p topic=%s len=%ld\n", (void*)cb->dataCb, topic, data_len); DBG("MQTT: Data cb=%p topic=%s len=%u\n", (void*)cb->dataCb, topic, data_len);
cmdResponseStart(CMD_RESP_CB, cb->dataCb, 2); cmdResponseStart(CMD_RESP_CB, cb->dataCb, 2);
cmdResponseBody(topic, topic_len); cmdResponseBody(topic, topic_len);
@ -168,7 +168,7 @@ MQTTCMD_Subscribe(CmdPacket *cmd) {
uint32_t qos = 0; uint32_t qos = 0;
cmdPopArg(&req, (uint8_t*)&qos, 4); cmdPopArg(&req, (uint8_t*)&qos, 4);
DBG("MQTT: MQTTCMD_Subscribe topic=%s, qos=%ld\n", topic, qos); DBG("MQTT: MQTTCMD_Subscribe topic=%s, qos=%u\n", topic, qos);
MQTT_Subscribe(client, (char*)topic, (uint8_t)qos); MQTT_Subscribe(client, (char*)topic, (uint8_t)qos);
os_free(topic); os_free(topic);
@ -245,7 +245,7 @@ MQTTCMD_Setup(CmdPacket *cmd) {
cmdPopArg(&req, &callback->dataCb, 4); cmdPopArg(&req, &callback->dataCb, 4);
client->user_data = callback; client->user_data = callback;
DBG("MQTT connectedCb=%lx\n", callback->connectedCb); DBG("MQTT connectedCb=%x\n", callback->connectedCb);
client->cmdConnectedCb = cmdMqttConnectedCb; client->cmdConnectedCb = cmdMqttConnectedCb;
client->cmdDisconnectedCb = cmdMqttDisconnectedCb; client->cmdDisconnectedCb = cmdMqttDisconnectedCb;

@ -200,7 +200,8 @@ rest_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) {
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
REST_Setup(CmdPacket *cmd) { REST_Setup(CmdPacket *cmd) {
CmdRequest req; CmdRequest req;
uint32_t port, security; uint16_t port;
uint8_t security;
int32_t err = -1; // error code in case of failure int32_t err = -1; // error code in case of failure
// start parsing the command // start parsing the command
@ -252,7 +253,7 @@ REST_Setup(CmdPacket *cmd) {
os_free(client->pCon); os_free(client->pCon);
} }
os_memset(client, 0, sizeof(RestClient)); os_memset(client, 0, sizeof(RestClient));
DBG_REST("REST: setup #%d host=%s port=%ld security=%ld\n", clientNum, rest_host, port, security); DBG_REST("REST: setup #%d host=%s port=%d security=%d\n", clientNum, rest_host, port, security);
client->resp_cb = cmd->value; client->resp_cb = cmd->value;
@ -348,7 +349,7 @@ REST_Request(CmdPacket *cmd) {
// Get client // Get client
uint32_t clientNum = cmd->value; uint32_t clientNum = cmd->value;
RestClient *client = restClient + (clientNum % MAX_REST); RestClient *client = restClient + (clientNum % MAX_REST);
DBG_REST(" #%ld", clientNum); DBG_REST(" #%d", clientNum);
// Get HTTP method // Get HTTP method
uint16_t len = cmdArgLen(&req); uint16_t len = cmdArgLen(&req);
@ -374,7 +375,7 @@ REST_Request(CmdPacket *cmd) {
realLen = cmdArgLen(&req); realLen = cmdArgLen(&req);
if (realLen > 2048) goto fail; if (realLen > 2048) goto fail;
} }
DBG_REST(" bodyLen=%ld", realLen); DBG_REST(" bodyLen=%d", realLen);
// we need to allocate memory for the header plus the body. First we count the length of the // we need to allocate memory for the header plus the body. First we count the length of the
// header (including some extra counted "%s" and then we add the body length. We allocate the // header (including some extra counted "%s" and then we add the body length. We allocate the
@ -393,7 +394,7 @@ REST_Request(CmdPacket *cmd) {
if (client->data) os_free(client->data); if (client->data) os_free(client->data);
client->data = (char*)os_zalloc(headerLen + realLen); client->data = (char*)os_zalloc(headerLen + realLen);
if (client->data == NULL) goto fail; if (client->data == NULL) goto fail;
DBG_REST(" totLen=%ld data=%p", headerLen + realLen, client->data); DBG_REST(" totLen=%d data=%p", headerLen + realLen, client->data);
client->data_len = os_sprintf((char*)client->data, headerFmt, method, path, client->host, client->data_len = os_sprintf((char*)client->data, headerFmt, method, path, client->host,
client->header, realLen, client->content_type, client->user_agent); client->header, realLen, client->content_type, client->user_agent);
DBG_REST(" hdrLen=%d", client->data_len); DBG_REST(" hdrLen=%d", client->data_len);
@ -412,7 +413,7 @@ REST_Request(CmdPacket *cmd) {
espconn_regist_reconcb(client->pCon, tcpclient_recon_cb); espconn_regist_reconcb(client->pCon, tcpclient_recon_cb);
if(UTILS_StrToIP((char *)client->host, &client->pCon->proto.tcp->remote_ip)) { if(UTILS_StrToIP((char *)client->host, &client->pCon->proto.tcp->remote_ip)) {
DBG_REST("REST: Connect to ip %s:%ld\n",client->host, client->port); DBG_REST("REST: Connect to ip %s:%d\n",client->host, client->port);
//if(client->security){ //if(client->security){
// espconn_secure_connect(client->pCon); // espconn_secure_connect(client->pCon);
//} //}
@ -420,7 +421,7 @@ REST_Request(CmdPacket *cmd) {
espconn_connect(client->pCon); espconn_connect(client->pCon);
//} //}
} else { } else {
DBG_REST("REST: Connect to host %s:%ld\n", client->host, client->port); DBG_REST("REST: Connect to host %s:%d\n", client->host, client->port);
espconn_gethostbyname(client->pCon, (char *)client->host, &client->ip, rest_dns_found); espconn_gethostbyname(client->pCon, (char *)client->host, &client->ip, rest_dns_found);
} }

@ -76,7 +76,7 @@ ajaxConsoleBaud(HttpdConnData *connData) {
} }
jsonHeader(connData, status); jsonHeader(connData, status);
os_sprintf(buff, "{\"rate\": %ld}", flashConfig.baud_rate); os_sprintf(buff, "{\"rate\": %d}", flashConfig.baud_rate);
httpdSend(connData, buff, -1); httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
@ -86,14 +86,14 @@ ajaxConsoleSend(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[2048]; char buff[2048];
int len, status = 400; int len, status = 400;
// figure out where to start in buffer based on URI param // figure out where to start in buffer based on URI param
len = httpdFindArg(connData->getArgs, "text", buff, sizeof(buff)); len = httpdFindArg(connData->getArgs, "text", buff, sizeof(buff));
if (len > 0) { if (len > 0) {
uart0_tx_buffer(buff, len); uart0_tx_buffer(buff, len);
status = 200; status = 200;
} }
jsonHeader(connData, status); jsonHeader(connData, status);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }

@ -156,8 +156,8 @@ static void ICACHE_FLASH_ATTR syslog_chk_status(void)
} }
} else { } else {
if ((wifi_status == STATION_WRONG_PASSWORD || if ((wifi_status == STATION_WRONG_PASSWORD ||
wifi_status == STATION_NO_AP_FOUND || wifi_status == STATION_NO_AP_FOUND ||
wifi_status == STATION_CONNECT_FAIL)) { wifi_status == STATION_CONNECT_FAIL)) {
syslog_set_status(SYSLOG_ERROR); syslog_set_status(SYSLOG_ERROR);
os_printf("*** connect failure!!!\n"); os_printf("*** connect failure!!!\n");
} else { } else {
@ -273,7 +273,7 @@ void ICACHE_FLASH_ATTR syslog_init(char *syslog_host)
if (syslog_espconn->proto.udp) { if (syslog_espconn->proto.udp) {
// there's no counterpart to espconn_create... // there's no counterpart to espconn_create...
os_free(syslog_espconn->proto.udp); os_free(syslog_espconn->proto.udp);
} }
os_free(syslog_espconn); os_free(syslog_espconn);
} }
syslog_espconn = NULL; syslog_espconn = NULL;
@ -380,6 +380,7 @@ syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *
{ {
DBG("[%dµs] %s id=%lu\n", WDEV_NOW(), __FUNCTION__, syslog_msgid); DBG("[%dµs] %s id=%lu\n", WDEV_NOW(), __FUNCTION__, syslog_msgid);
syslog_entry_t *se = os_zalloc(sizeof (syslog_entry_t) + 1024); // allow up to 1k datagram syslog_entry_t *se = os_zalloc(sizeof (syslog_entry_t) + 1024); // allow up to 1k datagram
if (se == NULL) return NULL;
char *p = se->datagram; char *p = se->datagram;
se->tick = WDEV_NOW(); // 0 ... 4294.967295s se->tick = WDEV_NOW(); // 0 ... 4294.967295s
se->msgid = syslog_msgid; se->msgid = syslog_msgid;
@ -405,16 +406,17 @@ syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *
tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday, tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec); tp->tm_hour, tp->tm_min, tp->tm_sec);
if (realtime_stamp == 0) if (realtime_stamp == 0)
p += os_sprintf(p, ".%06luZ ", se->tick % 1000000); p += os_sprintf(p, ".%06uZ ", se->tick % 1000000);
else else
p += os_sprintf(p, "%+03d:00 ", flashConfig.timezone_offset); p += os_sprintf(p, "%+03d:00 ", flashConfig.timezone_offset);
} }
// add HOSTNAME APP-NAME PROCID MSGID // add HOSTNAME APP-NAME PROCID MSGID
if (flashConfig.syslog_showtick) if (flashConfig.syslog_showtick)
p += os_sprintf(p, "%s %s %lu.%06lu %lu ", flashConfig.hostname, tag, se->tick / 1000000, se->tick % 1000000, syslog_msgid++); p += os_sprintf(p, "%s %s %u.%06u %u ", flashConfig.hostname, tag, se->tick / 1000000,
se->tick % 1000000, syslog_msgid++);
else else
p += os_sprintf(p, "%s %s - %lu ", flashConfig.hostname, tag, syslog_msgid++); p += os_sprintf(p, "%s %s - %u ", flashConfig.hostname, tag, syslog_msgid++);
// append syslog message // append syslog message
va_list arglist; va_list arglist;
@ -512,6 +514,7 @@ void ICACHE_FLASH_ATTR syslog(uint8_t facility, uint8_t severity, const char *ta
// compose the syslog message // compose the syslog message
void *arg = __builtin_apply_args(); void *arg = __builtin_apply_args();
void *res = __builtin_apply((void*)syslog_compose, arg, 128); void *res = __builtin_apply((void*)syslog_compose, arg, 128);
if (res == NULL) return; // compose failed, probably due to malloc failure
syslog_entry_t *se = *(syslog_entry_t **)res; syslog_entry_t *se = *(syslog_entry_t **)res;
// and append it to the message queue // and append it to the message queue

Loading…
Cancel
Save