Syslog and debug printing fixes
pull/140/merge
susisstrolch 9 years ago committed by Thorsten von Eicken
parent b56b2767cb
commit e3e19ffa38
  1. 36
      Makefile
  2. 2
      cmd/handlers.c
  3. 2
      esp-link/cgi.c
  4. 2
      esp-link/cgiflash.c
  5. 2
      esp-link/cgimqtt.c
  6. 2
      esp-link/cgioptiboot.c
  7. 2
      esp-link/cgiservices.c
  8. 73
      esp-link/cgiwifi.c
  9. 2
      esp-link/log.c
  10. 2
      esp-link/main.c
  11. 2
      esp-link/mqtt_client.c
  12. 11
      esp-link/task.c
  13. 2
      httpd/httpd.c
  14. 56
      mqtt/mqtt.c
  15. 2
      mqtt/mqtt_cmd.c
  16. 52
      rest/rest.c
  17. 2
      serial/slip.c
  18. 8
      serial/uart.c
  19. 67
      syslog/syslog.c
  20. 10
      user/user_main.c

@ -13,6 +13,9 @@
# `VERBOSE=1 make ...` will print debug info # `VERBOSE=1 make ...` will print debug info
# `ESP_HOSTNAME=my.esp.example.com make wiflash` is an easy way to override a variable # `ESP_HOSTNAME=my.esp.example.com make wiflash` is an easy way to override a variable
# CFLAGS may be changed by local.conf
CFLAGS=
# optional local configuration file # optional local configuration file
-include local.conf -include local.conf
@ -54,17 +57,25 @@ 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 (if you change this expect to make code adjustments elsewhere!)
ifneq ($(wildcard ../esp-open-sdk/esp_iot_sdk_v1.5.2/.*),) SDK_VERS ?= esp_iot_sdk_v1.5.2
# One that has been extracted as part of open-sdk
SDK_BASE ?= $(abspath ../esp-open-sdk/esp_iot_sdk_v1.5.2) # Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
else # http://bbs.espressif.com/viewforum.php?f=46
ifneq ($(wildcard ../esp_iot_sdk_v1.5.1/.*),) SDK_BASE ?= $(wildcard ../$(SDK_VERS))
# Manually downloaded from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.5.1) # If the firmware isn't there, see whether it got downloaded as part of esp-open-sdk
endif ifeq ($(SDK_BASE),)
SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
endif 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
# Windows users use the com port i.e: ESPPORT ?= com3 # Windows users use the com port i.e: ESPPORT ?= com3
@ -195,8 +206,6 @@ TARGET = httpd
# espressif tool to concatenate sections for OTA upload using bootloader v1.2+ # espressif tool to concatenate sections for OTA upload using bootloader v1.2+
APPGEN_TOOL ?= gen_appbin.py APPGEN_TOOL ?= gen_appbin.py
CFLAGS=
# set defines for optional modules # set defines for optional modules
ifneq (,$(findstring mqtt,$(MODULES))) ifneq (,$(findstring mqtt,$(MODULES)))
CFLAGS += -DMQTT CFLAGS += -DMQTT
@ -333,6 +342,7 @@ all: echo_version checkdirs $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin
echo_version: echo_version:
@echo VERSION: $(VERSION) @echo VERSION: $(VERSION)
@echo MODULES: $(MODULES)
$(USER1_OUT): $(APP_AR) $(LD_SCRIPT1) $(USER1_OUT): $(APP_AR) $(LD_SCRIPT1)
$(vecho) "LD $@" $(vecho) "LD $@"
@ -389,7 +399,7 @@ baseflash: all
flash: all flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \ $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" 0x01000 $(FW_BASE)/user1.bin \ 0x00000 "$(BOOTFILE)" 0x01000 $(FW_BASE)/user1.bin \
$(ET_BLANK) $(SDK_BASE)/bin/blank.bin $(ET_BLANK) $(SDK_BASE)/bin/blank.bin
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
@ -471,7 +481,7 @@ release: all
$(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user1.bin | cut -b 1-80 $(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user1.bin | cut -b 1-80
$(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user2.bin | cut -b 1-80 $(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user2.bin | cut -b 1-80
$(Q) cp $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(SDK_BASE)/bin/blank.bin \ $(Q) cp $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(SDK_BASE)/bin/blank.bin \
"$(SDK_BASE)/bin/boot_v1.5.bin" wiflash avrflash release/esp-link-$(BRANCH) "$(BOOTFILE)" wiflash avrflash release/esp-link-$(BRANCH)
$(Q) tar zcf esp-link-$(BRANCH).tgz -C release esp-link-$(BRANCH) $(Q) tar zcf esp-link-$(BRANCH).tgz -C release esp-link-$(BRANCH)
$(Q) echo "Release file: esp-link-$(BRANCH).tgz" $(Q) echo "Release file: esp-link-$(BRANCH).tgz"
$(Q) rm -rf release $(Q) rm -rf release

@ -13,7 +13,7 @@
#endif #endif
#ifdef CMD_DBG #ifdef CMD_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -18,7 +18,7 @@ Some random cgi routines.
#include "config.h" #include "config.h"
#ifdef CGI_DBG #ifdef CGI_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -20,7 +20,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati
#include "cgiflash.h" #include "cgiflash.h"
#ifdef CGIFLASH_DBG #ifdef CGIFLASH_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -17,7 +17,7 @@ char *mqttState(void) {
#include "cgimqtt.h" #include "cgimqtt.h"
#ifdef CGIMQTT_DBG #ifdef CGIMQTT_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -17,7 +17,7 @@
#define ATTEMPTS 8 // number of attempts total to make #define ATTEMPTS 8 // number of attempts total to make
#ifdef OPTIBOOT_DBG #ifdef OPTIBOOT_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -7,7 +7,7 @@
#include "cgimqtt.h" #include "cgimqtt.h"
#ifdef CGISERVICES_DBG #ifdef CGISERVICES_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -19,13 +19,34 @@ Cgi/template routines for the /wifi url.
#include "status.h" #include "status.h"
#include "config.h" #include "config.h"
#include "log.h" #include "log.h"
#include "syslog.h"
#ifdef CGIWIFI_DBG #ifdef CGIWIFI_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
#define LOG(severity, format, ...) do { \
char buffer[128]; \
os_sprintf(buffer, format, ## __VA_ARGS__); \
syslog(SYSLOG_FAC_USER, severity, "WIFI", buffer); \
DBG("%s %s\n", "WIFI", buffer); \
} while(0)
#define NOTICE(format, ...) do { \
LOG(SYSLOG_PRIO_NOTICE, format, ## __VA_ARGS__); \
} while(0)
#define INFO(format, ...) do { \
LOG(SYSLOG_PRIO_INFO, format, ## __VA_ARGS__); \
} while(0)
#define WARNING(format, ...) do { \
LOG(SYSLOG_PRIO_WARNING, format, ## __VA_ARGS__); \
} while(0)
# define VERS_STR_STR(V) #V # define VERS_STR_STR(V) #V
# define VERS_STR(V) VERS_STR_STR(V) # define VERS_STR(V) VERS_STR_STR(V)
@ -34,7 +55,7 @@ bool mdns_started = false;
// ===== wifi status change callbacks // ===== wifi status change callbacks
static WifiStateChangeCb wifi_state_change_cb[4]; static WifiStateChangeCb wifi_state_change_cb[4];
// Temp store for new staion config // Temp store for new station config
struct station_config stconf; struct station_config stconf;
// Temp store for new ap config // Temp store for new ap config
@ -68,25 +89,25 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) {
case EVENT_STAMODE_CONNECTED: case EVENT_STAMODE_CONNECTED:
wifiState = wifiIsConnected; wifiState = wifiIsConnected;
wifiReason = 0; wifiReason = 0;
DBG("Wifi connected to ssid %s, ch %d\n", evt->event_info.connected.ssid, NOTICE("connected to ssid %s, ch %d", evt->event_info.connected.ssid,
evt->event_info.connected.channel); evt->event_info.connected.channel);
statusWifiUpdate(wifiState); statusWifiUpdate(wifiState);
break; break;
case EVENT_STAMODE_DISCONNECTED: case EVENT_STAMODE_DISCONNECTED:
wifiState = wifiIsDisconnected; wifiState = wifiIsDisconnected;
wifiReason = evt->event_info.disconnected.reason; wifiReason = evt->event_info.disconnected.reason;
DBG("Wifi disconnected from ssid %s, reason %s (%d)\n", WARNING("disconnected from ssid %s, reason %s (%d)",
evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason); evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason);
statusWifiUpdate(wifiState); statusWifiUpdate(wifiState);
break; break;
case EVENT_STAMODE_AUTHMODE_CHANGE: case EVENT_STAMODE_AUTHMODE_CHANGE:
DBG("Wifi auth mode: %d -> %d\n", NOTICE("auth mode: %d -> %d",
evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode); evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode);
break; break;
case EVENT_STAMODE_GOT_IP: case EVENT_STAMODE_GOT_IP:
wifiState = wifiGotIP; wifiState = wifiGotIP;
wifiReason = 0; wifiReason = 0;
DBG("Wifi got ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n", NOTICE("got ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask), IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask),
IP2STR(&evt->event_info.got_ip.gw)); IP2STR(&evt->event_info.got_ip.gw));
statusWifiUpdate(wifiState); statusWifiUpdate(wifiState);
@ -94,11 +115,11 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) {
wifiStartMDNS(evt->event_info.got_ip.ip); wifiStartMDNS(evt->event_info.got_ip.ip);
break; break;
case EVENT_SOFTAPMODE_STACONNECTED: case EVENT_SOFTAPMODE_STACONNECTED:
DBG("Wifi AP: station " MACSTR " joined, AID = %d\n", NOTICE("AP: station " MACSTR " joined, AID = %d",
MAC2STR(evt->event_info.sta_connected.mac), evt->event_info.sta_connected.aid); MAC2STR(evt->event_info.sta_connected.mac), evt->event_info.sta_connected.aid);
break; break;
case EVENT_SOFTAPMODE_STADISCONNECTED: case EVENT_SOFTAPMODE_STADISCONNECTED:
DBG("Wifi AP: station " MACSTR " left, AID = %d\n", NOTICE("AP: station " MACSTR " left, AID = %d",
MAC2STR(evt->event_info.sta_disconnected.mac), evt->event_info.sta_disconnected.aid); MAC2STR(evt->event_info.sta_disconnected.mac), evt->event_info.sta_disconnected.aid);
break; break;
default: default:
@ -118,7 +139,7 @@ void ICACHE_FLASH_ATTR wifiAddStateChangeCb(WifiStateChangeCb cb) {
return; return;
} }
} }
DBG("WIFI: max state change cb count exceeded\n"); WARNING("max state change cb count exceeded");
} }
void ICACHE_FLASH_ATTR wifiStartMDNS(struct ip_addr ip) { void ICACHE_FLASH_ATTR wifiStartMDNS(struct ip_addr ip) {
@ -163,7 +184,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
struct bss_info *bss_link = (struct bss_info *)arg; struct bss_info *bss_link = (struct bss_info *)arg;
if (status!=OK) { if (status!=OK) {
DBG("wifiScanDoneCb status=%d\n", status); WARNING("wifiScanDoneCb status=%d", status);
cgiWifiAps.scanInProgress=0; cgiWifiAps.scanInProgress=0;
return; return;
} }
@ -183,7 +204,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
//Allocate memory for access point data //Allocate memory for access point data
cgiWifiAps.apData=(ApData **)os_malloc(sizeof(ApData *)*n); cgiWifiAps.apData=(ApData **)os_malloc(sizeof(ApData *)*n);
cgiWifiAps.noAps=n; cgiWifiAps.noAps=n;
DBG("Scan done: found %d APs\n", n); INFO("Scan done: found %d APs", n);
//Copy access point data to the static struct //Copy access point data to the static struct
n=0; n=0;
@ -192,7 +213,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
if (n>=cgiWifiAps.noAps) { if (n>=cgiWifiAps.noAps) {
//This means the bss_link changed under our nose. Shouldn't happen! //This means the bss_link changed under our nose. Shouldn't happen!
//Break because otherwise we will write in unallocated memory. //Break because otherwise we will write in unallocated memory.
DBG("Huh? I have more than the allocated %d aps!\n", cgiWifiAps.noAps); WARNING("Huh? I have more than the allocated %d aps!", cgiWifiAps.noAps);
break; break;
} }
//Save the ap data. //Save the ap data.
@ -200,7 +221,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
cgiWifiAps.apData[n]->rssi=bss_link->rssi; cgiWifiAps.apData[n]->rssi=bss_link->rssi;
cgiWifiAps.apData[n]->enc=bss_link->authmode; cgiWifiAps.apData[n]->enc=bss_link->authmode;
strncpy(cgiWifiAps.apData[n]->ssid, (char*)bss_link->ssid, 32); strncpy(cgiWifiAps.apData[n]->ssid, (char*)bss_link->ssid, 32);
DBG("bss%d: %s (%d)\n", n+1, (char*)bss_link->ssid, bss_link->rssi); INFO("bss%d: %s (%d)", n+1, (char*)bss_link->ssid, bss_link->rssi);
bss_link = bss_link->next.stqe_next; bss_link = bss_link->next.stqe_next;
n++; n++;
@ -211,7 +232,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
static ETSTimer scanTimer; static ETSTimer scanTimer;
static void ICACHE_FLASH_ATTR scanStartCb(void *arg) { static void ICACHE_FLASH_ATTR scanStartCb(void *arg) {
DBG("Starting a scan\n"); INFO("Starting a scan");
wifi_station_scan(NULL, wifiScanDoneCb); wifi_station_scan(NULL, wifiScanDoneCb);
} }
@ -303,28 +324,28 @@ static ETSTimer resetTimer;
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
int x = wifi_station_get_connect_status(); int x = wifi_station_get_connect_status();
int m = wifi_get_opmode() & 0x3; int m = wifi_get_opmode() & 0x3;
DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x); NOTICE("check: mode=%s status=%d", wifiMode[m], x);
if(m!=2){ if(m!=2){
if ( x == STATION_GOT_IP ) { if ( x == STATION_GOT_IP ) {
if (m != 1) { if (m != 1) {
#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"); NOTICE("got IP. Going into STA mode..");
wifi_set_opmode(1); wifi_set_opmode(1);
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
#endif #endif
} }
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) { if (m != 3) {
DBG("Wifi connect failed. Going into STA+AP mode..\n"); NOTICE("connect failed. Going into STA+AP mode..");
wifi_set_opmode(3); wifi_set_opmode(3);
wifi_softap_set_config(&apconf); wifi_softap_set_config(&apconf);
} }
log_uart(true); log_uart(true);
DBG("Enabling/continuing uart log\n"); INFO("Enabling/continuing uart log");
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
} }
} }
@ -335,7 +356,7 @@ static ETSTimer reassTimer;
// Callback actually doing reassociation // Callback actually doing reassociation
static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) { static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) {
DBG("Wifi changing association\n"); NOTICE("changing association");
wifi_station_disconnect(); wifi_station_disconnect();
stconf.bssid_set = 0; stconf.bssid_set = 0;
wifi_station_set_config(&stconf); wifi_station_set_config(&stconf);
@ -369,7 +390,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
//Set to 0 if you want to disable the actual reconnecting bit //Set to 0 if you want to disable the actual reconnecting bit
os_strncpy((char*)stconf.ssid, essid, 32); os_strncpy((char*)stconf.ssid, essid, 32);
os_strncpy((char*)stconf.password, passwd, 64); os_strncpy((char*)stconf.password, passwd, 64);
DBG("Wifi try to connect to AP %s pw %s\n", essid, passwd); NOTICE("try to connect to AP %s pw %s", essid, passwd);
//Schedule disconnect/connect //Schedule disconnect/connect
os_timer_disarm(&reassTimer); os_timer_disarm(&reassTimer);
@ -430,7 +451,7 @@ void ICACHE_FLASH_ATTR configWifiIP() {
if (wifi_station_dhcpc_status() == DHCP_STARTED) if (wifi_station_dhcpc_status() == DHCP_STARTED)
wifi_station_dhcpc_stop(); wifi_station_dhcpc_stop();
wifi_station_dhcpc_start(); wifi_station_dhcpc_start();
DBG("Wifi uses DHCP, hostname=%s\n", flashConfig.hostname); NOTICE("uses DHCP, hostname=%s", flashConfig.hostname);
} else { } else {
// no DHCP, we got static network config! // no DHCP, we got static network config!
wifi_station_dhcpc_stop(); wifi_station_dhcpc_stop();
@ -439,7 +460,7 @@ void ICACHE_FLASH_ATTR configWifiIP() {
ipi.netmask.addr = flashConfig.netmask; ipi.netmask.addr = flashConfig.netmask;
ipi.gw.addr = flashConfig.gateway; ipi.gw.addr = flashConfig.gateway;
wifi_set_ip_info(0, &ipi); wifi_set_ip_info(0, &ipi);
DBG("Wifi uses static IP %d.%d.%d.%d\n", IP2STR(&ipi.ip.addr)); NOTICE("uses static IP %d.%d.%d.%d", IP2STR(&ipi.ip.addr));
} }
#ifdef DEBUGIP #ifdef DEBUGIP
debugIP(); debugIP();

@ -7,7 +7,7 @@
#include "log.h" #include "log.h"
#ifdef LOG_DBG #ifdef LOG_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -151,7 +151,7 @@ void user_init(void) {
uint32_t fid = spi_flash_get_id(); uint32_t fid = spi_flash_get_id();
NOTICE("Flash map %s, manuf 0x%02X chip 0x%04X", 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();

@ -5,7 +5,7 @@
#include "mqtt.h" #include "mqtt.h"
#ifdef MQTTCLIENT_DBG #ifdef MQTTCLIENT_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__) } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -16,19 +16,18 @@
#define MAXUSRTASKS 8 #define MAXUSRTASKS 8
#ifdef USRTASK_DBG #ifdef USRTASK_DBG
#define DBG_USRTASK(format, ...) os_printf(format, ## __VA_ARGS__) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG_USRTASK(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
LOCAL os_event_t *_task_queue = NULL; // system_os_task queue LOCAL os_event_t *_task_queue = NULL; // system_os_task queue
LOCAL os_task_t *usr_task_queue = NULL; // user 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... // 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) 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); DBG("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) { 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, os_printf("usr_event_handler: task %d %s\n", (int)e->sig,
usr_task_queue[e->sig] == NULL ? "not registered" : "out of range"); usr_task_queue[e->sig] == NULL ? "not registered" : "out of range");
@ -57,7 +56,7 @@ uint8_t register_usr_task (os_task_t event)
{ {
int task; int task;
DBG_USRTASK("register_usr_task: %p\n", event); DBG("register_usr_task: %p\n", event);
if (_task_queue == NULL || usr_task_queue == NULL) if (_task_queue == NULL || usr_task_queue == NULL)
init_usr_task(); init_usr_task();
@ -68,7 +67,7 @@ uint8_t register_usr_task (os_task_t event)
for (task = 0; task < MAXUSRTASKS; task++) { for (task = 0; task < MAXUSRTASKS; task++) {
if (usr_task_queue[task] == NULL) { if (usr_task_queue[task] == NULL) {
DBG_USRTASK("register_usr_task: assign task #%d\n", task); DBG("register_usr_task: assign task #%d\n", task);
usr_task_queue[task] = event; usr_task_queue[task] = event;
break; break;
} }

@ -18,7 +18,7 @@ Esp8266 http server - core routines
#include "httpd.h" #include "httpd.h"
#ifdef HTTPD_DBG #ifdef HTTPD_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...)os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -42,9 +42,9 @@
#include "mqtt.h" #include "mqtt.h"
#ifdef MQTT_DBG #ifdef MQTT_DBG
#define DBG_MQTT(format, ...) os_printf(format, ## __VA_ARGS__) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG_MQTT(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
extern void dumpMem(void *buf, int len); extern void dumpMem(void *buf, int len);
@ -145,7 +145,7 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {
if (client->connState != MQTT_CONNECTED) { if (client->connState != MQTT_CONNECTED) {
// why are we receiving something?? // why are we receiving something??
DBG_MQTT("MQTT ERROR: recv in invalid state %d\n", client->connState); DBG("MQTT ERROR: recv in invalid state %d\n", client->connState);
mqtt_doAbort(client); mqtt_doAbort(client);
return; return;
} }
@ -157,12 +157,12 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {
pending_msg_type = mqtt_get_type(client->pending_buffer->data); pending_msg_type = mqtt_get_type(client->pending_buffer->data);
pending_msg_id = mqtt_get_id(client->pending_buffer->data, client->pending_buffer->filled); pending_msg_id = mqtt_get_id(client->pending_buffer->data, client->pending_buffer->filled);
} }
DBG_MQTT("MQTT: Recv type=%s id=%04X len=%d; Pend type=%s id=%02X\n", DBG("MQTT: Recv type=%s id=%04X len=%d; Pend type=%s id=%02X\n",
mqtt_msg_type[msg_type], msg_id, msg_len, mqtt_msg_type[pending_msg_type],pending_msg_id); mqtt_msg_type[msg_type], msg_id, msg_len, mqtt_msg_type[pending_msg_type],pending_msg_id);
switch (msg_type) { switch (msg_type) {
case MQTT_MSG_TYPE_CONNACK: case MQTT_MSG_TYPE_CONNACK:
//DBG_MQTT("MQTT: Connect successful\n"); //DBG("MQTT: Connect successful\n");
// callbacks for internal and external clients // callbacks for internal and external clients
if (client->connectedCb) client->connectedCb(client); if (client->connectedCb) client->connectedCb(client);
if (client->cmdConnectedCb) client->cmdConnectedCb(client); if (client->cmdConnectedCb) client->cmdConnectedCb(client);
@ -171,28 +171,28 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {
case MQTT_MSG_TYPE_SUBACK: case MQTT_MSG_TYPE_SUBACK:
if (pending_msg_type == MQTT_MSG_TYPE_SUBSCRIBE && pending_msg_id == msg_id) { if (pending_msg_type == MQTT_MSG_TYPE_SUBSCRIBE && pending_msg_id == msg_id) {
//DBG_MQTT("MQTT: Subscribe successful\n"); //DBG("MQTT: Subscribe successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer); client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
} }
break; break;
case MQTT_MSG_TYPE_UNSUBACK: case MQTT_MSG_TYPE_UNSUBACK:
if (pending_msg_type == MQTT_MSG_TYPE_UNSUBSCRIBE && pending_msg_id == msg_id) { if (pending_msg_type == MQTT_MSG_TYPE_UNSUBSCRIBE && pending_msg_id == msg_id) {
//DBG_MQTT("MQTT: Unsubscribe successful\n"); //DBG("MQTT: Unsubscribe successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer); client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
} }
break; break;
case MQTT_MSG_TYPE_PUBACK: // ack for a publish we sent case MQTT_MSG_TYPE_PUBACK: // ack for a publish we sent
if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) { if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) {
//DBG_MQTT("MQTT: QoS1 Publish successful\n"); //DBG("MQTT: QoS1 Publish successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer); client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
} }
break; break;
case MQTT_MSG_TYPE_PUBREC: // rec for a publish we sent case MQTT_MSG_TYPE_PUBREC: // rec for a publish we sent
if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) { if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) {
//DBG_MQTT("MQTT: QoS2 publish cont\n"); //DBG("MQTT: QoS2 publish cont\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer); client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
// we need to send PUBREL // we need to send PUBREL
mqtt_msg_pubrel(&client->mqtt_connection, msg_id); mqtt_msg_pubrel(&client->mqtt_connection, msg_id);
@ -203,7 +203,7 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {
case MQTT_MSG_TYPE_PUBCOMP: // comp for a pubrel we sent (originally publish we sent) case MQTT_MSG_TYPE_PUBCOMP: // comp for a pubrel we sent (originally publish we sent)
if (pending_msg_type == MQTT_MSG_TYPE_PUBREL && pending_msg_id == msg_id) { if (pending_msg_type == MQTT_MSG_TYPE_PUBREL && pending_msg_id == msg_id) {
//DBG_MQTT("MQTT: QoS2 Publish successful\n"); //DBG("MQTT: QoS2 Publish successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer); client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
} }
break; break;
@ -229,7 +229,7 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {
case MQTT_MSG_TYPE_PUBREL: // rel for a rec we sent (originally publish received) case MQTT_MSG_TYPE_PUBREL: // rel for a rec we sent (originally publish received)
if (pending_msg_type == MQTT_MSG_TYPE_PUBREC && pending_msg_id == msg_id) { if (pending_msg_type == MQTT_MSG_TYPE_PUBREC && pending_msg_id == msg_id) {
//DBG_MQTT("MQTT: Cont QoS2 recv\n"); //DBG("MQTT: Cont QoS2 recv\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer); client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
// we need to send PUBCOMP // we need to send PUBCOMP
mqtt_msg_pubcomp(&client->mqtt_connection, msg_id); mqtt_msg_pubcomp(&client->mqtt_connection, msg_id);
@ -262,16 +262,16 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {
*/ */
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
mqtt_tcpclient_sent_cb(void* arg) { mqtt_tcpclient_sent_cb(void* arg) {
//DBG_MQTT("MQTT: sent CB\n"); //DBG("MQTT: sent CB\n");
struct espconn* pCon = (struct espconn *)arg; struct espconn* pCon = (struct espconn *)arg;
MQTT_Client* client = (MQTT_Client *)pCon->reverse; MQTT_Client* client = (MQTT_Client *)pCon->reverse;
if (client == NULL) return; // aborted connection ? if (client == NULL) return; // aborted connection ?
//DBG_MQTT("MQTT: Sent\n"); //DBG("MQTT: Sent\n");
// if the message we sent is not a "pending" one, we need to free the buffer // if the message we sent is not a "pending" one, we need to free the buffer
if (client->sending_buffer != NULL) { if (client->sending_buffer != NULL) {
PktBuf *buf = client->sending_buffer; PktBuf *buf = client->sending_buffer;
//DBG_MQTT("PktBuf free %p l=%d\n", buf, buf->filled); //DBG("PktBuf free %p l=%d\n", buf, buf->filled);
os_free(buf); os_free(buf);
client->sending_buffer = NULL; client->sending_buffer = NULL;
} }
@ -290,7 +290,7 @@ mqtt_tcpclient_sent_cb(void* arg) {
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
mqtt_timer(void* arg) { mqtt_timer(void* arg) {
MQTT_Client* client = (MQTT_Client*)arg; MQTT_Client* client = (MQTT_Client*)arg;
//DBG_MQTT("MQTT: timer CB\n"); //DBG("MQTT: timer CB\n");
switch (client->connState) { switch (client->connState) {
default: break; default: break;
@ -314,7 +314,7 @@ mqtt_timer(void* arg) {
// check whether we need to send a keep-alive message // check whether we need to send a keep-alive message
if (client->keepAliveTick > 0 && --client->keepAliveTick == 0) { if (client->keepAliveTick > 0 && --client->keepAliveTick == 0) {
// timeout: we need to send a ping message // timeout: we need to send a ping message
//DBG_MQTT("MQTT: Send keepalive\n"); //DBG("MQTT: Send keepalive\n");
mqtt_msg_pingreq(&client->mqtt_connection); mqtt_msg_pingreq(&client->mqtt_connection);
PktBuf *buf = PktBuf_New(client->mqtt_connection.message.length); PktBuf *buf = PktBuf_New(client->mqtt_connection.message.length);
os_memcpy(buf->data, client->mqtt_connection.message.data, os_memcpy(buf->data, client->mqtt_connection.message.data,
@ -350,13 +350,13 @@ void ICACHE_FLASH_ATTR
mqtt_tcpclient_discon_cb(void* arg) { mqtt_tcpclient_discon_cb(void* arg) {
struct espconn* pespconn = (struct espconn *)arg; struct espconn* pespconn = (struct espconn *)arg;
MQTT_Client* client = (MQTT_Client *)pespconn->reverse; MQTT_Client* client = (MQTT_Client *)pespconn->reverse;
DBG_MQTT("MQTT: Disconnect CB, freeing espconn %p\n", arg); DBG("MQTT: Disconnect CB, freeing espconn %p\n", arg);
if (pespconn->proto.tcp) os_free(pespconn->proto.tcp); if (pespconn->proto.tcp) os_free(pespconn->proto.tcp);
os_free(pespconn); os_free(pespconn);
// if this is an aborted connection we're done // if this is an aborted connection we're done
if (client == NULL) return; if (client == NULL) return;
DBG_MQTT("MQTT: Disconnected from %s:%d\n", client->host, client->port); DBG("MQTT: Disconnected from %s:%d\n", client->host, client->port);
if (client->disconnectedCb) client->disconnectedCb(client); if (client->disconnectedCb) client->disconnectedCb(client);
if (client->cmdDisconnectedCb) client->cmdDisconnectedCb(client); if (client->cmdDisconnectedCb) client->cmdDisconnectedCb(client);
@ -376,7 +376,7 @@ static void ICACHE_FLASH_ATTR
mqtt_tcpclient_recon_cb(void* arg, int8_t err) { mqtt_tcpclient_recon_cb(void* arg, int8_t err) {
struct espconn* pespconn = (struct espconn *)arg; struct espconn* pespconn = (struct espconn *)arg;
MQTT_Client* client = (MQTT_Client *)pespconn->reverse; MQTT_Client* client = (MQTT_Client *)pespconn->reverse;
//DBG_MQTT("MQTT: Reset CB, freeing espconn %p (err=%d)\n", arg, err); //DBG("MQTT: Reset CB, freeing espconn %p (err=%d)\n", arg, err);
if (pespconn->proto.tcp) os_free(pespconn->proto.tcp); if (pespconn->proto.tcp) os_free(pespconn->proto.tcp);
os_free(pespconn); os_free(pespconn);
os_printf("MQTT: Connection reset from %s:%d\n", client->host, client->port); os_printf("MQTT: Connection reset from %s:%d\n", client->host, client->port);
@ -439,7 +439,7 @@ mqtt_enq_message(MQTT_Client *client, const uint8_t *data, uint16_t len) {
*/ */
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
mqtt_send_message(MQTT_Client* client) { mqtt_send_message(MQTT_Client* client) {
//DBG_MQTT("MQTT: Send_message\n"); //DBG("MQTT: Send_message\n");
PktBuf *buf = client->msgQueue; PktBuf *buf = client->msgQueue;
if (buf == NULL || client->sending) return; // ahem... if (buf == NULL || client->sending) return; // ahem...
client->msgQueue = PktBuf_Shift(client->msgQueue); client->msgQueue = PktBuf_Shift(client->msgQueue);
@ -502,7 +502,7 @@ mqtt_dns_found(const char* name, ip_addr_t* ipaddr, void* arg) {
client->connState = TCP_RECONNECT_REQ; // the timer will kick-off a reconnection 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: ip %d.%d.%d.%d\n",
*((uint8 *)&ipaddr->addr), *((uint8 *)&ipaddr->addr),
*((uint8 *)&ipaddr->addr + 1), *((uint8 *)&ipaddr->addr + 1),
*((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 2),
@ -521,7 +521,7 @@ mqtt_dns_found(const char* name, ip_addr_t* ipaddr, void* arg) {
if (client->reconTimeout < 128) client->reconTimeout <<= 1; if (client->reconTimeout < 128) client->reconTimeout <<= 1;
client->connState = TCP_RECONNECT_REQ; client->connState = TCP_RECONNECT_REQ;
} else { } else {
DBG_MQTT("MQTT: connecting...\n"); DBG("MQTT: connecting...\n");
} }
} }
} }
@ -574,7 +574,7 @@ MQTT_Publish(MQTT_Client* client, const char* topic, const char* data, uint16_t
os_memcpy(buf->data, msg.message.data, msg.message.length); os_memcpy(buf->data, msg.message.data, msg.message.length);
buf->filled = msg.message.length; buf->filled = msg.message.length;
DBG_MQTT("MQTT: Publish, topic: \"%s\", length: %d\n", topic, msg.message.length); DBG("MQTT: Publish, topic: \"%s\", length: %d\n", topic, msg.message.length);
//dumpMem(buf, buf_len); //dumpMem(buf, buf_len);
client->msgQueue = PktBuf_Push(client->msgQueue, buf); client->msgQueue = PktBuf_Push(client->msgQueue, buf);
@ -598,7 +598,7 @@ MQTT_Subscribe(MQTT_Client* client, char* topic, uint8_t qos) {
os_printf("MQTT ERROR: Queuing Subscribe failed (too long)\n"); os_printf("MQTT ERROR: Queuing Subscribe failed (too long)\n");
return FALSE; return FALSE;
} }
DBG_MQTT("MQTT: Subscribe, topic: \"%s\"\n", topic); DBG("MQTT: Subscribe, topic: \"%s\"\n", topic);
mqtt_enq_message(client, client->mqtt_connection.message.data, mqtt_enq_message(client, client->mqtt_connection.message.data,
client->mqtt_connection.message.length); client->mqtt_connection.message.length);
return TRUE; return TRUE;
@ -627,7 +627,7 @@ void ICACHE_FLASH_ATTR
MQTT_Init(MQTT_Client* client, char* host, uint32 port, uint8_t security, uint8_t sendTimeout, MQTT_Init(MQTT_Client* client, char* host, uint32 port, uint8_t security, uint8_t sendTimeout,
char* client_id, char* client_user, char* client_pass, char* client_id, char* client_user, char* client_pass,
uint8_t keepAliveTime) { uint8_t keepAliveTime) {
DBG_MQTT("MQTT_Init\n"); DBG("MQTT_Init\n");
os_memset(client, 0, sizeof(MQTT_Client)); os_memset(client, 0, sizeof(MQTT_Client));
@ -754,7 +754,7 @@ mqtt_doAbort(MQTT_Client* client) {
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
MQTT_Reconnect(MQTT_Client* client) { MQTT_Reconnect(MQTT_Client* client) {
DBG_MQTT("MQTT: Reconnect requested\n"); DBG("MQTT: Reconnect requested\n");
if (client->connState == MQTT_DISCONNECTED) if (client->connState == MQTT_DISCONNECTED)
MQTT_Connect(client); MQTT_Connect(client);
else if (client->connState == MQTT_CONNECTED) else if (client->connState == MQTT_CONNECTED)
@ -764,7 +764,7 @@ MQTT_Reconnect(MQTT_Client* client) {
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
MQTT_Disconnect(MQTT_Client* client) { MQTT_Disconnect(MQTT_Client* client) {
DBG_MQTT("MQTT: Disconnect requested\n"); DBG("MQTT: Disconnect requested\n");
os_timer_disarm(&client->mqttTimer); os_timer_disarm(&client->mqttTimer);
if (client->connState == MQTT_DISCONNECTED) return; if (client->connState == MQTT_DISCONNECTED) return;
if (client->connState == TCP_RECONNECT_REQ) { if (client->connState == TCP_RECONNECT_REQ) {
@ -779,7 +779,7 @@ MQTT_Disconnect(MQTT_Client* client) {
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
MQTT_Free(MQTT_Client* client) { MQTT_Free(MQTT_Client* client) {
DBG_MQTT("MQTT: Free requested\n"); DBG("MQTT: Free requested\n");
MQTT_Disconnect(client); MQTT_Disconnect(client);
if (client->host) os_free(client->host); if (client->host) os_free(client->host);

@ -8,7 +8,7 @@
#include "mqtt_cmd.h" #include "mqtt_cmd.h"
#ifdef MQTTCMD_DBG #ifdef MQTTCMD_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -9,9 +9,9 @@
#include "cmd.h" #include "cmd.h"
#ifdef REST_DBG #ifdef REST_DBG
#define DBG_REST(format, ...) os_printf(format, ## __VA_ARGS__) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG_REST(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
typedef enum { typedef enum {
@ -93,7 +93,7 @@ tcpclient_recv(void *arg, char *pdata, unsigned short len) {
// collect body and send it // collect body and send it
int body_len = len-pi; int body_len = len-pi;
DBG_REST("REST: status=%d, body=%d\n", code, body_len); DBG("REST: status=%d, body=%d\n", code, body_len);
if (pi == len) { if (pi == len) {
cmdResponseStart(CMD_RESP_CB, client->resp_cb, 1); cmdResponseStart(CMD_RESP_CB, client->resp_cb, 1);
cmdResponseBody(&code, sizeof(code)); cmdResponseBody(&code, sizeof(code));
@ -120,7 +120,7 @@ static void ICACHE_FLASH_ATTR
tcpclient_sent_cb(void *arg) { tcpclient_sent_cb(void *arg) {
struct espconn *pCon = (struct espconn *)arg; struct espconn *pCon = (struct espconn *)arg;
RestClient* client = (RestClient *)pCon->reverse; RestClient* client = (RestClient *)pCon->reverse;
DBG_REST("REST: Sent\n"); DBG("REST: Sent\n");
if (client->data_sent != client->data_len) { if (client->data_sent != client->data_len) {
// we only sent part of the buffer, send the rest // we only sent part of the buffer, send the rest
espconn_sent(client->pCon, (uint8_t*)(client->data+client->data_sent), espconn_sent(client->pCon, (uint8_t*)(client->data+client->data_sent),
@ -156,13 +156,13 @@ static void ICACHE_FLASH_ATTR
tcpclient_connect_cb(void *arg) { tcpclient_connect_cb(void *arg) {
struct espconn *pCon = (struct espconn *)arg; struct espconn *pCon = (struct espconn *)arg;
RestClient* client = (RestClient *)pCon->reverse; RestClient* client = (RestClient *)pCon->reverse;
DBG_REST("REST #%d: connected\n", client-restClient); DBG("REST #%d: connected\n", client-restClient);
espconn_regist_disconcb(client->pCon, tcpclient_discon_cb); espconn_regist_disconcb(client->pCon, tcpclient_discon_cb);
espconn_regist_recvcb(client->pCon, tcpclient_recv); espconn_regist_recvcb(client->pCon, tcpclient_recv);
espconn_regist_sentcb(client->pCon, tcpclient_sent_cb); espconn_regist_sentcb(client->pCon, tcpclient_sent_cb);
client->data_sent = client->data_len <= 1400 ? client->data_len : 1400; client->data_sent = client->data_len <= 1400 ? client->data_len : 1400;
DBG_REST("REST #%d: sending %d\n", client-restClient, client->data_sent); DBG("REST #%d: sending %d\n", client-restClient, client->data_sent);
//if(client->security){ //if(client->security){
// espconn_secure_sent(client->pCon, client->data, client->data_sent); // espconn_secure_sent(client->pCon, client->data, client->data_sent);
//} //}
@ -180,7 +180,7 @@ rest_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) {
os_printf("REST DNS: Got no ip, try to reconnect\n"); os_printf("REST DNS: Got no ip, try to reconnect\n");
return; return;
} }
DBG_REST("REST DNS: found ip %d.%d.%d.%d\n", DBG("REST DNS: found ip %d.%d.%d.%d\n",
*((uint8 *) &ipaddr->addr), *((uint8 *) &ipaddr->addr),
*((uint8 *) &ipaddr->addr + 1), *((uint8 *) &ipaddr->addr + 1),
*((uint8 *) &ipaddr->addr + 2), *((uint8 *) &ipaddr->addr + 2),
@ -193,7 +193,7 @@ rest_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) {
} else } else
#endif #endif
espconn_connect(client->pCon); espconn_connect(client->pCon);
DBG_REST("REST: connecting...\n"); DBG("REST: connecting...\n");
} }
} }
@ -252,7 +252,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=%d security=%d\n", clientNum, rest_host, port, security); DBG("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;
@ -315,7 +315,7 @@ REST_SetHeader(CmdPacket *cmd) {
client->header[len] = '\r'; client->header[len] = '\r';
client->header[len+1] = '\n'; client->header[len+1] = '\n';
client->header[len+2] = 0; client->header[len+2] = 0;
DBG_REST("REST: Set header: %s\r\n", client->header); DBG("REST: Set header: %s\r\n", client->header);
break; break;
case HEADER_CONTENT_TYPE: case HEADER_CONTENT_TYPE:
if(client->content_type) os_free(client->content_type); if(client->content_type) os_free(client->content_type);
@ -324,7 +324,7 @@ REST_SetHeader(CmdPacket *cmd) {
client->content_type[len] = '\r'; client->content_type[len] = '\r';
client->content_type[len+1] = '\n'; client->content_type[len+1] = '\n';
client->content_type[len+2] = 0; client->content_type[len+2] = 0;
DBG_REST("REST: Set content_type: %s\r\n", client->content_type); DBG("REST: Set content_type: %s\r\n", client->content_type);
break; break;
case HEADER_USER_AGENT: case HEADER_USER_AGENT:
if(client->user_agent) os_free(client->user_agent); if(client->user_agent) os_free(client->user_agent);
@ -333,7 +333,7 @@ REST_SetHeader(CmdPacket *cmd) {
client->user_agent[len] = '\r'; client->user_agent[len] = '\r';
client->user_agent[len+1] = '\n'; client->user_agent[len+1] = '\n';
client->user_agent[len+2] = 0; client->user_agent[len+2] = 0;
DBG_REST("REST: Set user_agent: %s\r\n", client->user_agent); DBG("REST: Set user_agent: %s\r\n", client->user_agent);
break; break;
} }
} }
@ -342,13 +342,13 @@ void ICACHE_FLASH_ATTR
REST_Request(CmdPacket *cmd) { REST_Request(CmdPacket *cmd) {
CmdRequest req; CmdRequest req;
cmdRequest(&req, cmd); cmdRequest(&req, cmd);
DBG_REST("REST: request"); DBG("REST: request");
if (cmd->argc != 2 && cmd->argc != 3) return; if (cmd->argc != 2 && cmd->argc != 3) return;
// 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(" #%d", clientNum); DBG(" #%d", clientNum);
// Get HTTP method // Get HTTP method
uint16_t len = cmdArgLen(&req); uint16_t len = cmdArgLen(&req);
@ -356,7 +356,7 @@ REST_Request(CmdPacket *cmd) {
char method[16]; char method[16];
cmdPopArg(&req, method, len); cmdPopArg(&req, method, len);
method[len] = 0; method[len] = 0;
DBG_REST(" method=%s", method); DBG(" method=%s", method);
// Get HTTP path // Get HTTP path
len = cmdArgLen(&req); len = cmdArgLen(&req);
@ -364,7 +364,7 @@ REST_Request(CmdPacket *cmd) {
char path[1024]; char path[1024];
cmdPopArg(&req, path, len); cmdPopArg(&req, path, len);
path[len] = 0; path[len] = 0;
DBG_REST(" path=%s", path); DBG(" path=%s", path);
// Get HTTP body // Get HTTP body
uint32_t realLen = 0; uint32_t realLen = 0;
@ -374,7 +374,7 @@ REST_Request(CmdPacket *cmd) {
realLen = cmdArgLen(&req); realLen = cmdArgLen(&req);
if (realLen > 2048) goto fail; if (realLen > 2048) goto fail;
} }
DBG_REST(" bodyLen=%d", realLen); DBG(" bodyLen=%ld", 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
@ -389,30 +389,30 @@ REST_Request(CmdPacket *cmd) {
"User-Agent: %s\r\n\r\n"; "User-Agent: %s\r\n\r\n";
uint16_t headerLen = strlen(headerFmt) + strlen(method) + strlen(path) + strlen(client->host) + uint16_t headerLen = strlen(headerFmt) + strlen(method) + strlen(path) + strlen(client->host) +
strlen(client->header) + strlen(client->content_type) + strlen(client->user_agent); strlen(client->header) + strlen(client->content_type) + strlen(client->user_agent);
DBG_REST(" hdrLen=%d", headerLen); DBG(" hdrLen=%d", headerLen);
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=%d data=%p", headerLen + realLen, client->data); DBG(" totLen=%ld 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(" hdrLen=%d", client->data_len);
if (realLen > 0) { if (realLen > 0) {
cmdPopArg(&req, client->data + client->data_len, realLen); cmdPopArg(&req, client->data + client->data_len, realLen);
client->data_len += realLen; client->data_len += realLen;
} }
DBG_REST("\n"); DBG("\n");
//DBG_REST("REST request: %s", (char*)client->data); //DBG("REST request: %s", (char*)client->data);
//DBG_REST("REST: pCon state=%d\n", client->pCon->state); //DBG("REST: pCon state=%d\n", client->pCon->state);
client->pCon->state = ESPCONN_NONE; client->pCon->state = ESPCONN_NONE;
espconn_regist_connectcb(client->pCon, tcpclient_connect_cb); espconn_regist_connectcb(client->pCon, tcpclient_connect_cb);
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:%d\n",client->host, client->port); DBG("REST: Connect to ip %s:%ld\n",client->host, client->port);
//if(client->security){ //if(client->security){
// espconn_secure_connect(client->pCon); // espconn_secure_connect(client->pCon);
//} //}
@ -420,12 +420,12 @@ REST_Request(CmdPacket *cmd) {
espconn_connect(client->pCon); espconn_connect(client->pCon);
//} //}
} else { } else {
DBG_REST("REST: Connect to host %s:%d\n", client->host, client->port); DBG("REST: Connect to host %s:%ld\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);
} }
return; return;
fail: fail:
DBG_REST("\n"); DBG("\n");
} }

@ -8,7 +8,7 @@
#include "cmd.h" #include "cmd.h"
#ifdef SLIP_DBG #ifdef SLIP_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif

@ -22,9 +22,9 @@
#include "uart.h" #include "uart.h"
#ifdef UART_DBG #ifdef UART_DBG
#define DBG_UART(format, ...) os_printf(format, ## __VA_ARGS__) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG_UART(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
LOCAL uint8_t uart_recvTaskNum; LOCAL uint8_t uart_recvTaskNum;
@ -203,7 +203,7 @@ uart0_rx_intr_handler(void *para)
if (UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST) if (UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST)
|| UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)) || UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST))
{ {
//DBG_UART("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no)); //DBG("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no));
ETS_UART_INTR_DISABLE(); ETS_UART_INTR_DISABLE();
post_usr_task(uart_recvTaskNum, 0); post_usr_task(uart_recvTaskNum, 0);
} }
@ -226,7 +226,7 @@ uart_recvTask(os_event_t *events)
(length < 128)) { (length < 128)) {
buf[length++] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; buf[length++] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
} }
//DBG_UART("%d ix %d\n", system_get_time(), length); //DBG("%d ix %d\n", system_get_time(), length);
for (int i=0; i<MAX_CB; i++) { for (int i=0; i<MAX_CB; i++) {
if (uart_recv_cb[i] != NULL) (uart_recv_cb[i])(buf, length); if (uart_recv_cb[i] != NULL) (uart_recv_cb[i])(buf, length);

@ -17,7 +17,7 @@
extern void * mem_trim(void *m, size_t s); // not well documented... extern void * mem_trim(void *m, size_t s); // not well documented...
#ifdef SYSLOG_DBG #ifdef SYSLOG_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else #else
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
@ -25,6 +25,8 @@ extern void * mem_trim(void *m, size_t s); // not well documented...
#define WIFI_CHK_INTERVAL 1000 // ms to check Wifi statis #define WIFI_CHK_INTERVAL 1000 // ms to check Wifi statis
static struct espconn *syslog_espconn = NULL; static struct espconn *syslog_espconn = NULL;
static struct espconn *syslog_dnsconn = NULL;
static uint32_t syslog_msgid = 1; static uint32_t syslog_msgid = 1;
static uint8_t syslog_task = 0; static uint8_t syslog_task = 0;
@ -131,7 +133,7 @@ static void ICACHE_FLASH_ATTR syslog_chk_status(void)
case SYSLOG_DNSWAIT: case SYSLOG_DNSWAIT:
DBG("%s: wait for DNS resolver\n", syslog_get_status()); DBG("%s: wait for DNS resolver\n", syslog_get_status());
syslog_timer_arm(10); syslog_timer_arm(100);
break; break;
case SYSLOG_READY: case SYSLOG_READY:
@ -156,10 +158,10 @@ 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 %d!!!\n", wifi_status);
} else { } else {
DBG("re-arming timer...\n"); DBG("re-arming timer...\n");
syslog_timer_arm(WIFI_CHK_INTERVAL); syslog_timer_arm(WIFI_CHK_INTERVAL);
@ -192,15 +194,13 @@ static void ICACHE_FLASH_ATTR syslog_udp_sent_cb(void *arg)
// UDP seems timecritical - we must ensure a minimum delay after each package... // UDP seems timecritical - we must ensure a minimum delay after each package...
syslog_set_status(SYSLOG_SENDING); syslog_set_status(SYSLOG_SENDING);
if (! syslog_timer_armed) if (! syslog_timer_armed)
syslog_chk_status(); syslog_chk_status();
} }
} }
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
syslog_udp_send_event(os_event_t *events) { syslog_udp_send_event(os_event_t *events) {
// os_printf("syslog_udp_send_event: %d %lu, %lu\n", syslogState, syslogQueue->msgid, syslogQueue->tick);
DBG("[%uµs] %s: id=%lu\n", WDEV_NOW(), __FUNCTION__, syslogQueue ? syslogQueue->msgid : 0); DBG("[%uµs] %s: id=%lu\n", WDEV_NOW(), __FUNCTION__, syslogQueue ? syslogQueue->msgid : 0);
if (syslogQueue == NULL) if (syslogQueue == NULL)
syslog_set_status(SYSLOG_READY); syslog_set_status(SYSLOG_READY);
else { else {
@ -234,11 +234,14 @@ static void ICACHE_FLASH_ATTR syslog_udp_recv_cb(void *arg, char *pusrdata, unsi
******************************************************************************/ ******************************************************************************/
static void ICACHE_FLASH_ATTR syslog_gethostbyname_cb(const char *name, ip_addr_t *ipaddr, void *arg) static void ICACHE_FLASH_ATTR syslog_gethostbyname_cb(const char *name, ip_addr_t *ipaddr, void *arg)
{ {
DBG("[%uµs] %s\n", WDEV_NOW(), __FUNCTION__);
struct espconn *pespconn = (struct espconn *)arg; struct espconn *pespconn = (struct espconn *)arg;
(void) pespconn; // espconn not longer required
os_free(pespconn->proto.udp);
os_free(pespconn);
DBG("[%uµs] %s\n", WDEV_NOW(), __FUNCTION__);
if (ipaddr != NULL) { if (ipaddr != NULL) {
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "SYSLOG", syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "SYSLOG",
"resolved hostname: %s: " IPSTR, name, IP2STR(ipaddr)); "resolved hostname: %s: " IPSTR, name, IP2STR(ipaddr));
syslogHost.addr.addr = ipaddr->addr; syslogHost.addr.addr = ipaddr->addr;
@ -273,7 +276,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;
@ -322,16 +325,18 @@ void ICACHE_FLASH_ATTR syslog_init(char *syslog_host)
// wifi_set_broadcast_if(STATIONAP_MODE); // send UDP broadcast from both station and soft-AP interface // wifi_set_broadcast_if(STATIONAP_MODE); // send UDP broadcast from both station and soft-AP interface
espconn_create(syslog_espconn); // create udp espconn_create(syslog_espconn); // create udp
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "SYSLOG",
"syslogserver: %s:%d %d", host, syslogHost.port, syslog_espconn->proto.udp->local_port);
if (UTILS_StrToIP((const char *)host, (void*)&syslogHost.addr)) { if (UTILS_StrToIP((const char *)host, (void*)&syslogHost.addr)) {
syslog_set_status(SYSLOG_READY); syslog_set_status(SYSLOG_READY);
} else { } else {
// we use our own espconn structure to avoid side effects...
if (syslog_dnsconn == NULL)
syslog_dnsconn = (espconn *)os_zalloc(sizeof(espconn));
if (syslog_dnsconn->proto.udp == NULL)
syslog_dnsconn->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
syslog_set_status(SYSLOG_DNSWAIT); syslog_set_status(SYSLOG_DNSWAIT);
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "SYSLOG", espconn_gethostbyname(syslog_dnsconn, host, &syslogHost.addr, syslog_gethostbyname_cb);
"must resolve hostname \"%s\"", host);
espconn_gethostbyname(syslog_espconn, host, &syslogHost.addr, syslog_gethostbyname_cb);
} }
} }
@ -355,13 +360,15 @@ syslog_add_entry(syslog_entry_t *entry)
pse = pse->next; pse = pse->next;
pse->next = entry; // append msg to syslog queue pse->next = entry; // append msg to syslog queue
} }
// DBG("%p %lu %d\n", entry, entry->msgid, system_get_free_heap_size()); // Debug: show queue addr, current msgid, avail. heap and syslog datagram
// DBG("%p %lu %d %s\n", entry, entry->msgid, system_get_free_heap_size(), entry->datagram);
// ensure we have sufficient heap for the rest of the system // ensure we have sufficient heap for the rest of the system
if (system_get_free_heap_size() < syslogHost.min_heap_size) { if (system_get_free_heap_size() < syslogHost.min_heap_size) {
if (syslogState != SYSLOG_HALTED) { if (syslogState != SYSLOG_HALTED) {
os_printf("syslog_add_entry: Warning: queue filled up, halted\n"); // os_printf("syslog_add_entry: Warning: queue filled up (%d), halted\n", system_get_free_heap_size());
entry->next = syslog_compose(SYSLOG_FAC_USER, SYSLOG_PRIO_CRIT, "SYSLOG", "queue filled up, halted"); entry->next = syslog_compose(SYSLOG_FAC_USER, SYSLOG_PRIO_CRIT, "SYSLOG", "queue filled up (%d), halted", system_get_free_heap_size());
os_printf("%s\n", entry->next->datagram);
if (syslogState == SYSLOG_READY) if (syslogState == SYSLOG_READY)
syslog_send_udp(); syslog_send_udp();
syslog_set_status(SYSLOG_HALTED); syslog_set_status(SYSLOG_HALTED);
@ -378,6 +385,11 @@ syslog_add_entry(syslog_entry_t *entry)
LOCAL syslog_entry_t ICACHE_FLASH_ATTR * LOCAL syslog_entry_t ICACHE_FLASH_ATTR *
syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *fmt, ...) syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *fmt, ...)
{ {
union {
uint8_t buf[sizeof (syslog_entry_t) + 1024];
syslog_entry_t se;
} sl;
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; if (se == NULL) return NULL;
@ -399,21 +411,22 @@ syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *
// create timestamp: FULL-DATE "T" PARTIAL-TIME "Z": 'YYYY-mm-ddTHH:MM:SSZ ' // create timestamp: FULL-DATE "T" PARTIAL-TIME "Z": 'YYYY-mm-ddTHH:MM:SSZ '
// as long as realtime_stamp is 0 we use tick div 10⁶ as date // as long as realtime_stamp is 0 we use tick div 10⁶ as date
now = (realtime_stamp == 0) ? (se->tick / 1000000) : realtime_stamp; now = (realtime_stamp == 0) ? (sl.se.tick / 1000000) : realtime_stamp;
tp = gmtime(&now); tp = gmtime(&now);
p += os_sprintf(p, "%4d-%02d-%02dT%02d:%02d:%02d", p += os_sprintf(p, "%4d-%02d-%02dT%02d:%02d:%02d",
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, ".%06uZ ", se->tick % 1000000); p += os_sprintf(p, ".%06uZ ", sl.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 %u.%06u %u ", flashConfig.hostname, tag, se->tick / 1000000, se->tick % 1000000, syslog_msgid++); p += os_sprintf(p, "%s %s %u.%06u %u ", flashConfig.hostname, tag, sl.se.tick / 1000000,
sl.se.tick % 1000000, syslog_msgid++);
else else
p += os_sprintf(p, "%s %s - %u ", flashConfig.hostname, tag, syslog_msgid++); p += os_sprintf(p, "%s %s - %u ", flashConfig.hostname, tag, syslog_msgid++);
@ -423,8 +436,9 @@ syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *
p += ets_vsprintf(p, fmt, arglist ); p += ets_vsprintf(p, fmt, arglist );
va_end(arglist); va_end(arglist);
se->datagram_len = p - se->datagram; sl.se.datagram_len = 1 + p - sl.se.datagram;
se = mem_trim(se, sizeof(syslog_entry_t) + se->datagram_len + 1); syslog_entry_t *se = os_zalloc(sizeof (syslog_entry_t) + sl.se.datagram_len);
os_memcpy(se, &sl.se, sizeof (syslog_entry_t) + sl.se.datagram_len);
return se; return se;
} }
@ -504,7 +518,8 @@ void ICACHE_FLASH_ATTR syslog(uint8_t facility, uint8_t severity, const char *ta
DBG("[%dµs] %s status: %s\n", WDEV_NOW(), __FUNCTION__, syslog_get_status()); DBG("[%dµs] %s status: %s\n", WDEV_NOW(), __FUNCTION__, syslog_get_status());
if (syslogState == SYSLOG_ERROR || if (syslogState == SYSLOG_ERROR ||
syslogState == SYSLOG_HALTED) syslogState == SYSLOG_HALTED ||
flashConfig.syslog_host[0] == '\0')
return; return;
if (severity > flashConfig.syslog_filter) if (severity > flashConfig.syslog_filter)

@ -1,5 +1,13 @@
#include <esp8266.h> #include <esp8266.h>
#include <config.h> #include "config.h"
#include "syslog.h"
#define APPINIT_DBG
#ifdef APPINIT_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
// initialize the custom stuff that goes beyond esp-link // initialize the custom stuff that goes beyond esp-link
void app_init() { void app_init() {

Loading…
Cancel
Save