From 44bc1d4977dcbca415975ce33ddd12281d23105f Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Fri, 19 Jul 2024 13:03:47 +0300 Subject: [PATCH] Added multiple attempts to read the sensor --- main/zh_espnow_switch.c | 7 +++++++ main/zh_espnow_switch.h | 1 + 2 files changed, 8 insertions(+) diff --git a/main/zh_espnow_switch.c b/main/zh_espnow_switch.c index 2e2784a..c9840c0 100644 --- a/main/zh_espnow_switch.c +++ b/main/zh_espnow_switch.c @@ -484,6 +484,8 @@ void zh_send_sensor_status_message_task(void *pvParameter) data.device_type = ZHDT_SENSOR; for (;;) { + uint8_t attempts = 0; + READ_SENSOR: esp_err_t err = ESP_OK; switch (switch_config->hardware_config.sensor_type) { @@ -515,6 +517,11 @@ void zh_send_sensor_status_message_task(void *pvParameter) } else { + if (++attempts < ZH_SENSOR_READ_MAXIMUM_RETRY) + { + vTaskDelay(1000 / portTICK_PERIOD_MS); + goto READ_SENSOR; + } data.payload_type = ZHPT_ERROR; char *message = (char *)heap_caps_malloc(150, MALLOC_CAP_8BIT); memset(message, 0, 150); diff --git a/main/zh_espnow_switch.h b/main/zh_espnow_switch.h index 8a81e0a..87e01c3 100644 --- a/main/zh_espnow_switch.h +++ b/main/zh_espnow_switch.h @@ -49,6 +49,7 @@ #define ZH_SWITCH_KEEP_ALIVE_MESSAGE_FREQUENCY 10 // Frequency of sending a switch keep alive message to the gateway (in seconds). #define ZH_SWITCH_ATTRIBUTES_MESSAGE_FREQUENCY 60 // Frequency of sending a switch attributes message to the gateway (in seconds). #define ZH_SENSOR_ATTRIBUTES_MESSAGE_FREQUENCY 60 // Frequency of sending a sensor attributes message to the gateway (in seconds). +#define ZH_SENSOR_READ_MAXIMUM_RETRY 5 // Maximum number of read sensor attempts. #define ZH_GPIO_TASK_PRIORITY 3 // Prioritize the task of GPIO processing. #define ZH_GPIO_STACK_SIZE 2048 // The stack size of the task of GPIO processing.