Version 2.0.0

Added ESP32 - C2/C3/C6/S2/S3 support.
Added ESP-NOW v2.0 support.
Removed zh_network support.
Removed external sensor support.
Improved stability of work.
This commit is contained in:
2025-01-26 11:51:51 +03:00
parent 02ec02edcc
commit 80d3c9953c
25 changed files with 185 additions and 497 deletions

View File

@ -8,34 +8,30 @@
#include "driver/gpio.h"
#include "esp_timer.h"
#include "esp_ota_ops.h"
#include "zh_ds18b20.h"
#include "zh_dht.h"
#include "zh_config.h"
#ifdef CONFIG_NETWORK_TYPE_DIRECT
#include "zh_espnow.h"
#define zh_send_message(a, b, c) zh_espnow_send(a, b, c)
#define ZH_EVENT ZH_ESPNOW
#else
#include "zh_network.h"
#define zh_send_message(a, b, c) zh_network_send(a, b, c)
#define ZH_EVENT ZH_NETWORK
#endif
#include "zh_config.h"
#ifdef CONFIG_IDF_TARGET_ESP8266
#define ZH_CHIP_TYPE HACHT_ESP8266
// #define ZH_CPU_FREQUENCY CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ;
#elif CONFIG_IDF_TARGET_ESP32
#define ZH_CHIP_TYPE HACHT_ESP32
// #define ZH_CPU_FREQUENCY CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
#elif CONFIG_IDF_TARGET_ESP32S2
#define ZH_CHIP_TYPE HACHT_ESP32S2
// #define ZH_CPU_FREQUENCY CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
#elif CONFIG_IDF_TARGET_ESP32S3
#define ZH_CHIP_TYPE HACHT_ESP32S3
// #define ZH_CPU_FREQUENCY CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
#elif CONFIG_IDF_TARGET_ESP32C2
#define ZH_CHIP_TYPE HACHT_ESP32C2
// #define ZH_CPU_FREQUENCY CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
#elif CONFIG_IDF_TARGET_ESP32C3
#define ZH_CHIP_TYPE HACHT_ESP32C3
// #define ZH_CPU_FREQUENCY CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
#elif CONFIG_IDF_TARGET_ESP32C6
#define ZH_CHIP_TYPE HACHT_ESP32C6
// #define ZH_CPU_FREQUENCY CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
#endif
#ifdef CONFIG_IDF_TARGET_ESP8266
@ -48,42 +44,34 @@
#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_TASK_PRIORITY 10 // Prioritize the task of GPIO processing.
#define ZH_GPIO_STACK_SIZE 2048 // The stack size of the task of GPIO processing.
#define ZH_MESSAGE_TASK_PRIORITY 2 // Prioritize the task of sending messages to the gateway.
#define ZH_MESSAGE_TASK_PRIORITY 5 // Prioritize the task of sending messages to the gateway.
#define ZH_MESSAGE_STACK_SIZE 2048 // The stack size of the task of sending messages to the gateway.
typedef struct // Structure of data exchange between tasks, functions and event handlers.
{
struct // Storage structure of switch hardware configuration data.
{
uint8_t relay_pin; // Relay GPIO number.
bool relay_on_level; // Relay ON level. @note HIGH (true) / LOW (false).
uint8_t led_pin; // Led GPIO number (if present).
bool led_on_level; // Led ON level (if present). @note HIGH (true) / LOW (false).
uint8_t int_button_pin; // Internal button GPIO number (if present).
bool int_button_on_level; // Internal button trigger level (if present). @note HIGH (true) / LOW (false).
uint8_t ext_button_pin; // External button GPIO number (if present).
bool ext_button_on_level; // External button trigger level (if present). @note HIGH (true) / LOW (false).
uint8_t sensor_pin; // Sensor GPIO number (if present).
ha_sensor_type_t sensor_type; // Sensor types (if present). @note Used to identify the sensor type by ESP-NOW gateway and send the appropriate sensor status messages to MQTT.
uint16_t measurement_frequency; // Sensor measurement frequency (if present).
uint8_t relay_pin; // Relay GPIO number.
bool relay_on_level; // Relay ON level. @note HIGH (true) / LOW (false).
uint8_t led_pin; // Led GPIO number (if present).
bool led_on_level; // Led ON level (if present). @note HIGH (true) / LOW (false).
uint8_t int_button_pin; // Internal button GPIO number (if present).
bool int_button_on_level; // Internal button trigger level (if present). @note HIGH (true) / LOW (false).
uint8_t ext_button_pin; // External button GPIO number (if present).
bool ext_button_on_level; // External button trigger level (if present). @note HIGH (true) / LOW (false).
} hardware_config;
struct // Storage structure of switch status data.
{
ha_on_off_type_t status; // Status of the zh_espnow_switch. @note Example - ON / OFF. @attention Must be same with set on switch_config_message structure.
ha_on_off_type_t status; // Status of the zh_espnow_switch. @note Example - ON / OFF. @attention Must be same with set on switch_config_message structure (zh_config).
} status;
volatile bool gpio_processing; // GPIO processing flag. @note Used to prevent a repeated interrupt from triggering during GPIO processing.
volatile bool gateway_is_available; // Gateway availability status flag. @note Used to control the tasks when the gateway connection is established / lost.
volatile bool is_first_connection; // First connection status flag. @note Used to control the tasks when the gateway connection is established / lost.
uint8_t gateway_mac[6]; // Gateway MAC address.
TaskHandle_t switch_attributes_message_task; // Unique task handle for zh_send_switsh_attributes_message_task().
TaskHandle_t switch_keep_alive_message_task; // Unique task handle for zh_send_switch_keep_alive_message_task().
TaskHandle_t sensor_attributes_message_task; // Unique task handle for zh_send_sensor_attributes_message_task().
TaskHandle_t sensor_status_message_task; // Unique task handle for zh_send_sensor_status_message_task().
SemaphoreHandle_t button_pushing_semaphore; // Unique semaphore handle for GPIO processing tasks.
const esp_partition_t *update_partition; // Next update partition.
esp_ota_handle_t update_handle; // Unique OTA handle.
@ -181,27 +169,6 @@ void zh_send_switch_keep_alive_message_task(void *pvParameter);
*/
void zh_send_switch_status_message(const switch_config_t *switch_config);
/**
* @brief Function for prepare the sensor configuration message and sending it to the gateway.
*
* @param[in] switch_config Pointer to the structure of data exchange between tasks, functions and event handlers.
*/
void zh_send_sensor_config_message(const switch_config_t *switch_config);
/**
* @brief Task for prepare the sensor attributes message and sending it to the gateway.
*
* @param[in] pvParameter Pointer to structure of data exchange between tasks, functions and event handlers.
*/
void zh_send_sensor_attributes_message_task(void *pvParameter);
/**
* @brief Task for prepare the sensor status message and sending it to the gateway.
*
* @param[in] pvParameter Pointer to the structure of data exchange between tasks, functions and event handlers.
*/
void zh_send_sensor_status_message_task(void *pvParameter);
/**
* @brief Function for ESP-NOW event processing.
*