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.4/v5.x.
git clone https://github.com/nopnop2002/esp-idf-net-logging
cd esp-idf-net-logging/basic
idf.py menuconfig
idf.py flash
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 the mDNS hostname of such a TCP server instead of the IP address.
tcp-server.local
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 UDP
You can usenetcat
as server.
We can use this as Logging Viewer.
Note that the most recent logging is displayed at the top.
We can also use this as Logging Viewer.
Note that the most recent logging is displayed at the buttom.
I like this one better.
There are others if you look for them. -
for TCP
You can usenetcat
as server.
We can use this as Logging Viewer.
-
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.
You can disable this if you are unable to display ANSI color codes correctly.
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);