ESP32 WiFi logger - Log messages over WiFi, using either TCP, UDP or Websockets
Example App:
protocol_examples_common (esp-idf/examples/common_components/)
cd <your_esp_idf_project>
mkdir components
cd components
cp $IDF_PATH/examples/common_components/protocol_examples_common . -r
git clone https://github.com/VedantParanjape/esp-wifi-logger.git wifi_logger
Change CMakeList.txt to add the line given below:
set(EXTRA_COMPONENT_DIRS <relative_path_to_component_folder>)
component folder must contain protocol_examples_common
and wifi_logger
component
sudo apt-get install netcat
nc -lu <PORT>
nc -l <PORT>
websocat -s <IP_ADDRESS_OF_YOUR_MACHINE>:<PORT>
websocat -s $(ip -o route get to 8.8.8.8 | sed -n 's/.*src ([0-9.]+).*/1/p'):1234
nc -l 1212
wifi_log_e() - Generate log with log level ERROR
wifi_log_w() - Generate log with log level WARN
wifi_log_i() - Generate log with log level INFO
wifi_log_d() - Generate log with log level DEBUG
wifi_log_v() - Generate log with log level VERBOSE
Can send logs generated by ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV
, if configured so through menuconfig
Usage pattern same as, ESP_LOGX()
Use wifi_log()_x
function to print logs over wifi
Example: wifi_log(TAG, "%s", "logger test");
ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV
logs will also be sent over wifi, if configured in menuconfig.
Call start_wifi_logger()
in void app_main()
to start the logger. Logging function wifi_log_x() (x = e,w,i,d,v)
can be called to log messages or normal ESP-IDF Logging API functions like ESP_LOGW
can be used if configured through menuconfig
.
Configure menuconfig
Example Connection Configuration
Set WiFi SSID and passwordComponent config
WiFi Logger configuration
Route logs generated by ESP_LOGX to the wifi logger
- Select if the logs written by system API are routed to be sent to the remote loggerNetwork Protocol (TCP/UDP/WEBSOCKET)
- Set network protocol to be usedUDP/TCP Network Protocol
Server IP Address
- Set the IP Address of the server which will receive log messages sent by ESP32Port
- Set the Port of the serverWEBSOCKET Network Protocol
Websocket Server URI
- Sets the URI of Websocket server, where logs are to be sentIP Address of the server can be found out by running ifconfig
on a linux machine
idf.py menuconfig
Example Connection Configuration
WiFi SSID
- Set WiFi SSID to connectWiFi Password
- Set WiFi PasswordComponent config
WiFi Logger configuration
Network Protocol (TCP/UDP/WEBSOCKET)
- Set network protocol to be usedRoute logs generated by ESP_LOGX to the wifi logger
- Select if the logs written by system API are routed to be sent to the remote loggerUDP/TCP Network Protocol
Server IP Address
- Set the IP Address of the server which will receive log messages sent by ESP32Port
- Set the Port of the serverWEBSOCKET Network Protocol
Websocket Server URI
- Sets the URI of Websocket server, where logs are to be sentQueue Size
- Advanced Config, change at your own risk Set the freeRTOS Queue size used to pass log messages to logger task.logger buffer size
- Advanced Config, change at your own risk Set the buffer size of char array used to generate log messages in ESP format#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "wifi_logger.h"
void app_main(void)
{
start_wifi_logger(); // Start wifi logger
while(1)
{
wifi_log_e("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> ERROR
wifi_log_w("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> WARN
wifi_log_i("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> INFO
wifi_log_d("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> DEBUG
wifi_log_v("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> VERBOSE
vTaskDelay(100); // Wait for 100ms, prevent watchdog from triggering a reset
}
}