Reduce memory consumption; fix syslog alloc when disabled

pull/163/head
Thorsten von Eicken 9 years ago
parent dc4fabc7ed
commit ef6a611045
  1. 10
      cmd/handlers.c
  2. 11
      esp-link/cgimqtt.c
  3. 19
      esp-link/main.c
  4. 2
      esp-link/task.h
  5. 3
      include/esp8266.h
  6. 6
      include/espmissingincludes.h
  7. 8
      mqtt/mqtt_cmd.c
  8. 9
      syslog/syslog.c

@ -3,6 +3,7 @@
// Adapted from: github.com/tuanpmt/esp_bridge, Created on: Jan 9, 2015, Author: Minh
#include "esp8266.h"
#include "sntp.h"
#include "cmd.h"
#include <cgiwifi.h>
#ifdef MQTT
@ -21,6 +22,7 @@
static void cmdNull(CmdPacket *cmd);
static void cmdSync(CmdPacket *cmd);
static void cmdWifiStatus(CmdPacket *cmd);
static void cmdGetTime(CmdPacket *cmd);
static void cmdAddCallback(CmdPacket *cmd);
// keep track of last status sent to uC so we can notify it when it changes
@ -33,6 +35,7 @@ const CmdList commands[] = {
{CMD_SYNC, "SYNC", cmdSync}, // synchronize
{CMD_WIFI_STATUS, "WIFI_STATUS", cmdWifiStatus},
{CMD_CB_ADD, "ADD_CB", cmdAddCallback},
{CMD_GET_TIME, "GET_TIME", cmdGetTime},
#ifdef MQTT
{CMD_MQTT_SETUP, "MQTT_SETUP", MQTTCMD_Setup},
{CMD_MQTT_PUBLISH, "MQTT_PUB", MQTTCMD_Publish},
@ -149,6 +152,13 @@ cmdWifiStatus(CmdPacket *cmd) {
return;
}
// Command handler for time
static void ICACHE_FLASH_ATTR
cmdGetTime(CmdPacket *cmd) {
cmdResponseStart(CMD_RESP_V, sntp_get_current_timestamp(), 0);
cmdResponseEnd();
return;
}
// Command handler to add a callback to the named-callbacks list, this is for a callback to the uC
static void ICACHE_FLASH_ATTR

@ -134,13 +134,16 @@ 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) {
} 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)
if (flashConfig.mqtt_enable && strlen(flashConfig.mqtt_host) > 0) {
MQTT_Free(&mqttClient); // safe even if not connected
mqtt_client_init();
MQTT_Reconnect(&mqttClient);
else
} else {
MQTT_Disconnect(&mqttClient);
MQTT_Free(&mqttClient); // safe even if not connected
}
}
// no action required if mqtt status settings change, they just get picked up at the

@ -43,6 +43,14 @@
} while ( 0 )
#endif
#ifdef MEMLEAK_DEBUG
#include "mem.h"
bool ICACHE_FLASH_ATTR check_memleak_debug_enable(void)
{
return MEMLEAK_DEBUG_ENABLE;
}
#endif
/*
This is the main url->function dispatching data struct.
In short, it's a struct with various URLs plus their handlers. The handlers can
@ -133,6 +141,7 @@ void user_init(void) {
os_delay_us(10000L);
os_printf("\n\n** %s\n", esp_link_version);
os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*");
prHeapTimerCb(0);
// Status LEDs
statusInit();
serledInit();
@ -166,10 +175,16 @@ void user_init(void) {
// Init SNTP service
cgiServicesSNTPInit();
#ifdef MQTT
NOTICE("initializing MQTT");
mqtt_client_init();
if (flashConfig.mqtt_enable) {
NOTICE("initializing MQTT");
mqtt_client_init();
}
#endif
NOTICE("initializing user application");
app_init();
NOTICE("Waiting for work to do...");
#ifdef MEMLEAK_DEBUG
system_show_malloc();
#endif
prHeapTimerCb(0);
}

@ -12,7 +12,7 @@
#define USRTASK_H
#define _taskPrio 1
#define _task_queueLen 64
#define _task_queueLen 8
uint8_t register_usr_task (os_task_t event);
bool post_usr_task(uint8_t task, os_param_t par);

@ -2,6 +2,9 @@
#ifndef _ESP8266_H_
#define _ESP8266_H_
#undef MEMLEAK_DEBUG
#define USE_OPTIMIZE_PRINTF
#include <user_config.h>
#include <ctype.h>
#include <stdio.h>

@ -62,9 +62,9 @@ int os_printf_plus(const char *format, ...) __attribute__((format(printf, 1, 2)
// memory allocation functions are "different" due to memory debugging functionality
// added in SDK 1.4.0
void vPortFree(void *ptr, char * file, int line);
void *pvPortMalloc(size_t xWantedSize, char * file, int line);
void *pvPortZalloc(size_t, char * file, int line);
void vPortFree(void *ptr, const char * file, int line);
void *pvPortMalloc(size_t xWantedSize, const char * file, int line);
void *pvPortZalloc(size_t, const char * file, int line);
void *vPortMalloc(size_t xWantedSize);
void pvPortFree(void *ptr);

@ -185,6 +185,10 @@ MQTTCMD_Setup(CmdPacket *cmd) {
if (cmdGetArgc(&req) != 4) return;
#if 0
// This section is commented-out because we're using the same client as esp-link is using itself,
// i.e. the one set-up in the Web UI. This code was here when we used a separate client for the
// attached uC, which just makes life more complicated...
if (cmdGetArgc(&req) != 9)
return 0;
@ -261,6 +265,10 @@ MQTTCMD_Setup(CmdPacket *cmd) {
}
#if 0
// This section is commented-out because we're using the same client as esp-link is using itself,
// i.e. the one set-up in the Web UI. This code was here when we used a separate client for the
// attached uC, which just makes life more complicated...
uint32_t ICACHE_FLASH_ATTR
MQTTCMD_Connect(CmdPacket *cmd) {
CmdRequest req;

@ -46,7 +46,6 @@ static void ICACHE_FLASH_ATTR syslog_udp_recv_cb(void *arg, char *pusrdata, unsi
#define syslog_send_udp() post_usr_task(syslog_task,0)
#ifdef SYSLOG_DBG
static char ICACHE_FLASH_ATTR *syslog_get_status(void) {
switch (syslogState)
{
@ -77,11 +76,13 @@ static char ICACHE_FLASH_ATTR *syslog_get_status(void) {
}
return "UNKNOWN ";
}
#endif
static void ICACHE_FLASH_ATTR syslog_set_status(enum syslog_state state) {
syslogState = state;
DBG("[%dµs] %s: %s (%d)\n", WDEV_NOW(), __FUNCTION__, syslog_get_status(), state);
#ifndef SYSLOG_DBG
os_printf("Syslog state: %s\n", syslog_get_status());
#endif
}
static void ICACHE_FLASH_ATTR syslog_timer_arm(int delay) {
@ -261,6 +262,7 @@ void ICACHE_FLASH_ATTR syslog_init(char *syslog_host)
{
DBG("[%uµs] %s\n", WDEV_NOW(), __FUNCTION__);
os_printf("SYSLOG host=%s *host=0x%x\n", syslog_host, *syslog_host);
if (!*syslog_host) {
syslog_set_status(SYSLOG_HALTED);
return;
@ -504,8 +506,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)
if (flashConfig.syslog_host[0] == 0 || syslogState == SYSLOG_ERROR || syslogState == SYSLOG_HALTED)
return;
if (severity > flashConfig.syslog_filter)

Loading…
Cancel
Save