Version 1.0.0

Initial version.
This commit is contained in:
2023-11-25 15:00:37 +03:00
parent ea2600c453
commit fad96e95f1
19 changed files with 53 additions and 42 deletions

0
main/component.mk Normal file
View File

View File

@ -53,9 +53,6 @@ void app_main(void)
#elif CONFIG_SENSOR_TYPE_DOOR
s_sensor_type = HAST_DOOR;
#endif
const esp_partition_t *running = esp_ota_get_running_partition();
esp_ota_img_states_t ota_state = {0};
esp_ota_get_state_partition(running, &ota_state);
nvs_flash_init();
esp_netif_init();
esp_event_loop_create_default();
@ -67,15 +64,10 @@ void app_main(void)
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B);
zh_espnow_init_config_t zh_espnow_init_config = ZH_ESPNOW_INIT_CONFIG_DEFAULT();
zh_espnow_init(&zh_espnow_init_config);
esp_event_handler_instance_register(ZH_ESPNOW, ESP_EVENT_ANY_ID, &s_zh_espnow_event_handler, NULL, NULL);
xTaskCreatePinnedToCore(&s_zh_uart_processing_task, "s_zh_uart_processing_tack", ZH_UART_STACK_SIZE, NULL, ZH_UART_TASK_PRIORITY, NULL, tskNO_AFFINITY);
esp_event_handler_register(ZH_ESPNOW, ESP_EVENT_ANY_ID, &s_zh_espnow_event_handler, NULL);
xTaskCreate(&s_zh_uart_processing_task, "s_zh_uart_processing_tack", ZH_UART_STACK_SIZE, NULL, ZH_UART_TASK_PRIORITY, NULL);
s_zh_send_sensor_config_message();
s_zh_send_sensor_attributes_message();
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY)
{
vTaskDelay(100 / portTICK_PERIOD_MS);
esp_ota_mark_app_valid_cancel_rollback();
}
}
static void s_zh_uart_processing_task(void *pvParameter)
@ -86,11 +78,9 @@ static void s_zh_uart_processing_task(void *pvParameter)
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_DEFAULT,
};
uart_driver_install(ZH_UART_NUM, ZH_UART_BUFF_SIZE, ZH_UART_BUFF_SIZE, ZH_UART_QUEUE_SIZE, &s_zh_uart_queue, 0);
uart_param_config(ZH_UART_NUM, &uart_config);
uart_set_pin(ZH_UART_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uint8_t *data = (uint8_t *)calloc(1, ZH_UART_BUFF_SIZE);
uart_event_t event = {0};
uart_write_bytes(ZH_UART_NUM, &s_initial_message, sizeof(s_initial_message));
@ -203,11 +193,11 @@ static void s_zh_save_status(void)
static void s_zh_send_sensor_attributes_message(void)
{
const esp_app_desc_t *app_info = esp_app_get_description();
const esp_app_desc_t *app_info = esp_ota_get_app_description();
zh_attributes_message_t attributes_message = {0};
attributes_message.chip_type = HACHT_ESP32;
attributes_message.chip_type = HACHT_ESP8266;
strcpy(attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
attributes_message.cpu_frequency = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
attributes_message.cpu_frequency = CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ;
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);
@ -265,12 +255,12 @@ static void s_zh_send_sensor_status_message(void)
static void s_zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
const esp_app_desc_t *app_info = esp_app_get_description();
const esp_app_desc_t *app_info = esp_ota_get_app_description();
zh_espnow_data_t data_in = {0};
zh_espnow_data_t data_out = {0};
zh_espnow_ota_message_t espnow_ota_message = {0};
data_out.device_type = ZHDT_BINARY_SENSOR;
espnow_ota_message.chip_type = HACHT_ESP32;
espnow_ota_message.chip_type = HACHT_ESP8266;
data_out.payload_data = (zh_payload_data_t)espnow_ota_message;
switch (event_id)
{
@ -293,7 +283,10 @@ static void s_zh_espnow_event_handler(void *arg, esp_event_base_t event_base, in
{
case ZHPT_UPDATE:
s_update_partition = esp_ota_get_next_update_partition(NULL);
strcpy(espnow_ota_message.app_name, app_info->project_name);
char *app_name = (char *)calloc(1, strlen(app_info->project_name) + 5 + 1);
sprintf(app_name, "%s.app%d", app_info->project_name, s_update_partition->subtype - ESP_PARTITION_SUBTYPE_APP_OTA_0 + 1);
strcpy(espnow_ota_message.app_name, app_name);
free(app_name);
strcpy(espnow_ota_message.app_version, app_info->version);
data_out.payload_type = ZHPT_UPDATE;
data_out.payload_data = (zh_payload_data_t)espnow_ota_message;