Version 1.0.0
Initial version.
@ -1,3 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(zh_espnow_open_sensor_esp32)
|
||||
project(zh_espnow_open_sensor_esp8266)
|
3
Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
PROJECT_NAME := zh_espnow_open_sensor_esp8266
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
17
README.md
@ -1,6 +1,6 @@
|
||||
# ESP-NOW open/close sensor
|
||||
|
||||
ESP-NOW based open/close sensor for ESP32 ESP-IDF. Alternate firmware for Tuya/SmartLife/eWeLink WiFi sensors.
|
||||
ESP-NOW based open/close sensor ESP8266 RTOS SDK. Alternate firmware for Tuya/SmartLife/eWeLink WiFi sensors.
|
||||
|
||||
There are two branches - for ESP8266 family and for ESP32 family. Please use the appropriate one.
|
||||
|
||||
@ -12,7 +12,7 @@ There are two branches - for ESP8266 family and for ESP32 family. Please use the
|
||||
## Notes
|
||||
|
||||
1. For initial settings use "menuconfig -> ZH ESP-NOW Open Sensor Configuration". After first boot all settings will be stored in NVS memory for prevente change during OTA firmware update.
|
||||
2. To update the sensor firmware, press the button for > 5 seconds and send the "update" command to the root topic of the sensor (example - "homeassistant/espnow_sensor/70-03-9F-44-BE-F7"). The update path should be like as "https://your_server/zh_espnow_open_sensor_esp32.bin". The time and success of the update depends on the load on WiFi channel 1. Average update time is less than one minute. The online status of the update is displayed in the root sensor topic.
|
||||
2. To update the sensor firmware, press the button for > 5 seconds and send the "update" command to the root topic of the sensor (example - "homeassistant/espnow_sensor/70-03-9F-44-BE-F7"). The update paths should be like as "https://your_server/zh_espnow_open_sensor_esp8266.app1.bin + https://your_server/zh_espnow_open_sensor_esp8266.app2.bin". The time and success of the update depends on the load on WiFi channel 1. Average update time is less than one minute. The online status of the update is displayed in the root sensor topic.
|
||||
|
||||
## Build and flash
|
||||
|
||||
@ -22,13 +22,18 @@ Run the following command to firmware build and flash module:
|
||||
cd your_projects_folder
|
||||
bash <(curl -Ls http://git.zh.com.ru/alexey.zholtikov/zh_espnow_open_sensor/raw/branch/esp8266/install.sh)
|
||||
cd zh_espnow_open_sensor
|
||||
idf.py menuconfig
|
||||
idf.py all
|
||||
idf.py -p (PORT) flash
|
||||
make menuconfig
|
||||
make
|
||||
make flash
|
||||
```
|
||||
|
||||
## Tested on
|
||||
|
||||
See [here](http://git.zh.com.ru/alexey.zholtikov/zh_espnow_open_sensor/src/branch/esp8266/hardware).
|
||||
|
||||
## Attention
|
||||
|
||||
1. A gateway is required. For details see [zh_gateway](http://git.zh.com.ru/alexey.zholtikov/zh_gateway).
|
||||
2. Highly recommended connect an external power supply during firmware update.
|
||||
3. Because this sensor is battery operated, it has an additional controller (MCU) that controls the power of the WiFi module (Module) and transmits data to it for transmission to the network. The communication is done via UART at 9600 speed. Make sure that the protocol is correct before flashing. Details [here](http://git.zh.com.ru/alexey.zholtikov/zh_espnow_open_sensor/src/branch/esp32/doc).
|
||||
3. Because this sensor is battery operated, it has an additional controller (MCU) that controls the power of the WiFi module (Module) and transmits data to it for transmission to the network. The communication is done via UART at 9600 speed. Make sure that the protocol is correct before flashing. Details [here](http://git.zh.com.ru/alexey.zholtikov/zh_espnow_open_sensor/src/branch/esp8266/doc).
|
||||
4. Use the "make ota" command instead of "make" to prepare 2 bin files for OTA update.
|
BIN
hardware/MODEL_D06_TYPE_1/TYWE3S.pdf
Normal file
BIN
hardware/MODEL_D06_TYPE_1/inside1.jpeg
Normal file
After Width: | Height: | Size: 2.2 MiB |
BIN
hardware/MODEL_D06_TYPE_1/inside2.jpeg
Normal file
After Width: | Height: | Size: 2.1 MiB |
BIN
hardware/MODEL_D06_TYPE_1/main.jpeg
Normal file
After Width: | Height: | Size: 2.1 MiB |
BIN
hardware/MODEL_D06_TYPE_2/CBU.pdf
Normal file
BIN
hardware/MODEL_D06_TYPE_2/ESP-M2.pdf
Normal file
BIN
hardware/MODEL_D06_TYPE_2/inside1.jpeg
Normal file
After Width: | Height: | Size: 2.3 MiB |
BIN
hardware/MODEL_D06_TYPE_2/inside2.jpeg
Normal file
After Width: | Height: | Size: 2.3 MiB |
BIN
hardware/MODEL_D06_TYPE_2/inside3.jpeg
Normal file
After Width: | Height: | Size: 2.3 MiB |
BIN
hardware/MODEL_D06_TYPE_2/inside4.jpeg
Normal file
After Width: | Height: | Size: 2.2 MiB |
BIN
hardware/MODEL_D06_TYPE_2/main.jpeg
Normal file
After Width: | Height: | Size: 2.1 MiB |
5
hardware/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Tested on
|
||||
|
||||
1. MODEL D06 TYPE 1. Built on Tuya WiFi module TYWE3S (ESP8266 chip). Replacement not required. Total triggering time about 1.5 sec. [Photo](https://github.com/aZholtikov/ESP-NOW-Window-Door-Sensor/tree/main/hardware/Model_D06_Type_1).
|
||||
|
||||
2. MODEL D06 TYPE 2. Built on Tuya WiFi module CBU (BK7231N chip). Replacement with ESP-M2 (ESP8285 chip). Total response time about 0.5 sec. [Photo](https://github.com/aZholtikov/ESP-NOW-Window-Door-Sensor/tree/main/hardware/Model_D06_Type_2).
|
0
main/component.mk
Normal 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;
|
||||
|
@ -1,7 +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,
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
|
||||
nvs, data, nvs, 0x9000, 0x4000
|
||||
otadata, data, ota, 0xd000, 0x2000
|
||||
phy_init, data, phy, 0xf000, 0x1000
|
||||
ota_0, 0, ota_0, 0x10000, 0x70000
|
||||
ota_1, 0, ota_1, 0x80000, 0x70000
|
||||
|
|
@ -1,18 +1,23 @@
|
||||
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_LOG_BOOTLOADER_LEVEL_NONE=y
|
||||
CONFIG_LOG_BOOTLOADER_LEVEL=0
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y
|
||||
CONFIG_ESPTOOLPY_FLASHMODE="dout"
|
||||
CONFIG_SPI_FLASH_MODE=0x3
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="1MB"
|
||||
CONFIG_SPI_FLASH_SIZE=0x100000
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y
|
||||
|
||||
CONFIG_ESP8266_DEFAULT_CPU_FREQ_80=y
|
||||
CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ=80
|
||||
|
||||
CONFIG_ESP_PANIC_SILENT_REBOOT=y
|
||||
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|