feat: added logging to syslog server

This commit is contained in:
aZholtikov committed 2026-03-08 11:49:48 +03:00
1 parent 17f41cde85
commit f2ffa5bebd
6 files changed
+121 -52

No files matched your search

+3
View File
@@ -22,3 +22,6 @@
[submodule "components/zh_tachometer"] [submodule "components/zh_tachometer"]
path = components/zh_tachometer path = components/zh_tachometer
url = https://github.com/aZholtikov/zh_tachometer url = https://github.com/aZholtikov/zh_tachometer
[submodule "components/zh_syslog"]
path = components/zh_syslog
url = https://github.com/aZholtikov/zh_syslog
Submodule components/zh_syslog added at 6105b97292.
+1 -1
View File
@@ -1 +1 @@
idf_component_register(SRCS "ate0005.c" INCLUDE_DIRS "" REQUIRES zh_160x_i2c zh_encoder zh_inclinometer zh_tachometer zh_espnow zh_ota_server esp_wifi nvs_flash esp_timer esp_app_format) idf_component_register(SRCS "ate0005.c" INCLUDE_DIRS "" REQUIRES zh_160x_i2c zh_encoder zh_inclinometer zh_tachometer zh_espnow zh_ota_server zh_syslog esp_wifi nvs_flash esp_timer esp_app_format)
+103 -45
View File
@@ -1,7 +1,5 @@
#include "ate0005.h" #include "ate0005.h"
// #define DEBUG
static task_stats_t _task_stats = {A_INCLINOMETER_TASK_STACK_SIZE, B_INCLINOMETER_TASK_STACK_SIZE, A_TACHOMETER_TASK_STACK_SIZE, B_TACHOMETER_TASK_STACK_SIZE}; static task_stats_t _task_stats = {A_INCLINOMETER_TASK_STACK_SIZE, B_INCLINOMETER_TASK_STACK_SIZE, A_TACHOMETER_TASK_STACK_SIZE, B_TACHOMETER_TASK_STACK_SIZE};
static httpd_handle_t _http_server_handle = NULL; static httpd_handle_t _http_server_handle = NULL;
@@ -19,8 +17,9 @@ static TaskHandle_t _a_inclinometer_task_handle = NULL;
static TaskHandle_t _b_inclinometer_task_handle = NULL; static TaskHandle_t _b_inclinometer_task_handle = NULL;
static TaskHandle_t _a_tachometer_task_handle = NULL; static TaskHandle_t _a_tachometer_task_handle = NULL;
static TaskHandle_t _b_tachometer_task_handle = NULL; static TaskHandle_t _b_tachometer_task_handle = NULL;
static TaskHandle_t _zh_stats_task_handle = NULL;
static void _zh_wifi_softap_init(void); static void _zh_wifi_init(void);
static void _zh_webserver_init(void); static void _zh_webserver_init(void);
static void _zh_espnow_init(void); static void _zh_espnow_init(void);
static void _zh_encoder_init(void); static void _zh_encoder_init(void);
@@ -32,29 +31,30 @@ static void _zh_pcf8574_init(void);
static void _zh_system_load(void); static void _zh_system_load(void);
static void _zh_timer_init(void); static void _zh_timer_init(void);
static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
// static void _zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); // To Do. static void _zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
static void _wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
static void _zh_inclinometer_reset_timer_on_alarm_cb(void *arg); static void _zh_inclinometer_reset_timer_on_alarm_cb(void *arg);
static void _zh_a_inclinometer_processing_task(void *pvParameter); static void _zh_a_inclinometer_processing_task(void *pvParameter);
static void _zh_b_inclinometer_processing_task(void *pvParameter); static void _zh_b_inclinometer_processing_task(void *pvParameter);
static void _zh_a_tachometer_processing_task(void *pvParameter); static void _zh_a_tachometer_processing_task(void *pvParameter);
static void _zh_b_tachometer_processing_task(void *pvParameter); static void _zh_b_tachometer_processing_task(void *pvParameter);
#ifdef DEBUG
static void _zh_stats_processing_task(void *pvParameter); static void _zh_stats_processing_task(void *pvParameter);
#endif
static const char *_main_menu[] = {MAIN_MENU_ANGLE_ANGLE_NAME, MAIN_MENU_TACHO_TACHO_NAME, MAIN_MENU_ANGLE_TACHO_NAME, MAIN_MENU_REMOTE_NAME}; static const char *_main_menu[] = {MAIN_MENU_ANGLE_ANGLE_NAME, MAIN_MENU_TACHO_TACHO_NAME, MAIN_MENU_ANGLE_TACHO_NAME, MAIN_MENU_REMOTE_NAME};
volatile static bool _is_menu_mode = false; volatile static bool _is_menu_mode = false;
volatile static bool _is_reset_mode = false; volatile static bool _is_reset_mode = false;
volatile static bool _is_reset_occurred = false; volatile static bool _is_reset_occurred = false;
volatile static uint8_t _current_menu_value = 0; volatile static uint8_t _current_menu_value = 0;
volatile static uint8_t _wifi_reconnect_retry_num = 0;
volatile static bool _is_wifi_connected = false;
void app_main(void) void app_main(void)
{ {
_lcd_mutex = xSemaphoreCreateMutex(); _lcd_mutex = xSemaphoreCreateMutex();
nvs_flash_init(); nvs_flash_init();
esp_event_loop_create_default(); esp_event_loop_create_default();
_zh_wifi_softap_init(); _zh_wifi_init();
_zh_webserver_init(); _zh_webserver_init();
_zh_pcf8574_init(); _zh_pcf8574_init();
_zh_system_load(); _zh_system_load();
@@ -63,9 +63,6 @@ void app_main(void)
_zh_b_inclinometer_init(); _zh_b_inclinometer_init();
_zh_espnow_init(); _zh_espnow_init();
_zh_timer_init(); _zh_timer_init();
#ifdef DEBUG
xTaskCreatePinnedToCore(&_zh_stats_processing_task, "stats_processing_task", STATS_TASK_STACK_SIZE, NULL, STATS_TASK_PRIORITY, NULL, tskNO_AFFINITY);
#endif
const esp_partition_t *running = esp_ota_get_running_partition(); const esp_partition_t *running = esp_ota_get_running_partition();
esp_ota_img_states_t ota_state = {0}; esp_ota_img_states_t ota_state = {0};
esp_ota_get_state_partition(running, &ota_state); esp_ota_get_state_partition(running, &ota_state);
@@ -76,23 +73,29 @@ void app_main(void)
} }
} }
static void _zh_wifi_softap_init(void) static void _zh_wifi_init(void)
{ {
esp_netif_init(); esp_netif_init();
esp_netif_create_default_wifi_ap(); esp_netif_create_default_wifi_ap();
wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT(); esp_netif_create_default_wifi_sta();
esp_wifi_init(&wifi_config); wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
wifi_config_t ap_config = { esp_wifi_init(&wifi_init_config);
.ap = { wifi_config_t wifi_ap_config = {
.ssid = WIFI_SSID, .ap.ssid = WIFI_AP_SSID,
.password = WIFI_PASS, .ap.password = WIFI_AP_PASS,
.channel = WIFI_CHANNEL, .ap.channel = WIFI_AP_CHANNEL,
.max_connection = MAX_STA_CONNECTION, .ap.max_connection = MAX_AP_CONNECTION,
.authmode = WIFI_AUTH_WPA2_PSK, .ap.authmode = WIFI_AUTH_WPA2_PSK,
}, };
wifi_config_t wifi_sta_config = {
.sta.ssid = WIFI_STA_SSID,
.sta.password = WIFI_STA_PASS,
}; };
esp_wifi_set_mode(WIFI_MODE_APSTA); esp_wifi_set_mode(WIFI_MODE_APSTA);
esp_wifi_set_config(WIFI_IF_AP, &ap_config); esp_wifi_set_config(WIFI_IF_AP, &wifi_ap_config);
esp_wifi_set_config(WIFI_IF_STA, &wifi_sta_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(); esp_wifi_start();
} }
@@ -328,10 +331,43 @@ static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, in
} }
} }
// static void _zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) static void _zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
// { {
// // To Do. // To Do.
// } }
static 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 (_is_wifi_connected == true)
{
vTaskDelete(_zh_stats_task_handle);
zh_syslog_deinit();
_is_wifi_connected = false;
}
if (_wifi_reconnect_retry_num < WIFI_STA_MAXIMUM_RETRY)
{
esp_wifi_connect();
++_wifi_reconnect_retry_num;
}
break;
case IP_EVENT_STA_GOT_IP:
_wifi_reconnect_retry_num = 0;
_is_wifi_connected = true;
zh_syslog_init_config_t config = ZH_SYSLOG_INIT_CONFIG_DEFAULT();
strcpy(config.syslog_ip, SYSLOG_IP);
zh_syslog_init(&config);
xTaskCreatePinnedToCore(&_zh_stats_processing_task, "stats_processing_task", STATS_TASK_STACK_SIZE, NULL, STATS_TASK_PRIORITY, &_zh_stats_task_handle, tskNO_AFFINITY);
break;
default:
break;
}
}
static void _zh_inclinometer_reset_timer_on_alarm_cb(void *arg) static void _zh_inclinometer_reset_timer_on_alarm_cb(void *arg)
{ {
@@ -462,31 +498,53 @@ static void _zh_b_tachometer_processing_task(void *pvParameter)
vTaskDelete(NULL); vTaskDelete(NULL);
} }
#ifdef DEBUG
static void _zh_stats_processing_task(void *pvParameter) static void _zh_stats_processing_task(void *pvParameter)
{ {
const esp_app_desc_t *esp_app_desc = esp_app_get_description();
for (;;) for (;;)
{ {
printf("Tasks:\n"); char buffer[1024] = {0};
printf("A inclinometer task minimum free stack size: %ld.\n", _task_stats.a_inclinometer_task_min_stack_size);
printf("B inclinometer task minimum free stack size: %ld.\n", _task_stats.b_inclinometer_task_min_stack_size);
printf("A tachometer task minimum free stack size: %ld.\n", _task_stats.a_tachometer_task_min_stack_size);
printf("A tachometer task minimum free stack size: %ld.\n", _task_stats.b_tachometer_task_min_stack_size);
printf("Stats task minimum free stack size: %ld.\n", (uint32_t)uxTaskGetStackHighWaterMark(NULL));
printf("Encoders:\n");
const zh_encoder_stats_t *encoder_stats = zh_encoder_get_stats(); const zh_encoder_stats_t *encoder_stats = zh_encoder_get_stats();
printf("Number of event post error: %ld.\n", encoder_stats->event_post_error);
printf("Number of queue overflow error: %ld.\n", encoder_stats->queue_overflow_error);
printf("Minimum free stack size: %ld.\n", encoder_stats->min_stack_size);
printf("Expanders:\n");
const zh_pcf8574_stats_t *pcf8574_stats = zh_pcf8574_get_stats(); const zh_pcf8574_stats_t *pcf8574_stats = zh_pcf8574_get_stats();
printf("Number of i2c driver error: %ld.\n", pcf8574_stats->i2c_driver_error); sprintf(buffer, "A inclinometer task minimum free stack size: %ld.\n", _task_stats.a_inclinometer_task_min_stack_size);
printf("Number of event post error: %ld.\n", pcf8574_stats->event_post_error); zh_syslog_send(ZH_KERN, _task_stats.a_inclinometer_task_min_stack_size > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_inclinometer", buffer);
printf("Number of vector error: %ld.\n", pcf8574_stats->vector_error); vTaskDelay(500 / portTICK_PERIOD_MS);
printf("Number of queue overflow error: %ld.\n", pcf8574_stats->queue_overflow_error); sprintf(buffer, "B inclinometer task minimum free stack size: %ld.\n", _task_stats.b_inclinometer_task_min_stack_size);
printf("Minimum free stack size: %ld.\n", pcf8574_stats->min_stack_size); zh_syslog_send(ZH_KERN, _task_stats.b_inclinometer_task_min_stack_size > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_inclinometer", buffer);
vTaskDelay(10000 / portTICK_PERIOD_MS); vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "A tachometer task minimum free stack size: %ld.\n", _task_stats.b_tachometer_task_min_stack_size);
zh_syslog_send(ZH_KERN, _task_stats.b_tachometer_task_min_stack_size > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_tachometer", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "B tachometer task minimum free stack size: %ld.\n", _task_stats.b_tachometer_task_min_stack_size);
zh_syslog_send(ZH_KERN, _task_stats.b_tachometer_task_min_stack_size > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_tachometer", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Stats task minimum free stack size: %ld.\n", (uint32_t)uxTaskGetStackHighWaterMark(NULL));
zh_syslog_send(ZH_KERN, (uint32_t)uxTaskGetStackHighWaterMark(NULL) > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_syslog", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Encoder task minimum free stack size: %ld.\n", encoder_stats->min_stack_size);
zh_syslog_send(ZH_KERN, encoder_stats->min_stack_size > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_encoder", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Expander task minimum free stack size: %ld.\n", pcf8574_stats->min_stack_size);
zh_syslog_send(ZH_KERN, pcf8574_stats->min_stack_size > 100 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_pcf8574", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Number of event post error: %ld.\n", encoder_stats->event_post_error);
zh_syslog_send(ZH_KERN, encoder_stats->event_post_error == 0 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_encoder", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Number of queue overflow error: %ld.\n", encoder_stats->queue_overflow_error);
zh_syslog_send(ZH_KERN, encoder_stats->queue_overflow_error == 0 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_encoder", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Number of i2c driver error: %ld.\n", pcf8574_stats->i2c_driver_error);
zh_syslog_send(ZH_KERN, pcf8574_stats->i2c_driver_error == 0 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_pcf8574", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Number of event post error: %ld.\n", pcf8574_stats->event_post_error);
zh_syslog_send(ZH_KERN, pcf8574_stats->event_post_error == 0 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_pcf8574", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Number of vector error: %ld.\n", pcf8574_stats->vector_error);
zh_syslog_send(ZH_KERN, pcf8574_stats->vector_error == 0 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_pcf8574", buffer);
vTaskDelay(500 / portTICK_PERIOD_MS);
sprintf(buffer, "Number of queue overflow error: %ld.\n", pcf8574_stats->queue_overflow_error);
zh_syslog_send(ZH_KERN, pcf8574_stats->queue_overflow_error == 0 ? ZH_INFO : ZH_WARNING, esp_app_desc->project_name, "zh_pcf8574", buffer);
vTaskDelay(60000 / portTICK_PERIOD_MS);
} }
vTaskDelete(NULL); vTaskDelete(NULL);
} }
#endif
+12 -5
View File
@@ -13,9 +13,10 @@
#include "zh_tachometer.h" #include "zh_tachometer.h"
#include "zh_ota_server.h" #include "zh_ota_server.h"
#include "zh_espnow.h" #include "zh_espnow.h"
#include "zh_syslog.h"
#define STATS_TASK_PRIORITY tskIDLE_PRIORITY #define STATS_TASK_PRIORITY tskIDLE_PRIORITY
#define STATS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE + 512 #define STATS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE + 1024
#define A_INCLINOMETER_TASK_PRIORITY tskIDLE_PRIORITY + 5 #define A_INCLINOMETER_TASK_PRIORITY tskIDLE_PRIORITY + 5
#define A_INCLINOMETER_TASK_STACK_SIZE configMINIMAL_STACK_SIZE + 512 #define A_INCLINOMETER_TASK_STACK_SIZE configMINIMAL_STACK_SIZE + 512
#define B_INCLINOMETER_TASK_PRIORITY tskIDLE_PRIORITY + 5 #define B_INCLINOMETER_TASK_PRIORITY tskIDLE_PRIORITY + 5
@@ -42,10 +43,16 @@
#define MODE_REMOTE 3 #define MODE_REMOTE 3
#define MAIN_MENU_REMOTE_NAME "REMOTE" #define MAIN_MENU_REMOTE_NAME "REMOTE"
#define WIFI_SSID "ATE0005" #define WIFI_AP_SSID "ATE0005"
#define WIFI_PASS "repairlab" #define WIFI_AP_PASS "repairlab"
#define WIFI_CHANNEL 1 #define WIFI_AP_CHANNEL 1
#define MAX_STA_CONNECTION 4 #define MAX_AP_CONNECTION 4
#define WIFI_STA_SSID "rick_professor"
#define WIFI_STA_PASS "repairlab"
#define WIFI_STA_MAXIMUM_RETRY 10
#define SYSLOG_IP "77.51.201.8"
#define I2C_SCL_GPIO GPIO_NUM_22 #define I2C_SCL_GPIO GPIO_NUM_22
#define I2C_SDA_GPIO GPIO_NUM_21 #define I2C_SDA_GPIO GPIO_NUM_21
+1 -1
View File
@@ -1 +1 @@
1.0.0 1.1.0