Chris Dzombak

sharing preview • dzombak.com

How to enable debug logging for Arduino's ESP8266HTTPClient with PlatformIO

How to enable debug logging for Arduino's ESP8266HTTPClient with PlatformIO

Part of the Getting Started with ESP8266 + Arduino series.

While working on my ESP8266 Arduino HTTPS demo project, I wanted to enable debug logging from the HTTP client. It took me a few minutes to figure out, likely due to my lack of experience with this platform & toolchain (Arduino, ESP8266, PlatformIO).

In platfomio.ini, add:

build_flags =
	-DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_PORT=Serial

The first flag enables debugging for the HTTP client; the second tells it where the debug logging should go.

(I initially tried adding #define DEBUG_ESP_HTTP_CLIENT and #define DEBUG_ESP_PORT Serial in my program, before including ESP8266HTTPClient.h. That does not work, though a similar approach works to configure some third-party libraries. I believe this is because the Arduino core and therefore the HTTP client are built well before the compiler gets to my main.cpp file and its #defines, so these definitions must be set earlier.)

Previous posts in this series & related resources: