Skip to content

nopnop2002/esp-idf-net-logging

Repository files navigation

esp-idf-net-logging

Redirect esp-idf logging to the network.

esp-idf has a Logging library.
The Logging library contains the esp_log_set_vprintf function.
By default, log output goes to UART0.
This function can be used to redirect log output to some other destination, such as file or network.

I made a project that uses 3 UARTs of ESP32.
But I was in trouble because there was no logging output destination.
So I made this.

The following protocols are available for this project.

  • UDP
  • TCP
  • MQTT
  • HTTP(POST)

I referred to this.

Software requirements

esp-idf v4.4/v5.x.

Installation

git clone https://github.com/nopnop2002/esp-idf-net-logging
cd esp-idf-net-logging/basic
idf.py menuconfig
idf.py flash

Configuration

config-top

Configuration for UDP Redirect

config-udp

There are the following four methods for specifying the UDP Address.

  • Limited broadcast address
    The address represented by 255.255.255.255, or <broadcast>, cannot cross the router.
    Both the sender and receiver must specify a Limited broadcast address.

  • Directed broadcast address
    It is possible to cross the router with an address that represents only the last octet as 255, such as 192.168.10.255.
    Both the sender and receiver must specify the Directed broadcast address.
    Note that it is possible to pass through the router.

  • Multicast address
    Data is sent to all PCs belonging to a specific group using a special address (224.0.0.0 to 239.255.255.255) called a multicast address.
    I've never used it, so I don't know anything more.

  • Unicast address
    It is possible to cross the router with an address that specifies all octets, such as 192.168.10.41.
    Both the sender and receiver must specify the Unicast address.

Configuration for TCP Redirect

config-tcp

You can use the mDNS hostname of such a TCP server instead of the IP address.
tcp-server.local

Configuration for MQTT Redirect

config-mqtt

Configuration for HTTP Redirect

config-http

You can use mDNS host name for your http server.

Disable Logging to STDOUT

config-stdout

Use xRingBuffer as IPC

config-xRingBuffer

Both xMessageBuffer and xRingBuffer are interprocess communication (IPC) components provided by ESP-IDF.
Several drivers provided by ESP-IDF use xRingBuffer.
This project uses xMessageBuffer by default.
If you use this project at the same time as a driver that uses xRingBuffer, using xRingBuffer uses less memory.
Memory usage status can be checked with idf.py size-files.

View logging

You can see the logging using python code or mosqutto client.

  • for UDP
    net-logging-udp
    You can use netcat as server.
    netcat-udp

  • for TCP
    net-logging-tcp
    You can use netcat as server.
    netcat-tcp

  • for MQTT
    The wifi logging is output in two parts.
    First time:W (7060) wifi:
    Second time:Characters after that
    In MQTT and HTTP, it is displayed separately in two.
    If you use broker.emqx.io, continuous Logging will drop.
    net-logging-mqtt
    Using a local MQTT server is stable.
    You can use this as a broker.
    net-logging-mqtt-local

  • for HTTP
    net-logging-http

API

Use one of the following.
Subsequent logging will be redirected.

esp_err_t udp_logging_init(char *ipaddr, unsigned long port, int16_t enableStdout);
esp_err_t tcp_logging_init(char *ipaddr, unsigned long port, int16_t enableStdout);
esp_err_t mqtt_logging_init(char *url, char *topic, int16_t enableStdout);
esp_err_t http_logging_init(char *url, int16_t enableStdout);