Changed main code to support the new major version of zh_config

This commit is contained in:
2024-06-06 13:34:30 +03:00
parent 9a9ab53d28
commit 09baf9769e
2 changed files with 105 additions and 101 deletions

View File

@ -312,22 +312,20 @@ void zh_send_switch_attributes_message_task(void *pvParameter)
{ {
switch_config_t *switch_config = pvParameter; switch_config_t *switch_config = pvParameter;
const esp_app_desc_t *app_info = get_app_description(); const esp_app_desc_t *app_info = get_app_description();
zh_attributes_message_t attributes_message = {0};
attributes_message.chip_type = ZH_CHIP_TYPE;
strcpy(attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
attributes_message.cpu_frequency = ZH_CPU_FREQUENCY;
attributes_message.reset_reason = (uint8_t)esp_reset_reason();
strcpy(attributes_message.app_name, app_info->project_name);
strcpy(attributes_message.app_version, app_info->version);
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_ATTRIBUTES; data.payload_type = ZHPT_ATTRIBUTES;
data.payload_data.attributes_message.chip_type = ZH_CHIP_TYPE;
strcpy(data.payload_data.attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
data.payload_data.attributes_message.cpu_frequency = ZH_CPU_FREQUENCY;
data.payload_data.attributes_message.reset_reason = (uint8_t)esp_reset_reason();
strcpy(data.payload_data.attributes_message.app_name, app_info->project_name);
strcpy(data.payload_data.attributes_message.app_version, app_info->version);
for (;;) for (;;)
{ {
attributes_message.heap_size = esp_get_free_heap_size(); data.payload_data.attributes_message.heap_size = esp_get_free_heap_size();
attributes_message.min_heap_size = esp_get_minimum_free_heap_size(); data.payload_data.attributes_message.min_heap_size = esp_get_minimum_free_heap_size();
attributes_message.uptime = esp_timer_get_time() / 1000000; data.payload_data.attributes_message.uptime = esp_timer_get_time() / 1000000;
data.payload_data = (zh_payload_data_t)attributes_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
vTaskDelay(ZH_SWITCH_ATTRIBUTES_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS); vTaskDelay(ZH_SWITCH_ATTRIBUTES_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
} }
@ -336,45 +334,46 @@ void zh_send_switch_attributes_message_task(void *pvParameter)
void zh_send_switch_config_message(const switch_config_t *switch_config) void zh_send_switch_config_message(const switch_config_t *switch_config)
{ {
zh_switch_config_message_t switch_config_message = {0};
switch_config_message.unique_id = 1;
switch_config_message.device_class = HASWDC_SWITCH;
switch_config_message.payload_on = HAONOFT_ON;
switch_config_message.payload_off = HAONOFT_OFF;
switch_config_message.enabled_by_default = true;
switch_config_message.optimistic = false;
switch_config_message.qos = 2;
switch_config_message.retain = true;
zh_config_message_t config_message = {0};
config_message = (zh_config_message_t)switch_config_message;
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_CONFIG; data.payload_type = ZHPT_CONFIG;
data.payload_data = (zh_payload_data_t)config_message; data.payload_data.config_message.switch_config_message.unique_id = 1;
data.payload_data.config_message.switch_config_message.device_class = HASWDC_SWITCH;
data.payload_data.config_message.switch_config_message.payload_on = HAONOFT_ON;
data.payload_data.config_message.switch_config_message.payload_off = HAONOFT_OFF;
data.payload_data.config_message.switch_config_message.enabled_by_default = true;
data.payload_data.config_message.switch_config_message.optimistic = false;
data.payload_data.config_message.switch_config_message.qos = 2;
data.payload_data.config_message.switch_config_message.retain = true;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
} }
void zh_send_switch_hardware_config_message(const switch_config_t *switch_config) void zh_send_switch_hardware_config_message(const switch_config_t *switch_config)
{ {
zh_config_message_t config_message = {0};
config_message = (zh_config_message_t)switch_config->hardware_config;
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_HARDWARE; data.payload_type = ZHPT_HARDWARE;
data.payload_data = (zh_payload_data_t)config_message; data.payload_data.config_message.switch_hardware_config_message.relay_pin = switch_config->hardware_config.relay_pin;
data.payload_data.config_message.switch_hardware_config_message.relay_on_level = switch_config->hardware_config.relay_on_level;
data.payload_data.config_message.switch_hardware_config_message.led_pin = switch_config->hardware_config.led_pin;
data.payload_data.config_message.switch_hardware_config_message.led_on_level = switch_config->hardware_config.led_on_level;
data.payload_data.config_message.switch_hardware_config_message.int_button_pin = switch_config->hardware_config.int_button_pin;
data.payload_data.config_message.switch_hardware_config_message.int_button_on_level = switch_config->hardware_config.int_button_on_level;
data.payload_data.config_message.switch_hardware_config_message.ext_button_pin = switch_config->hardware_config.ext_button_pin;
data.payload_data.config_message.switch_hardware_config_message.ext_button_on_level = switch_config->hardware_config.ext_button_on_level;
data.payload_data.config_message.switch_hardware_config_message.sensor_pin = switch_config->hardware_config.sensor_pin;
data.payload_data.config_message.switch_hardware_config_message.sensor_type = switch_config->hardware_config.sensor_type;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
} }
void zh_send_switch_keep_alive_message_task(void *pvParameter) void zh_send_switch_keep_alive_message_task(void *pvParameter)
{ {
switch_config_t *switch_config = pvParameter; switch_config_t *switch_config = pvParameter;
zh_keep_alive_message_t keep_alive_message = {0};
keep_alive_message.online_status = ZH_ONLINE;
keep_alive_message.message_frequency = ZH_SWITCH_KEEP_ALIVE_MESSAGE_FREQUENCY;
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_KEEP_ALIVE; data.payload_type = ZHPT_KEEP_ALIVE;
data.payload_data = (zh_payload_data_t)keep_alive_message; data.payload_data.keep_alive_message.online_status = ZH_ONLINE;
data.payload_data.keep_alive_message.message_frequency = ZH_SWITCH_KEEP_ALIVE_MESSAGE_FREQUENCY;
for (;;) for (;;)
{ {
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
@ -385,12 +384,10 @@ void zh_send_switch_keep_alive_message_task(void *pvParameter)
void zh_send_switch_status_message(const switch_config_t *switch_config) void zh_send_switch_status_message(const switch_config_t *switch_config)
{ {
zh_status_message_t status_message = {0};
status_message = (zh_status_message_t)switch_config->status;
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_STATE; data.payload_type = ZHPT_STATE;
data.payload_data = (zh_payload_data_t)status_message; data.payload_data.status_message.switch_status_message.status = switch_config->status.status;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
} }
@ -399,41 +396,33 @@ void zh_send_sensor_config_message(const switch_config_t *switch_config)
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SENSOR; data.device_type = ZHDT_SENSOR;
data.payload_type = ZHPT_CONFIG; data.payload_type = ZHPT_CONFIG;
zh_config_message_t config_message = {0}; data.payload_data.config_message.sensor_config_message.suggested_display_precision = 1;
zh_sensor_config_message_t sensor_config_message = {0}; data.payload_data.config_message.sensor_config_message.expire_after = ZH_SENSOR_STATUS_MESSAGE_FREQUENCY * 3;
sensor_config_message.suggested_display_precision = 1; data.payload_data.config_message.sensor_config_message.enabled_by_default = true;
sensor_config_message.expire_after = ZH_SENSOR_STATUS_MESSAGE_FREQUENCY * 3; data.payload_data.config_message.sensor_config_message.force_update = true;
sensor_config_message.enabled_by_default = true; data.payload_data.config_message.sensor_config_message.qos = 2;
sensor_config_message.force_update = true; data.payload_data.config_message.sensor_config_message.retain = true;
sensor_config_message.qos = 2; char *unit_of_measurement = NULL;
sensor_config_message.retain = true;
char *unit_of_measurement;
switch (switch_config->hardware_config.sensor_type) switch (switch_config->hardware_config.sensor_type)
{ {
case HAST_DS18B20:; case HAST_DS18B20:;
sensor_config_message.unique_id = 2; data.payload_data.config_message.sensor_config_message.unique_id = 2;
sensor_config_message.sensor_device_class = HASDC_TEMPERATURE; data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
unit_of_measurement = "°C"; unit_of_measurement = "°C";
strcpy(sensor_config_message.unit_of_measurement, unit_of_measurement); strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
config_message = (zh_config_message_t)sensor_config_message;
data.payload_data = (zh_payload_data_t)config_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
break; break;
case HAST_DHT11:; case HAST_DHT11:;
case HAST_DHT22:; case HAST_DHT22:;
sensor_config_message.unique_id = 2; data.payload_data.config_message.sensor_config_message.unique_id = 2;
sensor_config_message.sensor_device_class = HASDC_TEMPERATURE; data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
unit_of_measurement = "°C"; unit_of_measurement = "°C";
strcpy(sensor_config_message.unit_of_measurement, unit_of_measurement); strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
config_message = (zh_config_message_t)sensor_config_message;
data.payload_data = (zh_payload_data_t)config_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
sensor_config_message.unique_id = 3; data.payload_data.config_message.sensor_config_message.unique_id = 3;
sensor_config_message.sensor_device_class = HASDC_HUMIDITY; data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_HUMIDITY;
unit_of_measurement = "%"; unit_of_measurement = "%";
strcpy(sensor_config_message.unit_of_measurement, unit_of_measurement); strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
config_message = (zh_config_message_t)sensor_config_message;
data.payload_data = (zh_payload_data_t)config_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
break; break;
default: default:
@ -445,23 +434,21 @@ void zh_send_sensor_attributes_message_task(void *pvParameter)
{ {
switch_config_t *switch_config = pvParameter; switch_config_t *switch_config = pvParameter;
const esp_app_desc_t *app_info = get_app_description(); const esp_app_desc_t *app_info = get_app_description();
zh_attributes_message_t attributes_message = {0};
attributes_message.chip_type = ZH_CHIP_TYPE;
attributes_message.sensor_type = switch_config->hardware_config.sensor_type;
strcpy(attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
attributes_message.cpu_frequency = ZH_CPU_FREQUENCY;
attributes_message.reset_reason = (uint8_t)esp_reset_reason();
strcpy(attributes_message.app_name, app_info->project_name);
strcpy(attributes_message.app_version, app_info->version);
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SENSOR; data.device_type = ZHDT_SENSOR;
data.payload_type = ZHPT_ATTRIBUTES; data.payload_type = ZHPT_ATTRIBUTES;
data.payload_data.attributes_message.chip_type = ZH_CHIP_TYPE;
data.payload_data.attributes_message.sensor_type = switch_config->hardware_config.sensor_type;
strcpy(data.payload_data.attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
data.payload_data.attributes_message.cpu_frequency = ZH_CPU_FREQUENCY;
data.payload_data.attributes_message.reset_reason = (uint8_t)esp_reset_reason();
strcpy(data.payload_data.attributes_message.app_name, app_info->project_name);
strcpy(data.payload_data.attributes_message.app_version, app_info->version);
for (;;) for (;;)
{ {
attributes_message.heap_size = esp_get_free_heap_size(); data.payload_data.attributes_message.heap_size = esp_get_free_heap_size();
attributes_message.min_heap_size = esp_get_minimum_free_heap_size(); data.payload_data.attributes_message.min_heap_size = esp_get_minimum_free_heap_size();
attributes_message.uptime = esp_timer_get_time() / 1000000; data.payload_data.attributes_message.uptime = esp_timer_get_time() / 1000000;
data.payload_data = (zh_payload_data_t)attributes_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
vTaskDelay(ZH_SENSOR_ATTRIBUTES_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS); vTaskDelay(ZH_SENSOR_ATTRIBUTES_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
} }
@ -473,12 +460,10 @@ void zh_send_sensor_status_message_task(void *pvParameter)
switch_config_t *switch_config = pvParameter; switch_config_t *switch_config = pvParameter;
float humidity = 0.0; float humidity = 0.0;
float temperature = 0.0; float temperature = 0.0;
zh_sensor_status_message_t sensor_status_message = {0};
sensor_status_message.sensor_type = switch_config->hardware_config.sensor_type;
zh_status_message_t status_message = {0};
zh_espnow_data_t data = {0}; zh_espnow_data_t data = {0};
data.device_type = ZHDT_SENSOR; data.device_type = ZHDT_SENSOR;
data.payload_type = ZHPT_STATE; data.payload_type = ZHPT_STATE;
data.payload_data.status_message.sensor_status_message.sensor_type = switch_config->hardware_config.sensor_type;
for (;;) for (;;)
{ {
switch (switch_config->hardware_config.sensor_type) switch (switch_config->hardware_config.sensor_type)
@ -488,7 +473,7 @@ void zh_send_sensor_status_message_task(void *pvParameter)
switch (zh_ds18b20_read(NULL, &temperature)) switch (zh_ds18b20_read(NULL, &temperature))
{ {
case ESP_OK: case ESP_OK:
sensor_status_message.temperature = temperature; data.payload_data.status_message.sensor_status_message.temperature = temperature;
break; break;
case ESP_FAIL: case ESP_FAIL:
vTaskDelay(10000 / portTICK_PERIOD_MS); vTaskDelay(10000 / portTICK_PERIOD_MS);
@ -508,8 +493,8 @@ void zh_send_sensor_status_message_task(void *pvParameter)
switch (zh_dht_read(&switch_config->dht_handle, &humidity, &temperature)) switch (zh_dht_read(&switch_config->dht_handle, &humidity, &temperature))
{ {
case ESP_OK: case ESP_OK:
sensor_status_message.humidity = humidity; data.payload_data.status_message.sensor_status_message.humidity = humidity;
sensor_status_message.temperature = temperature; data.payload_data.status_message.sensor_status_message.temperature = temperature;
break; break;
case ESP_ERR_INVALID_RESPONSE: case ESP_ERR_INVALID_RESPONSE:
vTaskDelay(10000 / portTICK_PERIOD_MS); vTaskDelay(10000 / portTICK_PERIOD_MS);
@ -530,8 +515,6 @@ void zh_send_sensor_status_message_task(void *pvParameter)
default: default:
break; break;
} }
status_message = (zh_status_message_t)sensor_status_message;
data.payload_data = (zh_payload_data_t)status_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
vTaskDelay(ZH_SENSOR_STATUS_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS); vTaskDelay(ZH_SENSOR_STATUS_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
} }
@ -607,34 +590,40 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
} }
break; break;
case ZHPT_SET: case ZHPT_SET:
switch_config->status = data.payload_data.status_message.switch_status_message; switch_config->status.status = data.payload_data.status_message.switch_status_message.status;
zh_gpio_set_level(switch_config); zh_gpio_set_level(switch_config);
zh_save_status(switch_config); zh_save_status(switch_config);
zh_send_switch_status_message(switch_config); zh_send_switch_status_message(switch_config);
break; break;
case ZHPT_HARDWARE: case ZHPT_HARDWARE:
switch_config->hardware_config = data.payload_data.config_message.switch_hardware_config_message; switch_config->hardware_config.relay_pin = data.payload_data.config_message.switch_hardware_config_message.relay_pin;
switch_config->hardware_config.relay_on_level = data.payload_data.config_message.switch_hardware_config_message.relay_on_level;
switch_config->hardware_config.led_pin = data.payload_data.config_message.switch_hardware_config_message.led_pin;
switch_config->hardware_config.led_on_level = data.payload_data.config_message.switch_hardware_config_message.led_on_level;
switch_config->hardware_config.int_button_pin = data.payload_data.config_message.switch_hardware_config_message.int_button_pin;
switch_config->hardware_config.int_button_on_level = data.payload_data.config_message.switch_hardware_config_message.int_button_on_level;
switch_config->hardware_config.ext_button_pin = data.payload_data.config_message.switch_hardware_config_message.ext_button_pin;
switch_config->hardware_config.ext_button_on_level = data.payload_data.config_message.switch_hardware_config_message.ext_button_on_level;
switch_config->hardware_config.sensor_pin = data.payload_data.config_message.switch_hardware_config_message.sensor_pin;
switch_config->hardware_config.sensor_type = data.payload_data.config_message.switch_hardware_config_message.sensor_type;
zh_save_config(switch_config); zh_save_config(switch_config);
esp_restart(); esp_restart();
break; break;
case ZHPT_UPDATE:; case ZHPT_UPDATE:;
const esp_app_desc_t *app_info = get_app_description(); const esp_app_desc_t *app_info = get_app_description();
switch_config->update_partition = esp_ota_get_next_update_partition(NULL); switch_config->update_partition = esp_ota_get_next_update_partition(NULL);
zh_espnow_ota_message_t espnow_ota_message = {0}; strcpy(data.payload_data.ota_message.espnow_ota_data.app_version, app_info->version);
espnow_ota_message.chip_type = ZH_CHIP_TYPE;
strcpy(espnow_ota_message.app_version, app_info->version);
#ifdef CONFIG_IDF_TARGET_ESP8266 #ifdef CONFIG_IDF_TARGET_ESP8266
char *app_name = (char *)heap_caps_malloc(strlen(app_info->project_name) + 6, MALLOC_CAP_8BIT); char *app_name = (char *)heap_caps_malloc(strlen(app_info->project_name) + 6, MALLOC_CAP_8BIT);
memset(app_name, 0, strlen(app_info->project_name) + 6); memset(app_name, 0, strlen(app_info->project_name) + 6);
sprintf(app_name, "%s.app%d", app_info->project_name, switch_config->update_partition->subtype - ESP_PARTITION_SUBTYPE_APP_OTA_0 + 1); sprintf(app_name, "%s.app%d", app_info->project_name, switch_config->update_partition->subtype - ESP_PARTITION_SUBTYPE_APP_OTA_0 + 1);
strcpy(espnow_ota_message.app_name, app_name); strcpy(data.payload_data.ota_message.espnow_ota_data.app_name, app_name);
heap_caps_free(app_name); heap_caps_free(app_name);
#else #else
strcpy(espnow_ota_message.app_name, app_info->project_name); strcpy(data.payload_data.ota_message.espnow_ota_data.app_name, app_info->project_name);
#endif #endif
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_UPDATE; data.payload_type = ZHPT_UPDATE;
data.payload_data = (zh_payload_data_t)espnow_ota_message;
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
break; break;
case ZHPT_UPDATE_BEGIN: case ZHPT_UPDATE_BEGIN:
@ -649,10 +638,10 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
break; break;
case ZHPT_UPDATE_PROGRESS: case ZHPT_UPDATE_PROGRESS:
if (switch_config->ota_message_part_number == data.payload_data.espnow_ota_message.part) if (switch_config->ota_message_part_number == data.payload_data.ota_message.espnow_ota_message.part)
{ {
++switch_config->ota_message_part_number; ++switch_config->ota_message_part_number;
esp_ota_write(switch_config->update_handle, (const void *)data.payload_data.espnow_ota_message.data, data.payload_data.espnow_ota_message.data_len); esp_ota_write(switch_config->update_handle, (const void *)data.payload_data.ota_message.espnow_ota_message.data, data.payload_data.ota_message.espnow_ota_message.data_len);
} }
data.device_type = ZHDT_SWITCH; data.device_type = ZHDT_SWITCH;
data.payload_type = ZHPT_UPDATE_PROGRESS; data.payload_type = ZHPT_UPDATE_PROGRESS;

View File

@ -58,20 +58,35 @@
typedef struct // Structure of data exchange between tasks, functions and event handlers. typedef struct // Structure of data exchange between tasks, functions and event handlers.
{ {
zh_switch_hardware_config_message_t hardware_config; // Storage structure of switch hardware configuration data. struct // Storage structure of switch hardware configuration data.
zh_switch_status_message_t status; // Storage structure of switch status data. {
volatile bool gpio_processing; // GPIO processing flag. @note Used to prevent a repeated interrupt from triggering during GPIO processing. uint8_t relay_pin; // Relay GPIO number.
volatile bool gateway_is_available; // Gateway availability status flag. @note Used to control the tasks when the gateway connection is established / lost. bool relay_on_level; // Relay ON level. @note HIGH (true) / LOW (false).
uint8_t gateway_mac[6]; // Gateway MAC address. uint8_t led_pin; // Led GPIO number (if present).
zh_dht_handle_t dht_handle; // Unique DTH11/22 sensor handle. bool led_on_level; // Led ON level (if present). @note HIGH (true) / LOW (false).
TaskHandle_t switch_attributes_message_task; // Unique task handle for zh_send_switsh_attributes_message_task(). uint8_t int_button_pin; // Internal button GPIO number (if present).
TaskHandle_t switch_keep_alive_message_task; // Unique task handle for zh_send_switch_keep_alive_message_task(). bool int_button_on_level; // Internal button trigger level (if present). @note HIGH (true) / LOW (false).
TaskHandle_t sensor_attributes_message_task; // Unique task handle for zh_send_sensor_attributes_message_task(). uint8_t ext_button_pin; // External button GPIO number (if present).
TaskHandle_t sensor_status_message_task; // Unique task handle for zh_send_sensor_status_message_task(). bool ext_button_on_level; // External button trigger level (if present). @note HIGH (true) / LOW (false).
SemaphoreHandle_t button_pushing_semaphore; // Unique semaphore handle for GPIO processing tasks. uint8_t sensor_pin; // Sensor GPIO number (if present).
const esp_partition_t *update_partition; // Next update partition. 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.
esp_ota_handle_t update_handle; // Unique OTA handle. } hardware_config;
uint16_t ota_message_part_number; // The sequence number of the firmware upgrade part. @note Used to verify that all parts have been received. 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.
} 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.
uint8_t gateway_mac[6]; // Gateway MAC address.
zh_dht_handle_t dht_handle; // Unique DTH11/22 sensor handle.
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.
uint16_t ota_message_part_number; // The sequence number of the firmware upgrade part. @note Used to verify that all parts have been received.
} switch_config_t; } switch_config_t;
/** /**