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.
esp-idf v4.3 ~ v5.0.
git clone https://github.com/nopnop2002/esp-idf-net-logging.git
cd esp-idf-net-logging/examples/basic
idf.py menuconfig
idf.py flash
In your project, add this as a git submodule to your components/ directory.
cd components
git submodule add https://github.com/nopnop2002/esp-idf-net-logging.git
git submodule update --init --recursive
The library can be configured via idf.py menuconfig
.
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.
You can use mDNS host name for your tcp server.
You can use mDNS host name for your http server.
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
.
You can see the logging using python code or mosqutto client.
-
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.
Using a local MQTT server is stable.
You can use this as a broker.
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);