Skip to content

Commit

Permalink
TvEmaster
Browse files Browse the repository at this point in the history
Syslog and debug printing fixes
  • Loading branch information
susisstrolch authored and tve committed Apr 3, 2016
1 parent b56b276 commit e3e19ff
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 145 deletions.
38 changes: 24 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# `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

Expand Down Expand Up @@ -54,17 +57,25 @@ 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)/

# Base directory of the ESP8266 SDK package, absolute
ifneq ($(wildcard ../esp-open-sdk/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)
else
ifneq ($(wildcard ../esp_iot_sdk_v1.5.1/.*),)
# Manually downloaded from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.5.1)
endif
# Firmware version (if you change this expect to make code adjustments elsewhere!)
SDK_VERS ?= esp_iot_sdk_v1.5.2

# Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
# http://bbs.espressif.com/viewforum.php?f=46
SDK_BASE ?= $(wildcard ../$(SDK_VERS))

# If the firmware isn't there, see whether it got downloaded as part of esp-open-sdk
ifeq ($(SDK_BASE),)
SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
endif

# Clean up SDK path
SDK_BASE := $(abspath $(SDK_BASE))
$(warning Using SDK from $(SDK_BASE))

# Path to bootloader file
BOOTFILE ?= $(SDK_BASE/bin/boot_v1.5.bin)

# Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool
# Windows users use the com port i.e: ESPPORT ?= com3
Expand Down Expand Up @@ -195,8 +206,6 @@ 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
Expand Down Expand Up @@ -333,6 +342,7 @@ 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 $@"
Expand Down Expand Up @@ -389,7 +399,7 @@ baseflash: all

flash: all
$(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

ifeq ($(OS),Windows_NT)
Expand Down Expand Up @@ -436,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
Expand Down Expand Up @@ -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)/user2.bin | cut -b 1-80
$(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) echo "Release file: esp-link-$(BRANCH).tgz"
$(Q) rm -rf release
Expand Down
2 changes: 1 addition & 1 deletion cmd/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#endif

#ifdef CMD_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down
2 changes: 1 addition & 1 deletion esp-link/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Some random cgi routines.
#include "config.h"

#ifdef CGI_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down
2 changes: 1 addition & 1 deletion esp-link/cgiflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down
6 changes: 3 additions & 3 deletions esp-link/cgimqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ char *mqttState(void) {
#include "cgimqtt.h"

#ifdef CGIMQTT_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down Expand Up @@ -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)
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion esp-link/cgioptiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define ATTEMPTS 8 // number of attempts total to make

#ifdef OPTIBOOT_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down
2 changes: 1 addition & 1 deletion esp-link/cgiservices.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "cgimqtt.h"

#ifdef CGISERVICES_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down
73 changes: 47 additions & 26 deletions esp-link/cgiwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,34 @@ 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, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#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)

Expand All @@ -34,7 +55,7 @@ bool mdns_started = false;
// ===== wifi status change callbacks
static WifiStateChangeCb wifi_state_change_cb[4];

// Temp store for new staion config
// Temp store for new station config
struct station_config stconf;

// Temp store for new ap config
Expand Down Expand Up @@ -68,37 +89,37 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) {
case EVENT_STAMODE_CONNECTED:
wifiState = wifiIsConnected;
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);
statusWifiUpdate(wifiState);
break;
case EVENT_STAMODE_DISCONNECTED:
wifiState = wifiIsDisconnected;
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);
statusWifiUpdate(wifiState);
break;
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);
break;
case EVENT_STAMODE_GOT_IP:
wifiState = wifiGotIP;
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.gw));
statusWifiUpdate(wifiState);
if (!mdns_started)
wifiStartMDNS(evt->event_info.got_ip.ip);
break;
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);
break;
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);
break;
default:
Expand All @@ -118,7 +139,7 @@ void ICACHE_FLASH_ATTR wifiAddStateChangeCb(WifiStateChangeCb cb) {
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) {
Expand Down Expand Up @@ -163,7 +184,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
struct bss_info *bss_link = (struct bss_info *)arg;

if (status!=OK) {
DBG("wifiScanDoneCb status=%d\n", status);
WARNING("wifiScanDoneCb status=%d", status);
cgiWifiAps.scanInProgress=0;
return;
}
Expand All @@ -183,7 +204,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;
DBG("Scan done: found %d APs\n", n);
INFO("Scan done: found %d APs", n);

//Copy access point data to the static struct
n=0;
Expand All @@ -192,15 +213,15 @@ 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.
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;
}
//Save the ap data.
cgiWifiAps.apData[n]=(ApData *)os_malloc(sizeof(ApData));
cgiWifiAps.apData[n]->rssi=bss_link->rssi;
cgiWifiAps.apData[n]->enc=bss_link->authmode;
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;
n++;
Expand All @@ -211,7 +232,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {

static ETSTimer scanTimer;
static void ICACHE_FLASH_ATTR scanStartCb(void *arg) {
DBG("Starting a scan\n");
INFO("Starting a scan");
wifi_station_scan(NULL, wifiScanDoneCb);
}

Expand Down Expand Up @@ -303,28 +324,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;
DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);
NOTICE("check: mode=%s status=%d", 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
DBG("Wifi got IP. Going into STA mode..\n");
NOTICE("got IP. Going into STA mode..");
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) {
DBG("Wifi connect failed. Going into STA+AP mode..\n");
wifi_set_opmode(3);
wifi_softap_set_config(&apconf);
} else {
if (m != 3) {
NOTICE("connect failed. Going into STA+AP mode..");
wifi_set_opmode(3);
wifi_softap_set_config(&apconf);
}
log_uart(true);
DBG("Enabling/continuing uart log\n");
INFO("Enabling/continuing uart log");
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
}
}
Expand All @@ -335,7 +356,7 @@ static ETSTimer reassTimer;

// Callback actually doing reassociation
static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) {
DBG("Wifi changing association\n");
NOTICE("changing association");
wifi_station_disconnect();
stconf.bssid_set = 0;
wifi_station_set_config(&stconf);
Expand Down Expand Up @@ -369,7 +390,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);
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
os_timer_disarm(&reassTimer);
Expand Down Expand Up @@ -430,7 +451,7 @@ void ICACHE_FLASH_ATTR configWifiIP() {
if (wifi_station_dhcpc_status() == DHCP_STARTED)
wifi_station_dhcpc_stop();
wifi_station_dhcpc_start();
DBG("Wifi uses DHCP, hostname=%s\n", flashConfig.hostname);
NOTICE("uses DHCP, hostname=%s", flashConfig.hostname);
} else {
// no DHCP, we got static network config!
wifi_station_dhcpc_stop();
Expand All @@ -439,7 +460,7 @@ void ICACHE_FLASH_ATTR configWifiIP() {
ipi.netmask.addr = flashConfig.netmask;
ipi.gw.addr = flashConfig.gateway;
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
debugIP();
Expand Down
2 changes: 1 addition & 1 deletion esp-link/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "log.h"

#ifdef LOG_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
Expand Down
2 changes: 1 addition & 1 deletion esp-link/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ 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("** esp-link ready");
NOTICE("** %s: ready, heap=%ld", esp_link_version, (unsigned long)system_get_free_heap_size());

// Init SNTP service
cgiServicesSNTPInit();
Expand Down
Loading

0 comments on commit e3e19ff

Please sign in to comment.