Tag Archives: ESP8266 Debugging

ESP8266 Debug

Light bulb momentsSo – I’ve learned quiet a lot in the past few days..

Watchdogs on the ESP8266

Since Espressif SDK 1.01 or thereabouts, watchdog timer operation seems to have changed – delays of any length even in init()  are out – or so it would seem? So I got onto Stanza Wang, the business Development Director of Espressif Systems who as always was most helpful and got a quick reply from one of the development engineers on this subject.

It turns out they’d prefer the use of these function:

void pp_soft_wdt_stop();    // close software watchdog
void pp_soft_wdt_restart();    // reset software watchdog

So for example use void pp_soft_wdt_stop();    before your delay and then use void pp_soft_wdt_restart(); 

Delays are not a good idea full stop if you’re using background processes such as WIFI – but you might not be!

Maximum use of FLASH

Thanks to Richard Burton, it is now possible to start programming right down at the bottom of memory – leaving LOADS of FLASH free (though iRAM continues to be a precious commodity – someone needs to do a “how to” on saving RAM. I’ve blogged on this elsewhere with a link.

Debugging and those Pesky Messages

ESP12-EAnd now…. debugging.  I have had it up to here with odd strange output from the Espressif SDK. TuanPM implemented a simple macro called INFO for outputting to the serial port for debugging and general information – but there was no way to control what came out – worse, the SDK kept throwing status information out which wasn’t wanted – so we’ve written our own.

If you’re outputting info to the serial line the best way as we’ve found is to disable Espressif’s messages using


in your user_init function. This turns off all output to the serial – unfortunately that means that os_printf() no longer works – so you’re dead in the water. We wrote our own printf equivalent for the serial port and we call it iprintf().

You don’t HAVE to make it this complicated… if you want you can simply, having disabled os_printf() use ets_printf() where you want text to the serial port - but we wanted more control.

Here are a couple of definitions – bit masking – you might choose to make your own.

This is in our DEBUG.H file

extern int enable_debug_messages; // Needed by debug.h

#ifndef USER_DEBUG_H_
    #define USER_DEBUG_H_

    #define DEBUG 1
    #define INFO 2
    #define RESPONSE 4

#endif /* USER_DEBUG_H_ */

So somewhere in the init, set a variable (see above) to the level of debugging you want….

//int enable_debug_messages = INFO | DEBUG | RESPONSE;
int enable_debug_messages = INFO | RESPONSE;


And here is the function to use that…

void ICACHE_FLASH_ATTR iprintf(uint16_t debug_type, char *fmt, ... ){
  char buf[128]; // resulting string limited to 127 chars inc arguments – change if you like
  va_list args;
  va_start (args, fmt);
  ets_vsnprintf(buf, sizeof(buf), fmt, args);
  va_end (args);
  if (debug_type & enable_debug_messages) uart0_tx_buffer(buf,os_strlen(buf));

So basically you have a function you can call with a debug level..

iprintf(INFO,”Starting up the program”);

You can pass parameters to it just as you would with printf….

iprintf(RESPONSE,”The answer is %d”,answer);


Depending on the level of debugging you want you could expand on this greatly.   Someday we’ll convince Espressif to optionally turn off that start-up 78k rubbish and we’ll have totally clean output – for now this is a great start.

A shame you often have to hunt around for this stuff!