DS_CAP_SYS_LOG_HW - denis-stepanov/esp-ds-system GitHub Wiki

DS_CAP_SYS_LOG_HW — System Log on Hardware Serial Line

Description

This capability adds support for a syslog on hardware serial line (supported by Serial class). For description of what syslog can do, see its page. The serial link is initialized with the speed of 115200 bod and uses default serial settings, i.e. 8-N-1. Non-standard configurations (like different speed or use of Serial1 instead of Serial) can be achieved by changing few lines in System.cpp.

Requires

Since this capability is considered as implementation of syslog, you do not need to define the parent capability DS_CAP_SYS_LOG explicitly. If not found, its definition will be automatically enabled.

Cooperates With

  • DS_CAP_WEBSERVER — if web server is enabled, its "System Information" page will include a line about serial link configuration.

Conflicts With

  • DS_CAP_SYS_LED — in some boards, like ESP-01, the on-board LED is controlled by a serial TX pin. This means that, if both LED and syslog capabilities are enabled, a conflict over pin control may happen. Both features will likely misbehave in this case. To decrease such possibility, library will issue a compilation warning:

    #warning "In ESP8266, capabilities DS_CAP_SYS_LED and DS_CAP_SYS_LOG_HW may conflict on a pin. Define DS_LED_VS_SERIAL_CHECKED_OK to suppress this warning"
    

    In many cases, serial TX and on-board LED will use different pins. It is also possible to reallocate serial TX pin at runtime (the on-board LED is soldered to the pin and cannot be altered). The library has no means to detect if there would be actually a conflict in your case or not. If you are sure that there is no conflict, define DS_LED_VS_SERIAL_CHECKED_OK in MySystem.h in order to suppress the compilation warning.

Usage

MySystem.h:

#define DS_CAP_SYS_LOG_HW   // Enable syslog on hardware serial line

#include "System.h"         // System global definitions

sketch.ino:

#include "MySystem.h"

using namespace ds;

void setup() {
    System::begin();

    System::log->println("Simlpe log message");
    System::log->printf("Complex %s message including number: %d\n", "log", 12345);
    System::log->printf(TIMED("Log message with millis() timestamp\n"));   // Requires printf()
}

void loop() {
}

Mandatory Calls

System::begin() Required
System::update() Not required

Examples

Nearly all other examples use syslog on hardware serial to print some output, so they can be equally consulted.

Bugs

  • For historical reason, assignment of Serial log sink is currently done in the generic log section rather under hardware serial option (issue #4). This problem has no user-visible effect and will be fixed in future version of the library. For the same reason, if DS_CAP_SYS_LOG is defined without DS_CAP_SYS_LOG_HW, the log would be still sent to Serial, but without proper initialization; i.e., nothing will be printed;
  • Printout issued in setup() could be displayed as garbage in Arduino IDE Serial Monitor upon program uploading (there is no issue if controller is reset). The reason of this is not fully understood, but it could be related to interface transition from programming to communication. The library tries to circumvent this by adding a small delay (150 ms) after serial port initialization. If this delay is undesirable for some reason, define DS_UNSTABLE_SERIAL macro in MySystem.h.

Availability

Version 1.0 or later. Macro DS_UNSTABLE_SERIAL is available from version 1.1.

See Also

⚠️ **GitHub.com Fallback** ⚠️