Revert "TvEmaster"

This reverts commit f577c140df.
pull/140/merge
Thorsten von Eicken 8 years ago
parent 5eba5500ac
commit 56e76c6bc4
  1. 16
      Makefile
  2. 2
      cmd/handlers.c
  3. 2
      esp-link/cgi.c
  4. 2
      esp-link/cgiflash.c
  5. 6
      esp-link/cgimqtt.c
  6. 2
      esp-link/cgioptiboot.c
  7. 12
      esp-link/cgiservices.c
  8. 73
      esp-link/cgiwifi.c
  9. 2
      esp-link/log.c
  10. 6
      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. 62
      syslog/syslog.c
  20. 10
      user/user_main.c

@ -13,9 +13,6 @@
# `VERBOSE=1 make ...` will print debug info
# `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
-include local.conf
@ -57,7 +54,9 @@ ESP_HOSTNAME ?= esp-link
# Typically you'll install https://github.com/pfalcon/esp-open-sdk
XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Firmware version (if you change this expect to make code adjustments elsewhere!)
# Firmware version
# WARNING: if you change this expect to make code adjustments elsewhere, don't expect
# that esp-link will magically work with a different version of the SDK!!!
SDK_VERS ?= esp_iot_sdk_v1.5.2
# Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
@ -206,6 +205,8 @@ TARGET = httpd
# espressif tool to concatenate sections for OTA upload using bootloader v1.2+
APPGEN_TOOL ?= gen_appbin.py
CFLAGS=
# set defines for optional modules
ifneq (,$(findstring mqtt,$(MODULES)))
CFLAGS += -DMQTT
@ -342,7 +343,6 @@ all: echo_version checkdirs $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin
echo_version:
@echo VERSION: $(VERSION)
@echo MODULES: $(MODULES)
$(USER1_OUT): $(APP_AR) $(LD_SCRIPT1)
$(vecho) "LD $@"
@ -399,7 +399,7 @@ baseflash: all
flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
0x00000 "$(BOOTFILE)" 0x01000 $(FW_BASE)/user1.bin \
0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" 0x01000 $(FW_BASE)/user1.bin \
$(ET_BLANK) $(SDK_BASE)/bin/blank.bin
ifeq ($(OS),Windows_NT)
@ -446,7 +446,7 @@ ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
else
$(Q) cp -r html/head- html_compressed;
$(Q) cp -r html/*.html html_compressed;
$(Q) cp -r html/wifi/*.html html_compressed/wifi;
$(Q) cp -r html/wifi/*.html html_compressed/wifi;
endif
ifeq (,$(findstring mqtt,$(MODULES)))
$(Q) rm -rf html_compressed/mqtt.html
@ -481,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)/user2.bin | cut -b 1-80
$(Q) cp $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(SDK_BASE)/bin/blank.bin \
"$(BOOTFILE)" wiflash avrflash release/esp-link-$(BRANCH)
"$(SDK_BASE)/bin/boot_v1.5.bin" wiflash avrflash 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) rm -rf release

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

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

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

@ -17,7 +17,7 @@ char *mqttState(void) {
#include "cgimqtt.h"
#ifdef CGIMQTT_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#else
#define DBG(format, ...) do { } while(0)
#endif
@ -134,7 +134,7 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
mqtt_client_init();
// if just enable changed we just need to bounce the client
}
}
else if (mqtt_en_chg > 0) {
DBG("MQTT server enable=%d changed\n", flashConfig.mqtt_enable);
if (flashConfig.mqtt_enable && strlen(flashConfig.mqtt_host) > 0)
@ -154,7 +154,7 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
// if SLIP-enable is toggled it gets picked-up immediately by the parser
int slip_update = getBoolArg(connData, "slip-enable", &flashConfig.slip_enable);
if (slip_update < 0) return HTTPD_CGI_DONE;
if (slip_update > 0)
if (slip_update > 0)
DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable);
DBG("Saving config\n");

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

@ -7,7 +7,7 @@
#include "cgimqtt.h"
#ifdef CGISERVICES_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#else
#define DBG(format, ...) do { } while(0)
#endif
@ -92,10 +92,10 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
}
void ICACHE_FLASH_ATTR cgiServicesSNTPInit() {
if (flashConfig.sntp_server[0] != '\0') {
if (flashConfig.sntp_server[0] != '\0') {
sntp_stop();
if (true == sntp_set_timezone(flashConfig.timezone_offset)) {
sntp_setservername(0, flashConfig.sntp_server);
sntp_setservername(0, flashConfig.sntp_server);
sntp_init();
}
DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset);
@ -107,7 +107,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) {
if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
os_sprintf(buff,
os_sprintf(buff,
"{ "
"\"syslog_host\": \"%s\", "
"\"syslog_minheap\": %d, "
@ -118,7 +118,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) {
"\"sntp_server\": \"%s\", "
"\"mdns_enable\": \"%s\", "
"\"mdns_servername\": \"%s\""
" }",
" }",
flashConfig.syslog_host,
flashConfig.syslog_minheap,
flashConfig.syslog_filter,
@ -168,7 +168,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
int8_t mdns = 0;
mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable);
if (mdns < 0) return HTTPD_CGI_DONE;
if (mdns > 0) {
if (flashConfig.mdns_enable){
DBG("Services: MDNS Enabled\n");

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

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

@ -81,7 +81,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/pins", cgiPins, NULL },
#ifdef MQTT
{ "/mqtt", cgiMqtt, NULL },
#endif
#endif
{ "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem
{ NULL, NULL, NULL }
};
@ -151,8 +151,8 @@ void user_init(void) {
uint32_t fid = spi_flash_get_id();
NOTICE("Flash map %s, manuf 0x%02X chip 0x%04X", flash_maps[system_get_flash_size_map()],
fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
NOTICE("** %s: ready, heap=%ld", esp_link_version, (unsigned long)system_get_free_heap_size());
NOTICE("** esp-link ready");
// Init SNTP service
cgiServicesSNTPInit();
#ifdef MQTT

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

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

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

@ -42,9 +42,9 @@
#include "mqtt.h"
#ifdef MQTT_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#define DBG_MQTT(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#define DBG_MQTT(format, ...) do { } while(0)
#endif
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) {
// why are we receiving something??
DBG("MQTT ERROR: recv in invalid state %d\n", client->connState);
DBG_MQTT("MQTT ERROR: recv in invalid state %d\n", client->connState);
mqtt_doAbort(client);
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_id = mqtt_get_id(client->pending_buffer->data, client->pending_buffer->filled);
}
DBG("MQTT: Recv type=%s id=%04X len=%d; Pend type=%s id=%02X\n",
DBG_MQTT("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);
switch (msg_type) {
case MQTT_MSG_TYPE_CONNACK:
//DBG("MQTT: Connect successful\n");
//DBG_MQTT("MQTT: Connect successful\n");
// callbacks for internal and external clients
if (client->connectedCb) client->connectedCb(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:
if (pending_msg_type == MQTT_MSG_TYPE_SUBSCRIBE && pending_msg_id == msg_id) {
//DBG("MQTT: Subscribe successful\n");
//DBG_MQTT("MQTT: Subscribe successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;
case MQTT_MSG_TYPE_UNSUBACK:
if (pending_msg_type == MQTT_MSG_TYPE_UNSUBSCRIBE && pending_msg_id == msg_id) {
//DBG("MQTT: Unsubscribe successful\n");
//DBG_MQTT("MQTT: Unsubscribe successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;
case MQTT_MSG_TYPE_PUBACK: // ack for a publish we sent
if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) {
//DBG("MQTT: QoS1 Publish successful\n");
//DBG_MQTT("MQTT: QoS1 Publish successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;
case MQTT_MSG_TYPE_PUBREC: // rec for a publish we sent
if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) {
//DBG("MQTT: QoS2 publish cont\n");
//DBG_MQTT("MQTT: QoS2 publish cont\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
// we need to send PUBREL
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)
if (pending_msg_type == MQTT_MSG_TYPE_PUBREL && pending_msg_id == msg_id) {
//DBG("MQTT: QoS2 Publish successful\n");
//DBG_MQTT("MQTT: QoS2 Publish successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
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)
if (pending_msg_type == MQTT_MSG_TYPE_PUBREC && pending_msg_id == msg_id) {
//DBG("MQTT: Cont QoS2 recv\n");
//DBG_MQTT("MQTT: Cont QoS2 recv\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
// we need to send PUBCOMP
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
mqtt_tcpclient_sent_cb(void* arg) {
//DBG("MQTT: sent CB\n");
//DBG_MQTT("MQTT: sent CB\n");
struct espconn* pCon = (struct espconn *)arg;
MQTT_Client* client = (MQTT_Client *)pCon->reverse;
if (client == NULL) return; // aborted connection ?
//DBG("MQTT: Sent\n");
//DBG_MQTT("MQTT: Sent\n");
// if the message we sent is not a "pending" one, we need to free the buffer
if (client->sending_buffer != NULL) {
PktBuf *buf = client->sending_buffer;
//DBG("PktBuf free %p l=%d\n", buf, buf->filled);
//DBG_MQTT("PktBuf free %p l=%d\n", buf, buf->filled);
os_free(buf);
client->sending_buffer = NULL;
}
@ -290,7 +290,7 @@ mqtt_tcpclient_sent_cb(void* arg) {
static void ICACHE_FLASH_ATTR
mqtt_timer(void* arg) {
MQTT_Client* client = (MQTT_Client*)arg;
//DBG("MQTT: timer CB\n");
//DBG_MQTT("MQTT: timer CB\n");
switch (client->connState) {
default: break;
@ -314,7 +314,7 @@ mqtt_timer(void* arg) {
// check whether we need to send a keep-alive message
if (client->keepAliveTick > 0 && --client->keepAliveTick == 0) {
// timeout: we need to send a ping message
//DBG("MQTT: Send keepalive\n");
//DBG_MQTT("MQTT: Send keepalive\n");
mqtt_msg_pingreq(&client->mqtt_connection);
PktBuf *buf = PktBuf_New(client->mqtt_connection.message.length);
os_memcpy(buf->data, client->mqtt_connection.message.data,
@ -350,13 +350,13 @@ void ICACHE_FLASH_ATTR
mqtt_tcpclient_discon_cb(void* arg) {
struct espconn* pespconn = (struct espconn *)arg;
MQTT_Client* client = (MQTT_Client *)pespconn->reverse;
DBG("MQTT: Disconnect CB, freeing espconn %p\n", arg);
DBG_MQTT("MQTT: Disconnect CB, freeing espconn %p\n", arg);
if (pespconn->proto.tcp) os_free(pespconn->proto.tcp);
os_free(pespconn);
// if this is an aborted connection we're done
if (client == NULL) return;
DBG("MQTT: Disconnected from %s:%d\n", client->host, client->port);
DBG_MQTT("MQTT: Disconnected from %s:%d\n", client->host, client->port);
if (client->disconnectedCb) client->disconnectedCb(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) {
struct espconn* pespconn = (struct espconn *)arg;
MQTT_Client* client = (MQTT_Client *)pespconn->reverse;
//DBG("MQTT: Reset CB, freeing espconn %p (err=%d)\n", arg, err);
//DBG_MQTT("MQTT: Reset CB, freeing espconn %p (err=%d)\n", arg, err);
if (pespconn->proto.tcp) os_free(pespconn->proto.tcp);
os_free(pespconn);
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
mqtt_send_message(MQTT_Client* client) {
//DBG("MQTT: Send_message\n");
//DBG_MQTT("MQTT: Send_message\n");
PktBuf *buf = client->msgQueue;
if (buf == NULL || client->sending) return; // ahem...
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
return;
}
DBG("MQTT: ip %d.%d.%d.%d\n",
DBG_MQTT("MQTT: ip %d.%d.%d.%d\n",
*((uint8 *)&ipaddr->addr),
*((uint8 *)&ipaddr->addr + 1),
*((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;
client->connState = TCP_RECONNECT_REQ;
} else {
DBG("MQTT: connecting...\n");
DBG_MQTT("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);
buf->filled = msg.message.length;
DBG("MQTT: Publish, topic: \"%s\", length: %d\n", topic, msg.message.length);
DBG_MQTT("MQTT: Publish, topic: \"%s\", length: %d\n", topic, msg.message.length);
//dumpMem(buf, buf_len);
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");
return FALSE;
}
DBG("MQTT: Subscribe, topic: \"%s\"\n", topic);
DBG_MQTT("MQTT: Subscribe, topic: \"%s\"\n", topic);
mqtt_enq_message(client, client->mqtt_connection.message.data,
client->mqtt_connection.message.length);
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,
char* client_id, char* client_user, char* client_pass,
uint8_t keepAliveTime) {
DBG("MQTT_Init\n");
DBG_MQTT("MQTT_Init\n");
os_memset(client, 0, sizeof(MQTT_Client));
@ -754,7 +754,7 @@ mqtt_doAbort(MQTT_Client* client) {
void ICACHE_FLASH_ATTR
MQTT_Reconnect(MQTT_Client* client) {
DBG("MQTT: Reconnect requested\n");
DBG_MQTT("MQTT: Reconnect requested\n");
if (client->connState == MQTT_DISCONNECTED)
MQTT_Connect(client);
else if (client->connState == MQTT_CONNECTED)
@ -764,7 +764,7 @@ MQTT_Reconnect(MQTT_Client* client) {
void ICACHE_FLASH_ATTR
MQTT_Disconnect(MQTT_Client* client) {
DBG("MQTT: Disconnect requested\n");
DBG_MQTT("MQTT: Disconnect requested\n");
os_timer_disarm(&client->mqttTimer);
if (client->connState == MQTT_DISCONNECTED) return;
if (client->connState == TCP_RECONNECT_REQ) {
@ -779,7 +779,7 @@ MQTT_Disconnect(MQTT_Client* client) {
void ICACHE_FLASH_ATTR
MQTT_Free(MQTT_Client* client) {
DBG("MQTT: Free requested\n");
DBG_MQTT("MQTT: Free requested\n");
MQTT_Disconnect(client);
if (client->host) os_free(client->host);

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

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

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

@ -22,9 +22,9 @@
#include "uart.h"
#ifdef UART_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#define DBG_UART(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#define DBG_UART(format, ...) do { } while(0)
#endif
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)
|| UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST))
{
//DBG("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no));
//DBG_UART("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no));
ETS_UART_INTR_DISABLE();
post_usr_task(uart_recvTaskNum, 0);
}
@ -226,7 +226,7 @@ uart_recvTask(os_event_t *events)
(length < 128)) {
buf[length++] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
}
//DBG("%d ix %d\n", system_get_time(), length);
//DBG_UART("%d ix %d\n", system_get_time(), length);
for (int i=0; i<MAX_CB; i++) {
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...
#ifdef SYSLOG_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#else
#define DBG(format, ...) do { } while(0)
#endif
@ -25,8 +25,6 @@ extern void * mem_trim(void *m, size_t s); // not well documented...
#define WIFI_CHK_INTERVAL 1000 // ms to check Wifi statis
static struct espconn *syslog_espconn = NULL;
static struct espconn *syslog_dnsconn = NULL;
static uint32_t syslog_msgid = 1;
static uint8_t syslog_task = 0;
@ -133,7 +131,7 @@ static void ICACHE_FLASH_ATTR syslog_chk_status(void)
case SYSLOG_DNSWAIT:
DBG("%s: wait for DNS resolver\n", syslog_get_status());
syslog_timer_arm(100);
syslog_timer_arm(10);
break;
case SYSLOG_READY:
@ -161,7 +159,7 @@ static void ICACHE_FLASH_ATTR syslog_chk_status(void)
wifi_status == STATION_NO_AP_FOUND ||
wifi_status == STATION_CONNECT_FAIL)) {
syslog_set_status(SYSLOG_ERROR);
os_printf("*** connect failure %d!!!\n", wifi_status);
os_printf("*** connect failure!!!\n");
} else {
DBG("re-arming timer...\n");
syslog_timer_arm(WIFI_CHK_INTERVAL);
@ -194,13 +192,15 @@ static void ICACHE_FLASH_ATTR syslog_udp_sent_cb(void *arg)
// UDP seems timecritical - we must ensure a minimum delay after each package...
syslog_set_status(SYSLOG_SENDING);
if (! syslog_timer_armed)
syslog_chk_status();
syslog_chk_status();
}
}
static void ICACHE_FLASH_ATTR
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);
if (syslogQueue == NULL)
syslog_set_status(SYSLOG_READY);
else {
@ -234,14 +234,11 @@ 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)
{
DBG("[%uµs] %s\n", WDEV_NOW(), __FUNCTION__);
struct espconn *pespconn = (struct espconn *)arg;
// espconn not longer required
os_free(pespconn->proto.udp);
os_free(pespconn);
(void) pespconn;
DBG("[%uµs] %s\n", WDEV_NOW(), __FUNCTION__);
if (ipaddr != NULL) {
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "SYSLOG",
"resolved hostname: %s: " IPSTR, name, IP2STR(ipaddr));
syslogHost.addr.addr = ipaddr->addr;
@ -325,18 +322,16 @@ 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
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)) {
syslog_set_status(SYSLOG_READY);
} 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);
espconn_gethostbyname(syslog_dnsconn, host, &syslogHost.addr, syslog_gethostbyname_cb);
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "SYSLOG",
"must resolve hostname \"%s\"", host);
espconn_gethostbyname(syslog_espconn, host, &syslogHost.addr, syslog_gethostbyname_cb);
}
}
@ -360,15 +355,13 @@ syslog_add_entry(syslog_entry_t *entry)
pse = pse->next;
pse->next = entry; // append msg to syslog queue
}
// 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);
// DBG("%p %lu %d\n", entry, entry->msgid, system_get_free_heap_size());
// ensure we have sufficient heap for the rest of the system
if (system_get_free_heap_size() < syslogHost.min_heap_size) {
if (syslogState != SYSLOG_HALTED) {
// 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 (%d), halted", system_get_free_heap_size());
os_printf("%s\n", entry->next->datagram);
os_printf("syslog_add_entry: Warning: queue filled up, halted\n");
entry->next = syslog_compose(SYSLOG_FAC_USER, SYSLOG_PRIO_CRIT, "SYSLOG", "queue filled up, halted");
if (syslogState == SYSLOG_READY)
syslog_send_udp();
syslog_set_status(SYSLOG_HALTED);
@ -385,11 +378,6 @@ syslog_add_entry(syslog_entry_t *entry)
LOCAL syslog_entry_t ICACHE_FLASH_ATTR *
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);
syslog_entry_t *se = os_zalloc(sizeof (syslog_entry_t) + 1024); // allow up to 1k datagram
if (se == NULL) return NULL;
@ -411,22 +399,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 '
// as long as realtime_stamp is 0 we use tick div 10⁶ as date
now = (realtime_stamp == 0) ? (sl.se.tick / 1000000) : realtime_stamp;
now = (realtime_stamp == 0) ? (se->tick / 1000000) : realtime_stamp;
tp = gmtime(&now);
p += os_sprintf(p, "%4d-%02d-%02dT%02d:%02d:%02d",
tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec);
if (realtime_stamp == 0)
p += os_sprintf(p, ".%06uZ ", sl.se.tick % 1000000);
p += os_sprintf(p, ".%06uZ ", se->tick % 1000000);
else
p += os_sprintf(p, "%+03d:00 ", flashConfig.timezone_offset);
}
// add HOSTNAME APP-NAME PROCID MSGID
if (flashConfig.syslog_showtick)
p += os_sprintf(p, "%s %s %u.%06u %u ", flashConfig.hostname, tag, sl.se.tick / 1000000,
sl.se.tick % 1000000, syslog_msgid++);
p += os_sprintf(p, "%s %s %lu.%06lu %lu ", flashConfig.hostname, tag, se->tick / 1000000,
se->tick % 1000000, syslog_msgid++);
else
p += os_sprintf(p, "%s %s - %u ", flashConfig.hostname, tag, syslog_msgid++);
@ -436,9 +424,8 @@ syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *
p += ets_vsprintf(p, fmt, arglist );
va_end(arglist);
sl.se.datagram_len = 1 + p - sl.se.datagram;
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);
se->datagram_len = p - se->datagram;
se = mem_trim(se, sizeof(syslog_entry_t) + se->datagram_len + 1);
return se;
}
@ -518,8 +505,7 @@ 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());
if (syslogState == SYSLOG_ERROR ||
syslogState == SYSLOG_HALTED ||
flashConfig.syslog_host[0] == '\0')
syslogState == SYSLOG_HALTED)
return;
if (severity > flashConfig.syslog_filter)

@ -1,13 +1,5 @@
#include <esp8266.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
#include <config.h>
// initialize the custom stuff that goes beyond esp-link
void app_init() {

Loading…
Cancel
Save