matthias-bs / BresserWeatherSensorTTN

Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver based on ESP32 and RFM95W/SX1276 - sends data to a LoRaWAN Network (e.g. The Things Network)
MIT License
22 stars 9 forks source link

Replace DEBUG_PRINTF/DEBUG_PRINTF_TS by Arduino logging functions #27

Closed matthias-bs closed 1 year ago

matthias-bs commented 1 year ago

The DEBUG_PRINTF/DEBUG_PRINTF_TS macros only allow switching debug messages on/off using the define _BWS_DEBUG_MODE_ in BresserWeatherSensorTTNCfg.h.

With the Arduino logging functions from https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-log.h, the debug level can be set in a fine-grained, standardized way from the Arduino IDE (Tools->Core Debug Level: "<NONE|ERROR|WARN|INFO|DEBUG|VERBOSE>")

matthias-bs commented 1 year ago

The purpose of cEventLog is to implement the actual debug printing in callback functions using RegisterListener(). This is not implemented entirely consistent; some Serial.print() function calls are still left in MCCI_Arduino_LoRaWAN_Library/src/lib/arduino_lorawan_cEventLog.cpp.

This should be changed as follows:

bool
Arduino_LoRaWAN::cEventLog::processSingleEvent()
    {
    if (this->m_head == this->m_tail)
        {
        return false;
        }

    auto const pEvent = &this->m_queue[this->m_head];

    //Serial.print(osticks2ms(pEvent->time));
    //Serial.print(" ms:");
    pEvent->pCallBack(pEvent);
    //Serial.println();

    if (++m_head == sizeof(m_queue) / sizeof(m_queue[0]))
        {
        m_head = 0;
        }

    return true;
    }

N.B.: With Arduino logging functions (such as log_i()) a timestamp is included in the output per default.

matthias-bs commented 1 year ago

Implemented in https://github.com/matthias-bs/BresserWeatherSensorTTN/commit/1fe5a658da5996bc4e6a319a43d03b4fd8148d93