How to get DEBUG running

I have an ESP8266 with WiFi-connecting problems.

I have found DEBUG_WIFI_MULTI() in ESP8266WiFiMulti which would give me a lot of information.
But I do not know how I can enable my program to show these infos.

Thanx for helping!

 * @file ESP8266WiFiMulti.cpp
 * @date 16.05.2015
 * @author Markus Sattler
 * Copyright (c) 2015 Markus Sattler. All rights reserved.
 * This file is part of the esp8266 core for Arduino environment.
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#include "ESP8266WiFiMulti.h"
#include <limits.h>
#include <string.h>

ESP8266WiFiMulti::ESP8266WiFiMulti() {

ESP8266WiFiMulti::~ESP8266WiFiMulti() {

bool ESP8266WiFiMulti::addAP(const char* ssid, const char *passphrase) {
    return APlistAdd(ssid, passphrase);

wl_status_t ESP8266WiFiMulti::run(void) {

    int8_t scanResult;
    wl_status_t status = WiFi.status();
    if(status == WL_DISCONNECTED || status == WL_NO_SSID_AVAIL || status == WL_IDLE_STATUS || status == WL_CONNECT_FAILED) {

        scanResult = WiFi.scanComplete();
        if(scanResult == WIFI_SCAN_RUNNING) {
            // scan is running
            return WL_NO_SSID_AVAIL;
        } else if(scanResult > 0) {
            // scan done analyze
            WifiAPlist_t bestNetwork { NULL, NULL };
            int bestNetworkDb = INT_MIN;
            uint8 bestBSSID[6];
            int32_t bestChannel;

            DEBUG_WIFI_MULTI("[WIFI] scan done\n");

            if(scanResult <= 0) {
                DEBUG_WIFI_MULTI("[WIFI] no networks found\n");
            } else {
                DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", scanResult);
                for(int8_t i = 0; i < scanResult; ++i) {

                    String ssid_scan;
                    int32_t rssi_scan;
                    uint8_t sec_scan;
                    uint8_t* BSSID_scan;
                    int32_t chan_scan;
                    bool hidden_scan;

                    WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);

                    bool known = false;
                    for(uint32_t x = 0; x < APlist.size(); x++) {
                        WifiAPlist_t entry = APlist[x];

                        if(ssid_scan == entry.ssid) { // SSID match
                            known = true;
                            if(rssi_scan > bestNetworkDb) { // best network
                                if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan
                                    bestNetworkDb = rssi_scan;
                                    bestChannel = chan_scan;
                                    memcpy((void*) &bestNetwork, (void*) &entry, sizeof(bestNetwork));
                                    memcpy((void*) &bestBSSID, (void*) BSSID_scan, sizeof(bestBSSID));

                    if(known) {
                        DEBUG_WIFI_MULTI(" ---> ");
                    } else {
                        DEBUG_WIFI_MULTI("      ");

                    DEBUG_WIFI_MULTI(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c\n", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan.c_str(), rssi_scan, (sec_scan == ENC_TYPE_NONE) ? ' ' : '*');

            // clean up ram


            if(bestNetwork.ssid) {
                DEBUG_WIFI_MULTI("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channal: %d (%d)\n", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb);

                WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
                status = WiFi.status();

                // wait for connection or fail
                while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED) {
                    status = WiFi.status();
                IPAddress ip;
                uint8_t * mac;
                switch(status) {
                    case WL_CONNECTED:
                        ip = WiFi.localIP();
                        mac = WiFi.BSSID();
                        DEBUG_WIFI_MULTI("[WIFI] Connecting done.\n");
                        DEBUG_WIFI_MULTI("[WIFI] SSID: %s\n", WiFi.SSID().c_str());
                        DEBUG_WIFI_MULTI("[WIFI] IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
                        DEBUG_WIFI_MULTI("[WIFI] MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
                        DEBUG_WIFI_MULTI("[WIFI] Channel: %d\n",;
                    case WL_NO_SSID_AVAIL:
                        DEBUG_WIFI_MULTI("[WIFI] Connecting Failed AP not found.\n");
                    case WL_CONNECT_FAILED:
                        DEBUG_WIFI_MULTI("[WIFI] Connecting Failed.\n");
                        DEBUG_WIFI_MULTI("[WIFI] Connecting Failed (%d).\n", status);
            } else {
                DEBUG_WIFI_MULTI("[WIFI] no matching wifi found!\n");
        } else {
            // start scan
            DEBUG_WIFI_MULTI("[WIFI] delete old wifi config...\n");

            DEBUG_WIFI_MULTI("[WIFI] start scan\n");
            // scan wifi async mode
    return status;

// ##################################################################################

bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {

    WifiAPlist_t newAP;

    if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
        // fail SSID to long or missing!
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid to long\n");
        return false;

    if(passphrase && strlen(passphrase) > 63) {
        // fail passphrase to long!
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] passphrase to long\n");
        return false;

    newAP.ssid = strdup(ssid);

    if(!newAP.ssid) {
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] fail newAP.ssid == 0\n");
        return false;

    if(passphrase) {
        newAP.passphrase = strdup(passphrase);
    } else {
        newAP.passphrase = strdup("");

    if(!newAP.passphrase) {
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] fail newAP.passphrase == 0\n");
        return false;

    DEBUG_WIFI_MULTI("[WIFI][APlistAdd] add SSID: %s\n", newAP.ssid);
    return true;

void ESP8266WiFiMulti::APlistClean(void) {
    for(uint32_t i = 0; i < APlist.size(); i++) {
        WifiAPlist_t entry = APlist[i];
        if(entry.ssid) {
        if(entry.passphrase) {

Thanx for responding!

Of course I had a look at that file too. Unfortunately, my C knowledges are yet still that small, so this did not help me further. And I did not find an example that explains how to do. Possibly, I used the wrong Google search terms ..


I tried it with any combination of

#define DEBUG

without success.

As I stated before, I just started with ESP8266 and my C++ is still at it beginnings (but I am eager to get on :slight_smile: )

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

/*  try to activate the output of DEBUG_WIFI_MULTI()
#define DEBUG

const char* ssid = "nope"; 
const char* password = "double-nope"; 

const int ledPinD7 = 13;

ESP8266WiFiMulti WiFiMulti;

void setup() {
   pinMode(ledPinD7, OUTPUT);

  // Serial.setDebugOutput(true);


   for(uint8_t t = 4; t > 0; t--) {
       Serial.printf("[SETUP] WAIT %d...\n", t);

   WiFiMulti.addAP("ssid", "password");

void loop() {
   String message;
   Serial.print("Connecting to "); 

   // wait for WiFi connection
   if(( == WL_CONNECTED)) {
       Serial.println("\nConnected to " + String(ssid) );
       Serial.print("IP address: "); 

       HTTPClient http;

       Serial.print("[HTTP] begin...\n");
       message = WiFi.localIP().toString();
       message = "http://somewhere/a/" + message;
       Serial.println("GetString: " + message);
       http.begin(message); //HTTP

       Serial.print("[HTTP] GET...\n");
       // start connection and send HTTP header
       int httpCode = http.GET();

       // httpCode will be negative on error
       if(httpCode > 0) {
           // HTTP header has been send and Server response header has been handled
           Serial.printf("[HTTP] GET... code: %d\n", httpCode);

           // file found at server
           if(httpCode == HTTP_CODE_OK) {
               String payload = http.getString();
       } else {
           Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());

   } else {
     Serial.print("[] WiFi.status = ");


Since no one has posted the solution and I really wanted it myself, maybe someone else will find this useful. Enabling debugging is described in detail here.

DEBUG_ESP_PORT is set from the IDE go to "Tools" ->"Debug Port" and set it to Serial or Serial1. To set the debug level go to "Tools" ->"Debug Level" and the needed component there.

From the Doc

Debug Port The port has the define DEBUG_ESP_PORT possible value: - Disabled: define not existing - Serial: Serial - Serial1: Serial1

Debug Level All defines for the different levels starts with DEBUG_ESP_

a full list can be found here in the boards.txt

Please stop necro'ing old threads. If someone needs the info here, they can find it using the search tool.