doc: updated readme

This commit is contained in:
aZholtikov committed 2026-08-16 07:58:30 +03:00
1 parent f6a1a6a315
commit a7f4930a55
1 file changed
+18 -91
+18 -91
View File
@@ -1,20 +1,28 @@
# ESP32 ESP-IDF component for Syslog server UDP client # ESP32 ESP-IDF component for Syslog UDP client
## Wiki
[EN](WIKI_EN.md) | [RU](WIKI_RU.md)
## Tested on ## Tested on
1. [ESP32 ESP-IDF v6.0.0](https://docs.espressif.com/projects/esp-idf/en/v6.0/esp32/index.html) 1. [ESP-IDF v6.0.0](https://docs.espressif.com/projects/esp-idf/en/v6.0/esp32/index.html)
## SAST Tools ## SAST Tools
[PVS-Studio](https://pvs-studio.com/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) - static analyzer for C, C++, C#, and Java code. [PVS-Studio](https://pvs-studio.com/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) — static analyzer for C, C++, C#, and Java code.
## Note ## Features
Messages are built using the format defined in [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424). 1. Support for all standard syslog facility codes (0-23) per RFC 5424
2. Support for all standard syslog severity levels (0-7) per RFC 5424
3. RFC 5424 format message generation with priority calculation
4. Thread-safe initialization and deinitialization
5. MALLOC_CAP_8BIT memory allocation for DMA compatibility
## Using ## Using
In an existing project, run the following command to install the component: In an existing project, run the following command to install the components:
```text ```text
cd ../your_project/components cd ../your_project/components
@@ -27,91 +35,10 @@ In the application, add the component:
#include "zh_syslog.h" #include "zh_syslog.h"
``` ```
## Example ## Examples
Sending messages: See Wiki [EN](WIKI_EN.md#usage-examples) | [RU](WIKI_RU.md#примеры-использования)
```c ## Note
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_wifi.h"
#include "esp_timer.h"
#include "esp_event.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "zh_syslog.h"
#define WIFI_SSID "ssid" Messages are built using the format defined in [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424).
#define WIFI_PASS "password"
#define WIFI_MAXIMUM_RETRY 5
#define WIFI_RECONNECT_TIME 5
#define WIFI_CONNECT_SUCCESS BIT0
#define SYSLOG_IP "192.168.1.2"
esp_timer_handle_t wifi_reconnect_timer = {0};
uint8_t wifi_reconnect_retry_num = 0;
EventGroupHandle_t event_group_handle = {0};
void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
void app_main(void)
{
esp_log_level_set("zh_syslog", ESP_LOG_ERROR);
nvs_flash_init();
esp_netif_init();
esp_event_loop_create_default();
esp_netif_create_default_wifi_sta();
wifi_init_config_t wifi_init_sta_config = WIFI_INIT_CONFIG_DEFAULT();
esp_wifi_init(&wifi_init_sta_config);
wifi_config_t wifi_config = {
.sta.ssid = WIFI_SSID,
.sta.password = WIFI_PASS};
esp_wifi_set_mode(WIFI_MODE_STA);
esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL);
esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifi_event_handler, NULL, NULL);
esp_wifi_start();
event_group_handle = xEventGroupCreate();
xEventGroupWaitBits(event_group_handle, WIFI_CONNECT_SUCCESS, pdTRUE, pdTRUE, portMAX_DELAY);
zh_syslog_init_config_t config = ZH_SYSLOG_INIT_CONFIG_DEFAULT();
strcpy(config.syslog_ip, SYSLOG_IP);
zh_syslog_init(&config);
for (;;)
{
zh_syslog_send(ZH_USER, ZH_INFO, "my_device", "my_application", "Message");
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
switch (event_id)
{
case WIFI_EVENT_STA_START:
esp_wifi_connect();
break;
case WIFI_EVENT_STA_DISCONNECTED:
if (wifi_reconnect_retry_num < WIFI_MAXIMUM_RETRY)
{
esp_wifi_connect();
++wifi_reconnect_retry_num;
}
else
{
wifi_reconnect_retry_num = 0;
esp_timer_create_args_t wifi_reconnect_timer_args = {
.callback = (void *)esp_wifi_connect};
esp_timer_create(&wifi_reconnect_timer_args, &wifi_reconnect_timer);
esp_timer_start_once(wifi_reconnect_timer, WIFI_RECONNECT_TIME * 1000);
}
break;
case IP_EVENT_STA_GOT_IP:
wifi_reconnect_retry_num = 0;
xEventGroupSetBits(event_group_handle, WIFI_CONNECT_SUCCESS);
break;
default:
break;
}
}
```