Added offline message
This commit is contained in:
parent
c848b2121f
commit
f04dc554db
@ -505,8 +505,8 @@ void zh_send_sensor_status_message_task(void *pvParameter)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
data.payload_type = ZHPT_ERROR;
|
data.payload_type = ZHPT_ERROR;
|
||||||
char *message = (char *)heap_caps_malloc(151, MALLOC_CAP_8BIT);
|
char *message = (char *)heap_caps_malloc(150, MALLOC_CAP_8BIT);
|
||||||
memset(message, 0, 151);
|
memset(message, 0, 150);
|
||||||
sprintf(message, "Sensor %s reading error. Error - %s.", zh_get_sensor_type_value_name(switch_config->hardware_config.sensor_type), esp_err_to_name(err));
|
sprintf(message, "Sensor %s reading error. Error - %s.", zh_get_sensor_type_value_name(switch_config->hardware_config.sensor_type), esp_err_to_name(err));
|
||||||
strcpy(data.payload_data.status_message.error_message.message, message);
|
strcpy(data.payload_data.status_message.error_message.message, 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));
|
||||||
@ -555,13 +555,30 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
{
|
{
|
||||||
zh_send_switch_config_message(switch_config);
|
zh_send_switch_config_message(switch_config);
|
||||||
zh_send_switch_status_message(switch_config);
|
zh_send_switch_status_message(switch_config);
|
||||||
xTaskCreatePinnedToCore(&zh_send_switch_attributes_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->switch_attributes_message_task, tskNO_AFFINITY);
|
if (switch_config->is_first_connection == false)
|
||||||
xTaskCreatePinnedToCore(&zh_send_switch_keep_alive_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->switch_keep_alive_message_task, tskNO_AFFINITY);
|
{
|
||||||
|
xTaskCreatePinnedToCore(&zh_send_switch_attributes_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->switch_attributes_message_task, tskNO_AFFINITY);
|
||||||
|
xTaskCreatePinnedToCore(&zh_send_switch_keep_alive_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->switch_keep_alive_message_task, tskNO_AFFINITY);
|
||||||
|
switch_config->is_first_connection = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vTaskResume(switch_config->switch_attributes_message_task);
|
||||||
|
vTaskResume(switch_config->switch_keep_alive_message_task);
|
||||||
|
}
|
||||||
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
||||||
{
|
{
|
||||||
zh_send_sensor_config_message(switch_config);
|
zh_send_sensor_config_message(switch_config);
|
||||||
xTaskCreatePinnedToCore(&zh_send_sensor_status_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->sensor_status_message_task, tskNO_AFFINITY);
|
if (switch_config->is_first_connection == false)
|
||||||
xTaskCreatePinnedToCore(&zh_send_sensor_attributes_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->sensor_attributes_message_task, tskNO_AFFINITY);
|
{
|
||||||
|
xTaskCreatePinnedToCore(&zh_send_sensor_status_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->sensor_status_message_task, tskNO_AFFINITY);
|
||||||
|
xTaskCreatePinnedToCore(&zh_send_sensor_attributes_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, switch_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&switch_config->sensor_attributes_message_task, tskNO_AFFINITY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vTaskResume(switch_config->sensor_status_message_task);
|
||||||
|
vTaskResume(switch_config->sensor_attributes_message_task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -573,12 +590,12 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
switch_config->gateway_is_available = false;
|
switch_config->gateway_is_available = false;
|
||||||
if (switch_config->hardware_config.relay_pin != ZH_NOT_USED)
|
if (switch_config->hardware_config.relay_pin != ZH_NOT_USED)
|
||||||
{
|
{
|
||||||
vTaskDelete(switch_config->switch_attributes_message_task);
|
vTaskSuspend(switch_config->switch_attributes_message_task);
|
||||||
vTaskDelete(switch_config->switch_keep_alive_message_task);
|
vTaskSuspend(switch_config->switch_keep_alive_message_task);
|
||||||
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
||||||
{
|
{
|
||||||
vTaskDelete(switch_config->sensor_attributes_message_task);
|
vTaskSuspend(switch_config->sensor_attributes_message_task);
|
||||||
vTaskDelete(switch_config->sensor_status_message_task);
|
vTaskSuspend(switch_config->sensor_status_message_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,6 +619,12 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
switch_config->hardware_config.sensor_pin = 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_pin;
|
||||||
switch_config->hardware_config.sensor_type = data->payload_data.config_message.switch_hardware_config_message.sensor_type;
|
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);
|
||||||
|
data->device_type = ZHDT_SWITCH;
|
||||||
|
data->payload_type = ZHPT_KEEP_ALIVE;
|
||||||
|
data->payload_data.keep_alive_message.online_status = ZH_OFFLINE;
|
||||||
|
data->payload_data.keep_alive_message.message_frequency = ZH_SWITCH_KEEP_ALIVE_MESSAGE_FREQUENCY;
|
||||||
|
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
esp_restart();
|
esp_restart();
|
||||||
break;
|
break;
|
||||||
case ZHPT_UPDATE:;
|
case ZHPT_UPDATE:;
|
||||||
@ -657,10 +680,20 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
data->device_type = ZHDT_SWITCH;
|
data->device_type = ZHDT_SWITCH;
|
||||||
data->payload_type = ZHPT_UPDATE_SUCCESS;
|
data->payload_type = ZHPT_UPDATE_SUCCESS;
|
||||||
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));
|
||||||
|
data->payload_type = ZHPT_KEEP_ALIVE;
|
||||||
|
data->payload_data.keep_alive_message.online_status = ZH_OFFLINE;
|
||||||
|
data->payload_data.keep_alive_message.message_frequency = ZH_SWITCH_KEEP_ALIVE_MESSAGE_FREQUENCY;
|
||||||
|
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
esp_restart();
|
esp_restart();
|
||||||
break;
|
break;
|
||||||
case ZHPT_RESTART:
|
case ZHPT_RESTART:
|
||||||
|
data->device_type = ZHDT_SWITCH;
|
||||||
|
data->payload_type = ZHPT_KEEP_ALIVE;
|
||||||
|
data->payload_data.keep_alive_message.online_status = ZH_OFFLINE;
|
||||||
|
data->payload_data.keep_alive_message.message_frequency = ZH_SWITCH_KEEP_ALIVE_MESSAGE_FREQUENCY;
|
||||||
|
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
esp_restart();
|
esp_restart();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -681,12 +714,12 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
switch_config->gateway_is_available = false;
|
switch_config->gateway_is_available = false;
|
||||||
if (switch_config->hardware_config.relay_pin != ZH_NOT_USED)
|
if (switch_config->hardware_config.relay_pin != ZH_NOT_USED)
|
||||||
{
|
{
|
||||||
vTaskDelete(switch_config->switch_attributes_message_task);
|
vTaskSuspend(switch_config->switch_attributes_message_task);
|
||||||
vTaskDelete(switch_config->switch_keep_alive_message_task);
|
vTaskSuspend(switch_config->switch_keep_alive_message_task);
|
||||||
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
||||||
{
|
{
|
||||||
vTaskDelete(switch_config->sensor_attributes_message_task);
|
vTaskSuspend(switch_config->sensor_attributes_message_task);
|
||||||
vTaskDelete(switch_config->sensor_status_message_task);
|
vTaskSuspend(switch_config->sensor_status_message_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -702,12 +735,12 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
switch_config->gateway_is_available = false;
|
switch_config->gateway_is_available = false;
|
||||||
if (switch_config->hardware_config.relay_pin != ZH_NOT_USED)
|
if (switch_config->hardware_config.relay_pin != ZH_NOT_USED)
|
||||||
{
|
{
|
||||||
vTaskDelete(switch_config->switch_attributes_message_task);
|
vTaskSuspend(switch_config->switch_attributes_message_task);
|
||||||
vTaskDelete(switch_config->switch_keep_alive_message_task);
|
vTaskSuspend(switch_config->switch_keep_alive_message_task);
|
||||||
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
if (switch_config->hardware_config.sensor_pin != ZH_NOT_USED && switch_config->hardware_config.sensor_type != HAST_NONE)
|
||||||
{
|
{
|
||||||
vTaskDelete(switch_config->sensor_attributes_message_task);
|
vTaskSuspend(switch_config->sensor_attributes_message_task);
|
||||||
vTaskDelete(switch_config->sensor_status_message_task);
|
vTaskSuspend(switch_config->sensor_status_message_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ typedef struct // Structure of data exchange between tasks, functions and event
|
|||||||
} status;
|
} status;
|
||||||
volatile bool gpio_processing; // GPIO processing flag. @note Used to prevent a repeated interrupt from triggering during GPIO processing.
|
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 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.
|
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_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 switch_keep_alive_message_task; // Unique task handle for zh_send_switch_keep_alive_message_task().
|
||||||
|
@ -1 +1 @@
|
|||||||
1.0.4-1
|
1.0.4-2
|
Loading…
x
Reference in New Issue
Block a user