Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
603b407df4 | |||
049463f648 | |||
d40bb7d52e | |||
7a34b9c25a | |||
c8007ade5d |
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -1,9 +1,3 @@
|
||||
[submodule "components/zh_network"]
|
||||
path = components/zh_network
|
||||
url = https://github.com/aZholtikov/zh_network
|
||||
[submodule "components/zh_vector"]
|
||||
path = components/zh_vector
|
||||
url = https://github.com/aZholtikov/zh_vector
|
||||
[submodule "components/zh_espnow"]
|
||||
path = components/zh_espnow
|
||||
url = https://github.com/aZholtikov/zh_espnow
|
||||
|
15
README.md
15
README.md
@ -1,27 +1,24 @@
|
||||
# ESP-NOW led
|
||||
|
||||
ESP-NOW based led controller/light for ESP32 ESP-IDF and ESP8266 RTOS SDK. Alternate firmware for Tuya/SmartLife/eWeLink WiFi led controllers/lights.
|
||||
ESP-NOW based led controller/light for ESP32 ESP-IDF and ESP8266 RTOS_SDK. Alternate firmware for Tuya/SmartLife/eWeLink WiFi led controllers/lights.
|
||||
|
||||
## Tested on
|
||||
|
||||
1. ESP8266 RTOS_SDK v3.4
|
||||
2. ESP32 ESP-IDF v5.2
|
||||
2. ESP32 ESP-IDF v5.4
|
||||
|
||||
## Features
|
||||
|
||||
1. Saves the last state when the power is turned off.
|
||||
2. Automatically adds led configuration to Home Assistan via MQTT discovery as a light.
|
||||
3. Update firmware from HTTPS server via ESP-NOW.
|
||||
4. Direct or mesh work mode.
|
||||
|
||||
## Notes
|
||||
|
||||
1. Work mode must be same with [gateway](https://github.com/aZholtikov/zh_gateway) work mode.
|
||||
2. ESP-NOW mesh network based on the [zh_network](https://github.com/aZholtikov/zh_network).
|
||||
3. For initial settings use "menuconfig -> ZH ESP-NOW Led Configuration". After first boot all settings will be stored in NVS memory for prevente change during OTA firmware update.
|
||||
4. To restart the led, send the "restart" command to the root topic of the led (example - "homeassistant/espnow_led/24-62-AB-F9-1F-A8").
|
||||
5. To update the led firmware, send the "update" command to the root topic of the led (example - "homeassistant/espnow_led/70-03-9F-44-BE-F7"). The update path should be like as "https://your_server/zh_espnow_led_esp32.bin" (for ESP32) or "https://your_server/zh_espnow_led_esp8266.app1.bin + https://your_server/zh_espnow_led_esp8266.app2.bin" (for ESP8266). The time and success of the update depends on the load on WiFi channel 1. Average update time is up to five minutes. The online status of the update will be displayed in the root led topic.
|
||||
6. To change initial settings of the led (except work mode), send the X1,X2,X3,X4,X5,X6 command to the hardware topic of the led (example - "homeassistant/espnow_led/70-03-9F-44-BE-F7/hardware"). The configuration will only be accepted if it does not cause errors. The current configuration status is displayed in the configuration topic of the led (example - "homeassistant/espnow_led/70-03-9F-44-BE-F7/config").
|
||||
1. For initial settings use "menuconfig -> ZH ESP-NOW Led Configuration". After first boot all settings will be stored in NVS memory for prevente change during OTA firmware update.
|
||||
2. To restart the led, send the "restart" command to the root topic of the led (example - "homeassistant/espnow_led/24-62-AB-F9-1F-A8").
|
||||
3. To update the led firmware, send the "update" command to the root topic of the led (example - "homeassistant/espnow_led/70-03-9F-44-BE-F7"). The update path should be like as "https://your_server/zh_espnow_led_esp32.bin" (for ESP32) or "https://your_server/zh_espnow_led_esp8266.app1.bin + https://your_server/zh_espnow_led_esp8266.app2.bin" (for ESP8266). Average update time is up to one minute. The status of the update will be displayed in the root led topic.
|
||||
4. To change initial settings of the led (except work mode), send the X1,X2,X3,X4,X5,X6 command to the hardware topic of the led (example - "homeassistant/espnow_led/70-03-9F-44-BE-F7/hardware"). The configuration will only be accepted if it does not cause errors. The current configuration status is displayed in the configuration topic of the led (example - "homeassistant/espnow_led/70-03-9F-44-BE-F7/config").
|
||||
|
||||
MQTT configuration message should filled according to the template "X1,X2,X3,X4,X5,X6". Where:
|
||||
|
||||
|
Submodule components/zh_config updated: c568d84e56...73e8a70f4f
Submodule components/zh_espnow updated: 742c807c41...af7fa204e1
Submodule components/zh_network deleted from 783b44fbca
Submodule components/zh_vector deleted from 53cdc76873
@ -9,17 +9,6 @@ menu "ZH ESP-NOW Led Configuration"
|
||||
default 18 if IDF_TARGET_ESP32C2
|
||||
default 19 if IDF_TARGET_ESP32C3
|
||||
default 30 if IDF_TARGET_ESP32C6
|
||||
|
||||
choice NETWORK_TYPE
|
||||
prompt "Network type"
|
||||
help
|
||||
Network type.
|
||||
default NETWORK_TYPE_DIRECT
|
||||
config NETWORK_TYPE_DIRECT
|
||||
bool "DIRECT"
|
||||
config NETWORK_TYPE_MESH
|
||||
bool "MESH"
|
||||
endchoice
|
||||
|
||||
choice LED_TYPE
|
||||
prompt "Led type"
|
||||
|
@ -15,19 +15,13 @@ void app_main(void)
|
||||
wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&wifi_init_config);
|
||||
esp_wifi_set_mode(WIFI_MODE_STA);
|
||||
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B);
|
||||
esp_wifi_start();
|
||||
#ifdef CONFIG_NETWORK_TYPE_DIRECT
|
||||
zh_espnow_init_config_t espnow_init_config = ZH_ESPNOW_INIT_CONFIG_DEFAULT();
|
||||
zh_espnow_init(&espnow_init_config);
|
||||
#else
|
||||
zh_network_init_config_t network_init_config = ZH_NETWORK_INIT_CONFIG_DEFAULT();
|
||||
zh_network_init(&network_init_config);
|
||||
#endif
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
esp_event_handler_register(ZH_EVENT, ESP_EVENT_ANY_ID, &zh_espnow_event_handler, led_config);
|
||||
esp_event_handler_register(ZH_ESPNOW, ESP_EVENT_ANY_ID, &zh_espnow_event_handler, led_config);
|
||||
#else
|
||||
esp_event_handler_instance_register(ZH_EVENT, ESP_EVENT_ANY_ID, &zh_espnow_event_handler, led_config, NULL);
|
||||
esp_event_handler_instance_register(ZH_ESPNOW, ESP_EVENT_ANY_ID, &zh_espnow_event_handler, led_config, NULL);
|
||||
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);
|
||||
@ -46,8 +40,8 @@ void zh_load_config(led_config_t *led_config)
|
||||
uint8_t config_is_present = 0;
|
||||
if (nvs_get_u8(nvs_handle, "present", &config_is_present) == ESP_ERR_NVS_NOT_FOUND)
|
||||
{
|
||||
nvs_set_u8(nvs_handle, "present", 0xFE);
|
||||
nvs_close(nvs_handle);
|
||||
SETUP_INITIAL_SETTINGS:
|
||||
#ifdef CONFIG_LED_TYPE_W
|
||||
led_config->hardware_config.led_type = HALT_W;
|
||||
#elif CONFIG_LED_TYPE_WW
|
||||
@ -89,19 +83,25 @@ void zh_load_config(led_config_t *led_config)
|
||||
zh_save_config(led_config);
|
||||
return;
|
||||
}
|
||||
nvs_get_u8(nvs_handle, "led_type", (uint8_t *)&led_config->hardware_config.led_type);
|
||||
nvs_get_u8(nvs_handle, "frs_white_pin", &led_config->hardware_config.first_white_pin);
|
||||
nvs_get_u8(nvs_handle, "sec_white_pin", &led_config->hardware_config.second_white_pin);
|
||||
nvs_get_u8(nvs_handle, "red_pin", &led_config->hardware_config.red_pin);
|
||||
nvs_get_u8(nvs_handle, "green_pin", &led_config->hardware_config.green_pin);
|
||||
nvs_get_u8(nvs_handle, "blue_pin", &led_config->hardware_config.blue_pin);
|
||||
esp_err_t err = ESP_OK;
|
||||
err += nvs_get_u8(nvs_handle, "led_type", (uint8_t *)&led_config->hardware_config.led_type);
|
||||
err += nvs_get_u8(nvs_handle, "frs_white_pin", &led_config->hardware_config.first_white_pin);
|
||||
err += nvs_get_u8(nvs_handle, "sec_white_pin", &led_config->hardware_config.second_white_pin);
|
||||
err += nvs_get_u8(nvs_handle, "red_pin", &led_config->hardware_config.red_pin);
|
||||
err += nvs_get_u8(nvs_handle, "green_pin", &led_config->hardware_config.green_pin);
|
||||
err += nvs_get_u8(nvs_handle, "blue_pin", &led_config->hardware_config.blue_pin);
|
||||
nvs_close(nvs_handle);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
goto SETUP_INITIAL_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
void zh_save_config(const led_config_t *led_config)
|
||||
{
|
||||
nvs_handle_t nvs_handle = 0;
|
||||
nvs_open("config", NVS_READWRITE, &nvs_handle);
|
||||
nvs_set_u8(nvs_handle, "present", 0xFE);
|
||||
nvs_set_u8(nvs_handle, "led_type", led_config->hardware_config.led_type);
|
||||
nvs_set_u8(nvs_handle, "frs_white_pin", led_config->hardware_config.first_white_pin);
|
||||
nvs_set_u8(nvs_handle, "sec_white_pin", led_config->hardware_config.second_white_pin);
|
||||
@ -120,16 +120,13 @@ void zh_load_status(led_config_t *led_config)
|
||||
uint8_t status_is_present = 0;
|
||||
if (nvs_get_u8(nvs_handle, "present", &status_is_present) == ESP_ERR_NVS_NOT_FOUND)
|
||||
{
|
||||
nvs_set_u8(nvs_handle, "present", 0xFE);
|
||||
nvs_close(nvs_handle);
|
||||
zh_save_status(led_config);
|
||||
return;
|
||||
}
|
||||
nvs_get_u8(nvs_handle, "led_state", (uint8_t *)&led_config->status.status);
|
||||
nvs_get_u8(nvs_handle, "bright_state", &led_config->status.brightness);
|
||||
uint16_t temperature = 0;
|
||||
nvs_get_u16(nvs_handle, "temp_state", &temperature); // Just to prevent a compiler warning.
|
||||
led_config->status.temperature = temperature;
|
||||
nvs_get_u16(nvs_handle, "temp_state", &led_config->status.temperature);
|
||||
nvs_get_u8(nvs_handle, "red_state", &led_config->status.red);
|
||||
nvs_get_u8(nvs_handle, "green_state", &led_config->status.green);
|
||||
nvs_get_u8(nvs_handle, "blue_state", &led_config->status.blue);
|
||||
@ -141,6 +138,7 @@ void zh_save_status(const led_config_t *led_config)
|
||||
{
|
||||
nvs_handle_t nvs_handle = 0;
|
||||
nvs_open("status", NVS_READWRITE, &nvs_handle);
|
||||
nvs_set_u8(nvs_handle, "present", 0xFE);
|
||||
nvs_set_u8(nvs_handle, "led_state", led_config->status.status);
|
||||
nvs_set_u8(nvs_handle, "bright_state", led_config->status.brightness);
|
||||
nvs_set_u16(nvs_handle, "temp_state", led_config->status.temperature);
|
||||
@ -421,14 +419,15 @@ void zh_send_led_attributes_message_task(void *pvParameter)
|
||||
data.payload_data.attributes_message.heap_size = esp_get_free_heap_size();
|
||||
data.payload_data.attributes_message.min_heap_size = esp_get_minimum_free_heap_size();
|
||||
data.payload_data.attributes_message.uptime = esp_timer_get_time() / 1000000;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(ZH_LED_ATTRIBUTES_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void zh_send_led_config_message(const led_config_t *led_config)
|
||||
void zh_send_led_config_message_task(void *pvParameter)
|
||||
{
|
||||
led_config_t *led_config = pvParameter;
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_LED;
|
||||
data.payload_type = ZHPT_CONFIG;
|
||||
@ -440,11 +439,17 @@ void zh_send_led_config_message(const led_config_t *led_config)
|
||||
data.payload_data.config_message.led_config_message.optimistic = false;
|
||||
data.payload_data.config_message.led_config_message.qos = 2;
|
||||
data.payload_data.config_message.led_config_message.retain = true;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
for (;;)
|
||||
{
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(ZH_LED_CONFIG_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void zh_send_led_hardware_config_message(const led_config_t *led_config)
|
||||
void zh_send_led_hardware_config_message_task(void *pvParameter)
|
||||
{
|
||||
led_config_t *led_config = pvParameter;
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_LED;
|
||||
data.payload_type = ZHPT_HARDWARE;
|
||||
@ -454,7 +459,12 @@ void zh_send_led_hardware_config_message(const led_config_t *led_config)
|
||||
data.payload_data.config_message.led_hardware_config_message.red_pin = led_config->hardware_config.red_pin;
|
||||
data.payload_data.config_message.led_hardware_config_message.green_pin = led_config->hardware_config.green_pin;
|
||||
data.payload_data.config_message.led_hardware_config_message.blue_pin = led_config->hardware_config.blue_pin;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
for (;;)
|
||||
{
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(ZH_LED_HARDWARE_CONFIG_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void zh_send_led_keep_alive_message_task(void *pvParameter)
|
||||
@ -467,12 +477,33 @@ void zh_send_led_keep_alive_message_task(void *pvParameter)
|
||||
data.payload_data.keep_alive_message.message_frequency = ZH_LED_KEEP_ALIVE_MESSAGE_FREQUENCY;
|
||||
for (;;)
|
||||
{
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(ZH_LED_KEEP_ALIVE_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void zh_send_led_status_message_task(void *pvParameter)
|
||||
{
|
||||
led_config_t *led_config = pvParameter;
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_LED;
|
||||
data.payload_type = ZHPT_STATE;
|
||||
for (;;)
|
||||
{
|
||||
data.payload_data.status_message.led_status_message.status = led_config->status.status;
|
||||
data.payload_data.status_message.led_status_message.brightness = led_config->status.brightness;
|
||||
data.payload_data.status_message.led_status_message.temperature = led_config->status.temperature;
|
||||
data.payload_data.status_message.led_status_message.red = led_config->status.red;
|
||||
data.payload_data.status_message.led_status_message.green = led_config->status.green;
|
||||
data.payload_data.status_message.led_status_message.blue = led_config->status.blue;
|
||||
data.payload_data.status_message.led_status_message.effect = led_config->status.effect;
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(ZH_LED_STATUS_MESSAGE_FREQUENCY * 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void zh_send_led_status_message(const led_config_t *led_config)
|
||||
{
|
||||
zh_espnow_data_t data = {0};
|
||||
@ -485,7 +516,7 @@ void zh_send_led_status_message(const led_config_t *led_config)
|
||||
data.payload_data.status_message.led_status_message.green = led_config->status.green;
|
||||
data.payload_data.status_message.led_status_message.blue = led_config->status.blue;
|
||||
data.payload_data.status_message.led_status_message.effect = led_config->status.effect;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
}
|
||||
|
||||
void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
@ -493,21 +524,12 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
led_config_t *led_config = arg;
|
||||
switch (event_id)
|
||||
{
|
||||
#ifdef CONFIG_NETWORK_TYPE_DIRECT
|
||||
case ZH_ESPNOW_ON_RECV_EVENT:;
|
||||
zh_espnow_event_on_recv_t *recv_data = event_data;
|
||||
if (recv_data->data_len != sizeof(zh_espnow_data_t))
|
||||
{
|
||||
goto ZH_ESPNOW_EVENT_HANDLER_EXIT;
|
||||
}
|
||||
#else
|
||||
case ZH_NETWORK_ON_RECV_EVENT:;
|
||||
zh_network_event_on_recv_t *recv_data = event_data;
|
||||
if (recv_data->data_len != sizeof(zh_espnow_data_t))
|
||||
{
|
||||
goto ZH_NETWORK_EVENT_HANDLER_EXIT;
|
||||
}
|
||||
#endif
|
||||
zh_espnow_data_t *data = (zh_espnow_data_t *)recv_data->data;
|
||||
switch (data->device_type)
|
||||
{
|
||||
@ -515,33 +537,15 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
switch (data->payload_type)
|
||||
{
|
||||
case ZHPT_KEEP_ALIVE:
|
||||
if (data->payload_data.keep_alive_message.online_status == ZH_ONLINE)
|
||||
memcpy(led_config->gateway_mac, recv_data->mac_addr, 6);
|
||||
if (is_first_boot == false)
|
||||
{
|
||||
if (led_config->gateway_is_available == false)
|
||||
{
|
||||
led_config->gateway_is_available = true;
|
||||
memcpy(led_config->gateway_mac, recv_data->mac_addr, 6);
|
||||
zh_send_led_hardware_config_message(led_config);
|
||||
if (led_config->hardware_config.led_type != HALT_NONE)
|
||||
{
|
||||
zh_send_led_config_message(led_config);
|
||||
zh_send_led_status_message(led_config);
|
||||
xTaskCreatePinnedToCore(&zh_send_led_attributes_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&led_config->attributes_message_task, tskNO_AFFINITY);
|
||||
xTaskCreatePinnedToCore(&zh_send_led_keep_alive_message_task, "NULL", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, (TaskHandle_t *)&led_config->keep_alive_message_task, tskNO_AFFINITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (led_config->gateway_is_available == true)
|
||||
{
|
||||
led_config->gateway_is_available = false;
|
||||
if (led_config->hardware_config.led_type != HALT_NONE)
|
||||
{
|
||||
vTaskDelete(led_config->attributes_message_task);
|
||||
vTaskDelete(led_config->keep_alive_message_task);
|
||||
}
|
||||
}
|
||||
is_first_boot = true;
|
||||
xTaskCreatePinnedToCore(&zh_send_led_attributes_message_task, "led_attributes_message_task", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, NULL, tskNO_AFFINITY);
|
||||
xTaskCreatePinnedToCore(&zh_send_led_keep_alive_message_task, "led_keep_alive_message_task", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, NULL, tskNO_AFFINITY);
|
||||
xTaskCreatePinnedToCore(&zh_send_led_config_message_task, "led_config_message_task", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, NULL, tskNO_AFFINITY);
|
||||
xTaskCreatePinnedToCore(&zh_send_led_hardware_config_message_task, "led_hardware_config_message_task", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, NULL, tskNO_AFFINITY);
|
||||
xTaskCreatePinnedToCore(&zh_send_led_status_message_task, "led_status_message_task", ZH_MESSAGE_STACK_SIZE, led_config, ZH_MESSAGE_TASK_PRIORITY, NULL, tskNO_AFFINITY);
|
||||
}
|
||||
break;
|
||||
case ZHPT_SET:
|
||||
@ -593,9 +597,8 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
#else
|
||||
strcpy(data->payload_data.ota_message.espnow_ota_data.app_name, app_info->project_name);
|
||||
#endif
|
||||
data->device_type = ZHDT_LED;
|
||||
data->payload_type = ZHPT_UPDATE;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
case ZHPT_UPDATE_BEGIN:
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
@ -606,7 +609,7 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
led_config->ota_message_part_number = 1;
|
||||
data->device_type = ZHDT_LED;
|
||||
data->payload_type = ZHPT_UPDATE_PROGRESS;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
case ZHPT_UPDATE_PROGRESS:
|
||||
if (led_config->ota_message_part_number == data->payload_data.ota_message.espnow_ota_message.part)
|
||||
@ -616,7 +619,7 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
}
|
||||
data->device_type = ZHDT_LED;
|
||||
data->payload_type = ZHPT_UPDATE_PROGRESS;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
case ZHPT_UPDATE_ERROR:
|
||||
esp_ota_end(led_config->update_handle);
|
||||
@ -626,13 +629,13 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
{
|
||||
data->device_type = ZHDT_LED;
|
||||
data->payload_type = ZHPT_UPDATE_FAIL;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
}
|
||||
esp_ota_set_boot_partition(led_config->update_partition);
|
||||
data->device_type = ZHDT_LED;
|
||||
data->payload_type = ZHPT_UPDATE_SUCCESS;
|
||||
zh_send_message(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
zh_espnow_send(led_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
break;
|
||||
@ -646,39 +649,11 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#ifdef CONFIG_NETWORK_TYPE_DIRECT
|
||||
ZH_ESPNOW_EVENT_HANDLER_EXIT:
|
||||
heap_caps_free(recv_data->data);
|
||||
break;
|
||||
case ZH_ESPNOW_ON_SEND_EVENT:;
|
||||
zh_espnow_event_on_send_t *send_data = event_data;
|
||||
if (send_data->status == ZH_ESPNOW_SEND_FAIL && led_config->gateway_is_available == true)
|
||||
{
|
||||
led_config->gateway_is_available = false;
|
||||
if (led_config->hardware_config.led_type != HALT_NONE)
|
||||
{
|
||||
vTaskDelete(led_config->attributes_message_task);
|
||||
vTaskDelete(led_config->keep_alive_message_task);
|
||||
}
|
||||
}
|
||||
case ZH_ESPNOW_ON_SEND_EVENT:
|
||||
break;
|
||||
#else
|
||||
ZH_NETWORK_EVENT_HANDLER_EXIT:
|
||||
heap_caps_free(recv_data->data);
|
||||
break;
|
||||
case ZH_NETWORK_ON_SEND_EVENT:;
|
||||
zh_network_event_on_send_t *send_data = event_data;
|
||||
if (send_data->status == ZH_NETWORK_SEND_FAIL && led_config->gateway_is_available == true)
|
||||
{
|
||||
led_config->gateway_is_available = false;
|
||||
if (led_config->hardware_config.led_type != HALT_NONE)
|
||||
{
|
||||
vTaskDelete(led_config->attributes_message_task);
|
||||
vTaskDelete(led_config->keep_alive_message_task);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -9,17 +9,8 @@
|
||||
#include "driver/ledc.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_ota_ops.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
|
||||
@ -45,12 +36,17 @@
|
||||
#define get_app_description() esp_app_get_description()
|
||||
#endif
|
||||
|
||||
#define ZH_LED_KEEP_ALIVE_MESSAGE_FREQUENCY 10 // Frequency of sending a led keep alive message to the gateway (in seconds).
|
||||
#define ZH_LED_ATTRIBUTES_MESSAGE_FREQUENCY 60 // Frequency of sending a led attributes message to the gateway (in seconds).
|
||||
#define ZH_LED_KEEP_ALIVE_MESSAGE_FREQUENCY 10 // Frequency of sending a led keep alive message to the gateway (in seconds).
|
||||
#define ZH_LED_ATTRIBUTES_MESSAGE_FREQUENCY 60 // Frequency of sending a led attributes message to the gateway (in seconds).
|
||||
#define ZH_LED_HARDWARE_CONFIG_MESSAGE_FREQUENCY 60 // Frequency of sending a led hardware config message to the gateway (in seconds).
|
||||
#define ZH_LED_CONFIG_MESSAGE_FREQUENCY 60 // Frequency of sending a led config message to the gateway (in seconds).
|
||||
#define ZH_LED_STATUS_MESSAGE_FREQUENCY 60 // Frequency of sending a led status message to the gateway (in seconds).
|
||||
|
||||
#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.
|
||||
|
||||
static bool is_first_boot = false;
|
||||
|
||||
typedef struct // Structure of data exchange between tasks, functions and event handlers.
|
||||
{
|
||||
struct // Storage structure of led hardware configuration data.
|
||||
@ -80,10 +76,7 @@ typedef struct // Structure of data exchange between tasks, functions and event
|
||||
uint8_t green; // Green color channel.
|
||||
uint8_t blue; // Blue color channel.
|
||||
} channel;
|
||||
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.
|
||||
TaskHandle_t attributes_message_task; // Unique task handle for zh_send_led_attributes_message_task().
|
||||
TaskHandle_t keep_alive_message_task; // Unique task handle for zh_send_led_keep_alive_message_task().
|
||||
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.
|
||||
@ -147,23 +140,23 @@ int32_t zh_map(int32_t value, int32_t in_min, int32_t in_max, int32_t out_min, i
|
||||
/**
|
||||
* @brief Task for prepare the led attributes message and sending it to the gateway.
|
||||
*
|
||||
* @param[in,out] pvParameter Pointer to structure of data exchange between tasks, functions and event handlers.
|
||||
* @param[in] pvParameter Pointer to structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_send_led_attributes_message_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief Function for prepare the led configuration message and sending it to the gateway.
|
||||
* @brief Task for prepare the led configuration message and sending it to the gateway.
|
||||
*
|
||||
* @param[in] led_config Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
* @param[in] pvParameter Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_send_led_config_message(const led_config_t *led_config);
|
||||
void zh_send_led_config_message_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief Function for prepare the led hardware configuration message and sending it to the gateway.
|
||||
* @brief Task for prepare the led hardware configuration message and sending it to the gateway.
|
||||
*
|
||||
* @param[in] led_config Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
* @param[in] pvParameter Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_send_led_hardware_config_message(const led_config_t *led_config);
|
||||
void zh_send_led_hardware_config_message_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief Task for prepare the led keep alive message and sending it to the gateway.
|
||||
@ -172,6 +165,13 @@ void zh_send_led_hardware_config_message(const led_config_t *led_config);
|
||||
*/
|
||||
void zh_send_led_keep_alive_message_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief Task for prepare the sled 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_led_status_message_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief Function for prepare the led status message and sending it to the gateway.
|
||||
*
|
||||
|
7
partitions_esp32c2.csv
Normal file
7
partitions_esp32c2.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, , 0x4000,
|
||||
otadata, data, ota, , 0x2000,
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, , 900K,
|
||||
ota_1, app, ota_1, , 900K,
|
|
7
partitions_esp32c3.csv
Normal file
7
partitions_esp32c3.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, , 0x4000,
|
||||
otadata, data, ota, , 0x2000,
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, , 1500K,
|
||||
ota_1, app, ota_1, , 1500K,
|
|
7
partitions_esp32c6.csv
Normal file
7
partitions_esp32c6.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, , 0x4000,
|
||||
otadata, data, ota, , 0x2000,
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, , 1500K,
|
||||
ota_1, app, ota_1, , 1500K,
|
|
7
partitions_esp32s2.csv
Normal file
7
partitions_esp32s2.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, , 0x4000,
|
||||
otadata, data, ota, , 0x2000,
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, , 1500K,
|
||||
ota_1, app, ota_1, , 1500K,
|
|
7
partitions_esp32s3.csv
Normal file
7
partitions_esp32s3.csv
Normal file
@ -0,0 +1,7 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, , 0x4000,
|
||||
otadata, data, ota, , 0x2000,
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, , 1500K,
|
||||
ota_1, app, ota_1, , 1500K,
|
|
18
sdkconfig.defaults.esp32c2
Normal file
18
sdkconfig.defaults.esp32c2
Normal file
@ -0,0 +1,18 @@
|
||||
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
|
||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32c2.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_esp32c2.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
18
sdkconfig.defaults.esp32c3
Normal file
18
sdkconfig.defaults.esp32c3
Normal file
@ -0,0 +1,18 @@
|
||||
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
|
||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32c3.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_esp32c3.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
18
sdkconfig.defaults.esp32c6
Normal file
18
sdkconfig.defaults.esp32c6
Normal file
@ -0,0 +1,18 @@
|
||||
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
|
||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32c6.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_esp32c6.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
18
sdkconfig.defaults.esp32s2
Normal file
18
sdkconfig.defaults.esp32s2
Normal file
@ -0,0 +1,18 @@
|
||||
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
|
||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32s2.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_esp32s2.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
18
sdkconfig.defaults.esp32s3
Normal file
18
sdkconfig.defaults.esp32s3
Normal file
@ -0,0 +1,18 @@
|
||||
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x1000
|
||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_esp32s3.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_esp32s3.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
@ -1 +1 @@
|
||||
1.0.2
|
||||
2.1.0
|
Reference in New Issue
Block a user