esp wifi logger
1.0.0
ESP32 WiFi 记录器 - 使用 TCP、UDP 或 Websockets 通过 WiFi 记录消息
示例应用程序: 
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
更改 CMakeList.txt 以添加以下行:
set(EXTRA_COMPONENT_DIRS <relative_path_to_component_folder>)
组件文件夹必须包含protocol_examples_common和wifi_logger组件
sudo apt-get install netcatnc -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'):1234nc -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
可以发送ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV生成的日志(如果通过 menuconfig 配置)
使用模式与ESP_LOGX()相同
使用wifi_log()_x函数通过 wifi 打印日志
示例: wifi_log(TAG, "%s", "logger test");
如果在 menuconfig 中配置ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV日志也将通过 wifi 发送。
在void app_main()中调用start_wifi_logger()来启动记录器。可以调用日志函数wifi_log_x() (x = e,w,i,d,v)来记录消息,如果通过menuconfig配置,则可以使用普通 ESP-IDF 日志 API 函数(如ESP_LOGW 。
配置menuconfig配置
Example Connection Configuration设置 WiFi SSID 和密码Component configWiFi Logger configurationRoute logs generated by ESP_LOGX to the wifi logger - 选择是否将系统 API 写入的日志路由发送到远程记录器Network Protocol (TCP/UDP/WEBSOCKET) - 设置要使用的网络协议UDP/TCP Network ProtocolServer IP Address - 设置将接收 ESP32 发送的日志消息的服务器的 IP 地址Port - 设置服务器的端口WEBSOCKET Network ProtocolWebsocket Server URI - 设置要发送日志的 Websocket 服务器的 URI在Linux机器上运行ifconfig可以找到服务器的IP地址
idf.py menuconfig
Example Connection Configuration
WiFi SSID - 设置要连接的 WiFi SSIDWiFi Password - 设置 WiFi 密码Component config
WiFi Logger configurationNetwork Protocol (TCP/UDP/WEBSOCKET) - 设置要使用的网络协议Route logs generated by ESP_LOGX to the wifi logger - 选择是否将系统 API 写入的日志路由发送到远程记录器UDP/TCP Network ProtocolServer IP Address - 设置将接收 ESP32 发送的日志消息的服务器的 IP 地址Port - 设置服务器的端口WEBSOCKET Network ProtocolWebsocket Server URI - 设置要发送日志的 Websocket 服务器的 URIQueue Size -高级配置,更改需要您自担风险设置用于将日志消息传递到记录器任务的 freeRTOS 队列大小。logger buffer size -高级配置,更改需要您自担风险设置用于生成 ESP 格式日志消息的字符数组的缓冲区大小
#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
}
}