ESP32 WiFi 로거 - TCP, UDP 또는 웹소켓을 사용하여 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
menuconfig를 통해 구성된 경우 ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV 에 의해 생성된 로그를 보낼 수 있습니다.
ESP_LOGX() 와 동일한 사용 패턴
wifi_log()_x 함수를 사용하여 Wi-Fi를 통해 로그를 인쇄하세요.
예: wifi_log(TAG, "%s", "logger test");
ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV 로그는 menuconfig에서 구성된 경우 Wi-Fi를 통해서도 전송됩니다.
로거를 시작하려면 void app_main() 에서 start_wifi_logger() 호출하세요. 로깅 함수 wifi_log_x() (x = e,w,i,d,v) 호출하여 메시지를 기록할 수 있으며, menuconfig 통해 구성된 경우 ESP_LOGW 와 같은 일반 ESP-IDF 로깅 API 함수를 사용할 수 있습니다.
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 - 로그가 전송될 웹소켓 서버의 URI를 설정합니다. 서버의 IP 주소는 Linux 시스템에서 ifconfig 실행하여 확인할 수 있습니다.
idf.py menuconfig
Example Connection Configuration
WiFi SSID - 연결할 WiFi SSID를 설정합니다.WiFi 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 - 로그가 전송될 웹소켓 서버의 URI를 설정합니다.Queue 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
}
}