Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
cbb6b77f01 | |||
482903cecf | |||
079429fde0 | |||
4baf53970f | |||
c1b89af391 |
@ -12,13 +12,14 @@ Gateway for ESP32 ESP-IDF for data exchange between ESP-NOW devices and MQTT bro
|
||||
2. Automatically adds supported devices configurations to Home Assistan via MQTT discovery.
|
||||
3. Update firmware from HTTPS server via OTA.
|
||||
4. Update firmware of supported devices from HTTPS server via ESP-NOW.
|
||||
5. Direct or mesh work mode.
|
||||
5. LAN or WiFi connection to router.
|
||||
6. Direct or mesh work mode.
|
||||
|
||||
## Notes
|
||||
|
||||
1. All devices on the network must have the same 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 Gateway Configuration".
|
||||
3. For initial settings use "menuconfig -> ZH Gateway Configuration". After first boot all settings (except work mode) will be stored in NVS memory for prevente change during OTA firmware update.
|
||||
4. To restart the gateway, send the "restart" command to the root topic of the gateway (example - "homeassistant/gateway/70-03-9F-44-BE-F7").
|
||||
5. To update the gateway firmware, send the "update" command to the root topic of the gateway (example - "homeassistant/gateway/70-03-9F-44-BE-F7"). The update path should be like as "https://your_server/zh_gateway_esp32.bin". The online status of the update is displayed in the root gateway topic.
|
||||
|
||||
@ -37,7 +38,7 @@ idf.py flash
|
||||
|
||||
## Attention
|
||||
|
||||
1. The program is written for and tested only on [LILYGO T-ETH-Lite ESP32](https://github.com/Xinyuan-LilyGO/LilyGO-T-ETH-Series). To work on another module it will be necessary change ZH_LAN_MODULE_TYPE and ZH_LAN_MODULE_POWER_PIN (for using LAN connection only). No changes are required when using a WiFi connection.
|
||||
1. The program is tested on [LILYGO T-ETH-Lite ESP32](https://github.com/Xinyuan-LilyGO/LilyGO-T-ETH-Series) and [Wireless-Tag WT32-ETH01](https://github.com/ldijkman/WT32-ETH01-LAN-8720-RJ45-). To work on another module it will be necessary change ZH_LAN_MODULE_TYPE and ZH_LAN_MODULE_POWER_PIN (for using LAN connection only). No changes are required when using a WiFi connection.
|
||||
2. If using a WiFi connection, the WiFi router must be set to the same channel as ESP-NOW.
|
||||
3. Only one device can be updated via ESP-NOW at a time. During the device upgrade, there may be delays in the response of others devices on the network.
|
||||
4. The certificate (certificate.pem) must match the upgrade server.
|
||||
|
0
components/zh_config/CMakeLists.txt
Executable file → Normal file
0
components/zh_config/CMakeLists.txt
Executable file → Normal file
0
components/zh_config/LICENSE
Executable file → Normal file
0
components/zh_config/LICENSE
Executable file → Normal file
0
components/zh_config/README.md
Executable file → Normal file
0
components/zh_config/README.md
Executable file → Normal file
0
components/zh_config/component.mk
Executable file → Normal file
0
components/zh_config/component.mk
Executable file → Normal file
507
components/zh_config/include/zh_config.h
Executable file → Normal file
507
components/zh_config/include/zh_config.h
Executable file → Normal file
@ -14,7 +14,7 @@
|
||||
#define ZH_OFFLINE false
|
||||
|
||||
#define ZH_NOT_USED 0xFF
|
||||
//***********************************************************************************//
|
||||
|
||||
#define ZH_DEVICE_TYPE \
|
||||
DF(ZHDT_NONE, "") \
|
||||
DF(ZHDT_GATEWAY, "gateway") \
|
||||
@ -29,15 +29,24 @@
|
||||
DF(ZHDT_BINARY_SENSOR, "espnow_sensor") \
|
||||
DF(ZHDT_MAX, "")
|
||||
|
||||
typedef enum zh_device_type_t
|
||||
typedef enum // Enumeration of device types supported by the ESP-NOW gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
ZH_DEVICE_TYPE
|
||||
#undef DF
|
||||
} zh_device_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration zh_device_type_t value.
|
||||
*
|
||||
* @note Used for identificate device type in MQTT topics (example - "homeassistant/espnow_switch/70-03-9F-44-BE-F7").
|
||||
*
|
||||
* @param[in] value Enumeration value of zh_device_type_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_device_type_value_name(zh_device_type_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define ZH_PAYLOAD_TYPE \
|
||||
DF(ZHPT_NONE, "") \
|
||||
DF(ZHPT_ATTRIBUTES, "attributes") \
|
||||
@ -62,15 +71,24 @@ char *zh_get_device_type_value_name(zh_device_type_t value);
|
||||
DF(ZHPT_HARDWARE, "hardware") \
|
||||
DF(ZHPT_MAX, "")
|
||||
|
||||
typedef enum zh_payload_type_t
|
||||
typedef enum // Enumeration of payload types supported by the ESP-NOW gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
ZH_PAYLOAD_TYPE
|
||||
#undef DF
|
||||
} zh_payload_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration zh_payload_type_t value.
|
||||
*
|
||||
* @note Used for identificate payload type in MQTT topics (example - "homeassistant/espnow_switch/70-03-9F-44-BE-F7/attributes").
|
||||
*
|
||||
* @param[in] value Enumeration value of zh_payload_type_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_payload_type_value_name(zh_payload_type_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_COMPONENT_TYPE \
|
||||
DF(HACT_NONE, "") \
|
||||
DF(HACT_ALARM_CONTROL_PANEL, "alarm_control_panel") \
|
||||
@ -95,15 +113,24 @@ char *zh_get_payload_type_value_name(zh_payload_type_t value);
|
||||
DF(HACT_VACUUM, "vacuum") \
|
||||
DF(HACT_MAX, "")
|
||||
|
||||
typedef enum ha_component_type_t
|
||||
typedef enum // Enumeration of device types supported by the Home Assistant. For details see https://www.home-assistant.io/integrations/mqtt.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_COMPONENT_TYPE
|
||||
#undef DF
|
||||
} ha_component_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_component_type_t value.
|
||||
*
|
||||
* @note Used to prepare a configuration message for Home Assistant MQTT discovery.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_component_type_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_component_type_value_name(ha_component_type_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_BINARY_SENSOR_DEVICE_CLASS \
|
||||
DF(HABSDC_NONE, "") \
|
||||
DF(HABSDC_BATTERY, "battery") \
|
||||
@ -136,15 +163,24 @@ char *zh_get_component_type_value_name(ha_component_type_t value);
|
||||
DF(HABSDC_WINDOW, "window") \
|
||||
DF(HABSDC_MAX, "")
|
||||
|
||||
typedef enum ha_binary_sensor_device_class_t
|
||||
typedef enum // Enumeration of binary sensor types supported by the Home Assistant. For details see https://www.home-assistant.io/integrations/binary_sensor/#device-class.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_BINARY_SENSOR_DEVICE_CLASS
|
||||
#undef DF
|
||||
} ha_binary_sensor_device_class_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_binary_sensor_device_class_t value.
|
||||
*
|
||||
* @note Used to prepare a configuration message for Home Assistant MQTT discovery.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_binary_sensor_device_class_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_binary_sensor_device_class_value_name(ha_binary_sensor_device_class_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_COVER_DEVICE_CLASS \
|
||||
DF(HACDC_NONE, "") \
|
||||
DF(HACDC_AWNING, "awning") \
|
||||
@ -159,15 +195,24 @@ char *zh_get_binary_sensor_device_class_value_name(ha_binary_sensor_device_class
|
||||
DF(HACDC_WINDOW, "window") \
|
||||
DF(HACDC_MAX, "")
|
||||
|
||||
typedef enum ha_cover_device_class_t
|
||||
typedef enum // Enumeration of cover types supported by the Home Assistant. For details see https://www.home-assistant.io/integrations/cover.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_COVER_DEVICE_CLASS
|
||||
#undef DF
|
||||
} ha_cover_device_class_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_cover_device_class_t value.
|
||||
*
|
||||
* @note Used to prepare a configuration message for Home Assistant MQTT discovery.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_cover_device_class_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_cover_device_class_value_name(ha_cover_device_class_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_SENSOR_DEVICE_CLASS \
|
||||
DF(HASDC_NONE, "") \
|
||||
DF(HASDC_APPARENT_POWER, "apparent_power") \
|
||||
@ -212,30 +257,48 @@ char *zh_get_cover_device_class_value_name(ha_cover_device_class_t value);
|
||||
DF(HASDC_WIND_SPEED, "wind_speed") \
|
||||
DF(HASDC_MAX, "")
|
||||
|
||||
typedef enum ha_sensor_device_class_t
|
||||
typedef enum // Enumeration of sensor types supported by the Home Assistant. For details see https://www.home-assistant.io/integrations/sensor.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_SENSOR_DEVICE_CLASS
|
||||
#undef DF
|
||||
} ha_sensor_device_class_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_sensor_device_class_t value.
|
||||
*
|
||||
* @note Used to prepare a configuration message for Home Assistant MQTT discovery.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_sensor_device_class_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_sensor_device_class_value_name(ha_sensor_device_class_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_SWITCH_DEVICE_CLASS \
|
||||
DF(HASWDC_NONE, "") \
|
||||
DF(HASWDC_OUTLET, "outlet") \
|
||||
DF(HASWDC_SWITCH, "switch") \
|
||||
DF(HASWDC_MAX, "")
|
||||
|
||||
typedef enum ha_switch_device_class_t
|
||||
typedef enum // Enumeration of switch types supported by the Home Assistant. For details see https://www.home-assistant.io/integrations/switch.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_SWITCH_DEVICE_CLASS
|
||||
#undef DF
|
||||
} ha_switch_device_class_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_switch_device_class_t value.
|
||||
*
|
||||
* @note Used to prepare a configuration message for Home Assistant MQTT discovery.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_switch_device_class_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_switch_device_class_value_name(ha_switch_device_class_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_ON_OFF_TYPE \
|
||||
DF(HAONOFT_NONE, "") \
|
||||
DF(HAONOFT_ON, "ON") \
|
||||
@ -252,15 +315,24 @@ char *zh_get_switch_device_class_value_name(ha_switch_device_class_t value);
|
||||
DF(HAONOFT_LEAKAGE, "LEAKAGE") \
|
||||
DF(HAONOFT_MAX, "")
|
||||
|
||||
typedef enum ha_on_off_type_t
|
||||
typedef enum // Enumeration of payload_on / payload_off types supported by gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_ON_OFF_TYPE
|
||||
#undef DF
|
||||
} ha_on_off_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_on_off_type_t value.
|
||||
*
|
||||
* @note Used to prepare a configuration message for Home Assistant MQTT discovery.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_on_off_type_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_on_off_type_value_name(ha_on_off_type_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_CHIP_TYPE \
|
||||
DF(HACHT_NONE, "") \
|
||||
DF(HACHT_ESP32, "ESP32") \
|
||||
@ -272,264 +344,243 @@ char *zh_get_on_off_type_value_name(ha_on_off_type_t value);
|
||||
DF(HACHT_ESP32C6, "ESP32-C6") \
|
||||
DF(HACHT_MAX, "")
|
||||
|
||||
typedef enum ha_chip_type_t
|
||||
typedef enum // Enumeration of ESP module types supported by gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_CHIP_TYPE
|
||||
#undef DF
|
||||
} ha_chip_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_chip_type_t value.
|
||||
*
|
||||
* @note Used to prepare a attribytes message by ESP-NOW gateway.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_chip_type_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_chip_type_value_name(ha_chip_type_t value);
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_LED_EFFECT_TYPE \
|
||||
DF(HALET_NONE, "") \
|
||||
DF(HALET_MAX, "")
|
||||
|
||||
typedef enum ha_led_effect_type_t
|
||||
typedef enum // Enumeration of light effect supported by gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_LED_EFFECT_TYPE
|
||||
#undef DF
|
||||
} ha_led_effect_type_t;
|
||||
//***********************************************************************************//
|
||||
|
||||
#define HA_LED_TYPE \
|
||||
DF(HALT_NONE, "") \
|
||||
DF(HALT_W, "W") \
|
||||
DF(HALT_WW, "WW") \
|
||||
DF(HALT_RGB, "RGB") \
|
||||
DF(HALT_RGBW, "RGBW") \
|
||||
DF(HALT_RGBWW, "RGBWW") \
|
||||
DF(HALT_W, "Cold white or Warm white or one another color") \
|
||||
DF(HALT_WW, "Cold white + Warm white") \
|
||||
DF(HALT_RGB, "Red + Green + Blue colors") \
|
||||
DF(HALT_RGBW, "Red + Green + Blue + Cold white or Warm white colors") \
|
||||
DF(HALT_RGBWW, "Red + Green + Blue + Cold white + Warm white colors") \
|
||||
DF(HALT_MAX, "")
|
||||
|
||||
typedef enum ha_led_type_t
|
||||
typedef enum // Enumeration of led types supported by gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_LED_TYPE
|
||||
#undef DF
|
||||
} ha_led_type_t;
|
||||
|
||||
char *zh_get_led_type_value_name(ha_led_type_t value);
|
||||
//***********************************************************************************//
|
||||
#define HA_SENSOR_TYPE \
|
||||
DF(HAST_NONE, "") \
|
||||
DF(HAST_DS18B20, "DS18B20") \
|
||||
DF(HAST_DHT11, "DHT11") \
|
||||
DF(HAST_DHT22, "DHT22") \
|
||||
DF(HAST_GATEWAY, "GATEWAY") \
|
||||
DF(HAST_WINDOW, "WINDOW") \
|
||||
DF(HAST_DOOR, "DOOR") \
|
||||
DF(HAST_LEAKAGE, "LEAKAGE") \
|
||||
DF(HAST_GATEWAY, "") \
|
||||
DF(HAST_WINDOW, "") \
|
||||
DF(HAST_DOOR, "") \
|
||||
DF(HAST_LEAKAGE, "") \
|
||||
DF(HAST_MAX, "")
|
||||
|
||||
typedef enum ha_sensor_type_t
|
||||
typedef enum // Enumeration of sensor / binary sensor supported by gateway.
|
||||
{
|
||||
#define DF(_value, _name) _value,
|
||||
HA_SENSOR_TYPE
|
||||
#undef DF
|
||||
} ha_sensor_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get char description from the enumeration ha_sensor_type_t value.
|
||||
*
|
||||
* @note Used to prepare at attributes messages and status messages by ESP-NOW gateway.
|
||||
*
|
||||
* @param[in] value Enumeration value of ha_sensor_type_t.
|
||||
*
|
||||
* @return Pointer to char value
|
||||
*/
|
||||
char *zh_get_sensor_type_value_name(ha_sensor_type_t value);
|
||||
//***********************************************************************************//
|
||||
typedef struct zh_sensor_config_message_t
|
||||
{
|
||||
uint8_t unique_id;
|
||||
ha_sensor_device_class_t sensor_device_class;
|
||||
char unit_of_measurement[5];
|
||||
uint8_t suggested_display_precision;
|
||||
uint16_t expire_after;
|
||||
bool enabled_by_default;
|
||||
bool force_update;
|
||||
uint8_t qos;
|
||||
bool retain;
|
||||
} __attribute__((packed)) zh_sensor_config_message_t;
|
||||
|
||||
typedef struct zh_sensor_hardware_config_message_t
|
||||
typedef struct // Structure for data exchange between ESP-NOW devices.
|
||||
{
|
||||
ha_sensor_type_t sensor_type;
|
||||
uint8_t sensor_pin_1;
|
||||
uint8_t sensor_pin_2;
|
||||
uint8_t power_pin;
|
||||
uint16_t measurement_frequency;
|
||||
bool battery_power;
|
||||
} __attribute__((packed)) zh_sensor_hardware_config_message_t;
|
||||
|
||||
typedef struct zh_binary_sensor_config_message_t
|
||||
{
|
||||
uint8_t unique_id;
|
||||
ha_binary_sensor_device_class_t binary_sensor_device_class;
|
||||
ha_on_off_type_t payload_on;
|
||||
ha_on_off_type_t payload_off;
|
||||
uint16_t expire_after;
|
||||
uint16_t off_delay;
|
||||
bool enabled_by_default;
|
||||
bool force_update;
|
||||
uint8_t qos;
|
||||
bool retain;
|
||||
} __attribute__((packed)) zh_binary_sensor_config_message_t;
|
||||
|
||||
typedef struct zh_led_config_message_t
|
||||
{
|
||||
uint8_t unique_id;
|
||||
ha_led_type_t led_type;
|
||||
ha_on_off_type_t payload_on;
|
||||
ha_on_off_type_t payload_off;
|
||||
bool enabled_by_default;
|
||||
bool optimistic;
|
||||
uint8_t qos;
|
||||
bool retain;
|
||||
} __attribute__((packed)) zh_led_config_message_t;
|
||||
|
||||
typedef struct zh_led_hardware_config_message_t
|
||||
{
|
||||
ha_led_type_t led_type;
|
||||
uint8_t first_white_pin;
|
||||
uint8_t second_white_pin;
|
||||
uint8_t red_pin;
|
||||
uint8_t green_pin;
|
||||
uint8_t blue_pin;
|
||||
} __attribute__((packed)) zh_led_hardware_config_message_t;
|
||||
|
||||
typedef struct zh_switch_config_message_t
|
||||
{
|
||||
uint8_t unique_id;
|
||||
ha_switch_device_class_t device_class;
|
||||
ha_on_off_type_t payload_on;
|
||||
ha_on_off_type_t payload_off;
|
||||
bool enabled_by_default;
|
||||
bool optimistic;
|
||||
uint8_t qos;
|
||||
bool retain;
|
||||
} __attribute__((packed)) zh_switch_config_message_t;
|
||||
|
||||
typedef struct zh_switch_hardware_config_message_t
|
||||
{
|
||||
uint8_t relay_pin;
|
||||
bool relay_on_level;
|
||||
uint8_t led_pin;
|
||||
bool led_on_level;
|
||||
uint8_t int_button_pin;
|
||||
bool int_button_on_level;
|
||||
uint8_t ext_button_pin;
|
||||
bool ext_button_on_level;
|
||||
uint8_t sensor_pin;
|
||||
ha_sensor_type_t sensor_type;
|
||||
} __attribute__((packed)) zh_switch_hardware_config_message_t;
|
||||
//***********************************************************************************//
|
||||
typedef struct zh_sensor_status_message_t
|
||||
{
|
||||
ha_sensor_type_t sensor_type;
|
||||
float temperature;
|
||||
float humidity;
|
||||
float pressure;
|
||||
float quality;
|
||||
float voltage;
|
||||
float reserved_1; // Reserved for future development.
|
||||
float reserved_2; // Reserved for future development.
|
||||
float reserved_3; // Reserved for future development.
|
||||
float reserved_4; // Reserved for future development.
|
||||
float reserved_5; // Reserved for future development.
|
||||
} __attribute__((packed)) zh_sensor_status_message_t;
|
||||
|
||||
typedef struct zh_binary_sensor_status_message_t
|
||||
{
|
||||
ha_sensor_type_t sensor_type;
|
||||
ha_on_off_type_t connect;
|
||||
ha_on_off_type_t open;
|
||||
ha_on_off_type_t battery;
|
||||
ha_on_off_type_t leakage;
|
||||
zh_device_type_t device_type; // Type of ESP-NOW message sender (gateway, switch, led, etc…).
|
||||
zh_payload_type_t payload_type; // Type of payload for indicating to the recipient of the message into which required structure the received data should be converted (if required).
|
||||
union // Main union for data exchange between ESP-NOW devices. @attention Usually not used in this view. According to the device_type data and payload_type data, the ESP-NOW device should convert the payload_data to the required secondary structure/union (excluding the case of having to send an empty message).
|
||||
{
|
||||
struct // Secondary structure of attributes message.
|
||||
{
|
||||
ha_chip_type_t chip_type; // Used ESP module type.
|
||||
ha_sensor_type_t sensor_type; // Used sensor/binary sensor type (if present).
|
||||
char flash_size[5]; // SoC flash memory.
|
||||
uint8_t cpu_frequency; // SoC frequency.
|
||||
uint32_t heap_size; // Current HEAP memory size.
|
||||
uint32_t min_heap_size; // Minimum HEAP memory size.
|
||||
uint8_t reset_reason; // Last reset reason.
|
||||
char app_name[32]; // Firmware application name.
|
||||
char app_version[32]; // Firmware application version.
|
||||
uint32_t uptime; // Uptime work (in seconds).
|
||||
} attributes_message;
|
||||
struct // Secondary structure of keep alive message.
|
||||
{
|
||||
bool online_status; // Current status of ESP-NOW device operation. @note Online (true) / Offline (false).
|
||||
uint8_t message_frequency; // Frequency of transmission of the keep alive message by ESP-NOW device. @note Used by the ESP-NOW gateway to set the offline status of a ESP-NOW node when the message sending time is exceeded.
|
||||
} keep_alive_message;
|
||||
union // Secondary union of structures of any configuration messages. @attention Not used in this view. Should be converted to the required tertiary structure.
|
||||
{
|
||||
struct // Tertiary structure of zh_espnow_binary_sensor node configuration message. @note Used for publish at MQTT zh_espnow_binary_sensor node configuration message.
|
||||
{
|
||||
uint8_t unique_id; // An ID that uniquely identifies this binary sensor device. @note The ID will look like this - "MAC-X" (for example 64-B7-08-31-00-A8-1). @attention If two binary sensors have the same unique ID, Home Assistant will raise an exception.
|
||||
ha_binary_sensor_device_class_t binary_sensor_device_class; // Binary sensor type supported by the Home Assistant. @note Used to prepare a correct configuration message for Home Assistant MQTT discovery. For details see https://www.home-assistant.io/integrations/binary_sensor.
|
||||
ha_on_off_type_t payload_on; // The payload that represents ON state.
|
||||
ha_on_off_type_t payload_off; // The payload that represents OFF state.
|
||||
uint16_t expire_after; // If set, it defines the number of seconds after the sensors state expires, if its not updated. After expiry, the sensors state becomes unavailable.
|
||||
uint16_t off_delay; // For sensors that only send on state updates (like PIRs), this variable sets a delay in seconds after which the sensors state will be updated back to off.
|
||||
bool enabled_by_default; // Flag which defines if the entity should be enabled when first added.
|
||||
bool force_update; // Sends update events (which results in update of state objects last_changed) even if the sensors state hasnt changed. Useful if you want to have meaningful value graphs in history or want to create an automation that triggers on every incoming state message (not only when the sensors new state is different to the current one).
|
||||
uint8_t qos; // The maximum QoS level to be used when receiving and publishing messages.
|
||||
bool retain; // If the published message should have the retain flag on or not.
|
||||
} binary_sensor_config_message;
|
||||
struct // Tertiary structure of zh_espnow_sensor node configuration message. @note Used publish at MQTT zh_espnow_sensor node configuration message.
|
||||
{
|
||||
uint8_t unique_id; // An ID that uniquely identifies this sensor device. @note The ID will look like this - "MAC-X" (for example 64-B7-08-31-00-A8-1). @attention If two sensors have the same unique ID, Home Assistant will raise an exception.
|
||||
ha_sensor_device_class_t sensor_device_class; // Sensor type supported by the Home Assistant. @note Used to prepare a correct configuration message for Home Assistant MQTT discovery. For details see https://www.home-assistant.io/integrations/sensor.
|
||||
char unit_of_measurement[5]; // Defines the units of measurement of the sensor, if any.
|
||||
uint8_t suggested_display_precision; // The number of decimals which should be used in the sensors state after rounding.
|
||||
uint16_t expire_after; // If set, it defines the number of seconds after the sensors state expires, if its not updated. After expiry, the sensors state becomes unavailable.
|
||||
bool enabled_by_default; // Flag which defines if the entity should be enabled when first added.
|
||||
bool force_update; // Sends update events (which results in update of state objects last_changed) even if the sensors state hasnt changed. Useful if you want to have meaningful value graphs in history or want to create an automation that triggers on every incoming state message (not only when the sensors new state is different to the current one).
|
||||
uint8_t qos; // The maximum QoS level to be used when receiving and publishing messages.
|
||||
bool retain; // If the published message should have the retain flag on or not.
|
||||
} sensor_config_message;
|
||||
struct // Tertiary structure of zh_espnow_sensor node hardware configuration message. @note Used for change hardware configuration / publish at MQTT zh_espnow_sensor node hardware configuration message.
|
||||
{
|
||||
ha_sensor_type_t sensor_type; // Sensor types. @note Used in zh_espnow_sensor firmware only.
|
||||
uint8_t sensor_pin_1; // Sensor GPIO number 1. @note Main pin for 1-wire sensors, SDA pin for I2C sensors.
|
||||
uint8_t sensor_pin_2; // Sensor GPIO number 2. @note SCL pin for I2C sensors.
|
||||
uint8_t power_pin; // Power GPIO number (if used sensor power control).
|
||||
uint16_t measurement_frequency; // Measurement frequency (sleep time on battery powering).
|
||||
bool battery_power; // Battery powered. @note Battery powering (true) / external powering (false).
|
||||
} sensor_hardware_config_message;
|
||||
struct // Tertiary structure of zh_espnow_led node configuration message. @note Used for publish at MQTT zh_espnow_led node configuration message.
|
||||
{
|
||||
uint8_t unique_id; // An ID that uniquely identifies this light device. @note The ID will look like this - "MAC-X" (for example 64-B7-08-31-00-A8-1). @attention If two lights have the same unique ID, Home Assistant will raise an exception.
|
||||
ha_led_type_t led_type; // Led type. @note Used to identify the led type by ESP-NOW gateway and prepare a correct configuration message for Home Assistant MQTT discovery.
|
||||
ha_on_off_type_t payload_on; // The payload that represents ON state.
|
||||
ha_on_off_type_t payload_off; // The payload that represents OFF state.
|
||||
bool enabled_by_default; // Flag which defines if the entity should be enabled when first added.
|
||||
bool optimistic; // Flag that defines if led works in optimistic mode.
|
||||
uint8_t qos; // The maximum QoS level to be used when receiving and publishing messages.
|
||||
bool retain; // If the published message should have the retain flag on or not.
|
||||
} led_config_message;
|
||||
struct // Tertiary structure of zh_espnow_led node hardware configuration message. @note Used for change hardware configuration / publish at MQTT zh_espnow_led node hardware configuration message.
|
||||
{
|
||||
ha_led_type_t led_type; // Led types. @note Used in zh_espnow_led firmware only.
|
||||
uint8_t first_white_pin; // First white GPIO number.
|
||||
uint8_t second_white_pin; // Second white GPIO number (if present).
|
||||
uint8_t red_pin; // Red GPIO number (if present).
|
||||
uint8_t green_pin; // Green GPIO number (if present).
|
||||
uint8_t blue_pin; // Blue GPIO number (if present).
|
||||
} led_hardware_config_message;
|
||||
struct // Tertiary structure of zh_espnow_switch node configuration message. @note Used for publish at MQTT zh_espnow_switch node configuration message.
|
||||
{
|
||||
uint8_t unique_id; // An ID that uniquely identifies this switch device. @note The ID will look like this - "MAC-X" (for example 64-B7-08-31-00-A8-1). @attention If two switches have the same unique ID, Home Assistant will raise an exception.
|
||||
ha_switch_device_class_t device_class; // Switch type supported by the Home Assistant. @note Used to prepare a correct configuration message for Home Assistant MQTT discovery. For details see https://www.home-assistant.io/integrations/switch
|
||||
ha_on_off_type_t payload_on; // The payload that represents ON state.
|
||||
ha_on_off_type_t payload_off; // The payload that represents OFF state.
|
||||
bool enabled_by_default; // Flag which defines if the entity should be enabled when first added.
|
||||
bool optimistic; // Flag that defines if switch works in optimistic mode.
|
||||
uint8_t qos; // The maximum QoS level to be used when receiving and publishing messages.
|
||||
bool retain; // If the published message should have the retain flag on or not.
|
||||
} switch_config_message;
|
||||
struct // Tertiary structure of zh_espnow_switch node hardware configuration message. @note Used for change hardware configuration / publish at MQTT zh_espnow_switch node hardware configuration message.
|
||||
{
|
||||
uint8_t relay_pin; // Relay GPIO number.
|
||||
bool relay_on_level; // Relay ON level. @note HIGH (true) / LOW (false).
|
||||
uint8_t led_pin; // Led GPIO number (if present).
|
||||
bool led_on_level; // Led ON level (if present). @note HIGH (true) / LOW (false).
|
||||
uint8_t int_button_pin; // Internal button GPIO number (if present).
|
||||
bool int_button_on_level; // Internal button trigger level (if present). @note HIGH (true) / LOW (false).
|
||||
uint8_t ext_button_pin; // External button GPIO number (if present).
|
||||
bool ext_button_on_level; // External button trigger level (if present). @note HIGH (true) / LOW (false).
|
||||
uint8_t sensor_pin; // Sensor GPIO number (if present).
|
||||
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.
|
||||
} switch_hardware_config_message;
|
||||
} config_message;
|
||||
union // Secondary union of structures of any status messages. @attention Not used in this view. Should be converted to the required tertiary structure.
|
||||
{
|
||||
struct // Tertiary structure of zh_espnow_binary_sensor node status message.
|
||||
{
|
||||
ha_sensor_type_t sensor_type; // Binary sensor types. @note Used to identify the binary sensor type by ESP-NOW gateway and send the appropriate binary sensor status messages to MQTT.
|
||||
ha_on_off_type_t connect; // Event that caused the sensor to be triggered (if present). @note Example - CONNECT @attention Must be same with set on binary_sensor_config_message structure.
|
||||
ha_on_off_type_t open; // Event that caused the sensor to be triggered (if present). @note Example - OPEN / CLOSE @attention Must be same with set on binary_sensor_config_message structure.
|
||||
ha_on_off_type_t battery; // Event that caused the sensor to be triggered (if present). @note Example - HIGH / LOW @attention Must be same with set on binary_sensor_config_message structure.
|
||||
ha_on_off_type_t leakage; // Event that caused the sensor to be triggered (if present). @note Example - DRY / LEAKAGE @attention Must be same with set on binary_sensor_config_message structure.
|
||||
ha_on_off_type_t reserved_1; // Reserved for future development.
|
||||
ha_on_off_type_t reserved_2; // Reserved for future development.
|
||||
ha_on_off_type_t reserved_3; // Reserved for future development.
|
||||
ha_on_off_type_t reserved_4; // Reserved for future development.
|
||||
ha_on_off_type_t reserved_5; // Reserved for future development.
|
||||
} __attribute__((packed)) zh_binary_sensor_status_message_t;
|
||||
|
||||
typedef struct zh_led_status_message_t
|
||||
{
|
||||
ha_on_off_type_t status;
|
||||
uint8_t brightness;
|
||||
uint16_t temperature;
|
||||
uint8_t red;
|
||||
uint8_t green;
|
||||
uint8_t blue;
|
||||
} binary_sensor_status_message;
|
||||
struct // Tertiary structure of zh_espnow_sensor node status message.
|
||||
{
|
||||
ha_sensor_type_t sensor_type; // Sensor types. @note Used to identify the sensor type by ESP-NOW gateway and send the appropriate sensor status messages to MQTT.
|
||||
float temperature; // Temperature value (if present).
|
||||
float humidity; // Humidity value (if present).
|
||||
float pressure; // Pressure value (if present).
|
||||
float quality; // Quality value (if present).
|
||||
float voltage; // Voltage value (if present).
|
||||
float reserved_1; // Reserved for future development.
|
||||
float reserved_2; // Reserved for future development.
|
||||
float reserved_3; // Reserved for future development.
|
||||
float reserved_4; // Reserved for future development.
|
||||
float reserved_5; // Reserved for future development.
|
||||
} sensor_status_message;
|
||||
struct // Tertiary structure of zh_espnow_led node status message.
|
||||
{
|
||||
ha_on_off_type_t status; // Status of the zh_espnow_led. @note Example - ON / OFF. @attention Must be same with set on led_config_message structure.
|
||||
uint8_t brightness; // Brightness value.
|
||||
uint16_t temperature; // White color temperature value (if present).
|
||||
uint8_t red; // Red color value (if present).
|
||||
uint8_t green; // Green color value (if present).
|
||||
uint8_t blue; // Blue color value (if present).
|
||||
ha_led_effect_type_t effect; // Reserved for future development.
|
||||
} __attribute__((packed)) zh_led_status_message_t;
|
||||
} led_status_message;
|
||||
struct // Tertiary structure of zh_espnow_switch node status message.
|
||||
{
|
||||
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.
|
||||
} switch_status_message;
|
||||
} status_message;
|
||||
union // Secondary union of structures of any OTA update messages. @attention Not used in this view. Should be converted to the required tertiary structure.
|
||||
{
|
||||
struct // Tertiary structure for transfer from ESP-NOW node to ESP-NOW gateway system information for OTA update initialization.
|
||||
{
|
||||
char app_name[32]; // Firmware application name.
|
||||
char app_version[32]; // Firmware application version.
|
||||
} espnow_ota_data;
|
||||
struct // Tertiary structure for transfer from ESP-NOW gateway to ESP-NOW node OTA update data.
|
||||
{
|
||||
uint16_t part; // System counter for the number of new firmware sent parts.
|
||||
uint8_t data_len; // Size of sent data @note Except for the last part, the data is transmitted in 200 bytes part size.
|
||||
uint8_t data[200]; // Sent data.
|
||||
} espnow_ota_message;
|
||||
} ota_message;
|
||||
} payload_data;
|
||||
|
||||
typedef struct zh_switch_status_message_t
|
||||
{
|
||||
ha_on_off_type_t status;
|
||||
} __attribute__((packed)) zh_switch_status_message_t;
|
||||
//***********************************************************************************//
|
||||
typedef struct zh_attributes_message_t
|
||||
{
|
||||
ha_chip_type_t chip_type;
|
||||
ha_sensor_type_t sensor_type;
|
||||
char flash_size[5];
|
||||
uint8_t cpu_frequency;
|
||||
uint32_t heap_size;
|
||||
uint32_t min_heap_size;
|
||||
uint8_t reset_reason;
|
||||
char app_name[32];
|
||||
char app_version[32];
|
||||
uint32_t uptime;
|
||||
} __attribute__((packed)) zh_attributes_message_t;
|
||||
|
||||
typedef struct zh_keep_alive_message_t
|
||||
{
|
||||
bool online_status;
|
||||
uint8_t message_frequency;
|
||||
} __attribute__((packed)) zh_keep_alive_message_t;
|
||||
|
||||
typedef union zh_config_message_t
|
||||
{
|
||||
zh_binary_sensor_config_message_t binary_sensor_config_message;
|
||||
zh_sensor_config_message_t sensor_config_message;
|
||||
zh_sensor_hardware_config_message_t sensor_hardware_config_message;
|
||||
zh_led_config_message_t led_config_message;
|
||||
zh_led_hardware_config_message_t led_hardware_config_message;
|
||||
zh_switch_config_message_t switch_config_message;
|
||||
zh_switch_hardware_config_message_t switch_hardware_config_message;
|
||||
} __attribute__((packed)) zh_config_message_t;
|
||||
|
||||
typedef union zh_status_message_t
|
||||
{
|
||||
zh_binary_sensor_status_message_t binary_sensor_status_message;
|
||||
zh_sensor_status_message_t sensor_status_message;
|
||||
zh_led_status_message_t led_status_message;
|
||||
zh_switch_status_message_t switch_status_message;
|
||||
} __attribute__((packed)) zh_status_message_t;
|
||||
|
||||
typedef struct zh_espnow_ota_message_t
|
||||
{
|
||||
ha_chip_type_t chip_type;
|
||||
char app_name[32];
|
||||
char app_version[32];
|
||||
uint16_t part;
|
||||
uint8_t data_len;
|
||||
uint8_t data[128];
|
||||
} __attribute__((packed)) zh_espnow_ota_message_t;
|
||||
|
||||
typedef struct zh_espnow_ota_data_t
|
||||
{
|
||||
ha_chip_type_t chip_type;
|
||||
zh_device_type_t device_type;
|
||||
char app_name[32];
|
||||
char app_version[32];
|
||||
uint8_t mac_addr[6];
|
||||
} __attribute__((packed)) zh_espnow_ota_data_t;
|
||||
|
||||
typedef union zh_payload_data_t
|
||||
{
|
||||
zh_attributes_message_t attributes_message;
|
||||
zh_keep_alive_message_t keep_alive_message;
|
||||
zh_config_message_t config_message;
|
||||
zh_status_message_t status_message;
|
||||
zh_espnow_ota_message_t espnow_ota_message;
|
||||
} __attribute__((packed)) zh_payload_data_t;
|
||||
|
||||
typedef struct zh_espnow_data_t
|
||||
{
|
||||
zh_device_type_t device_type;
|
||||
zh_payload_type_t payload_type;
|
||||
zh_payload_data_t payload_data;
|
||||
} __attribute__((packed)) zh_espnow_data_t;
|
2
components/zh_config/version.txt
Executable file → Normal file
2
components/zh_config/version.txt
Executable file → Normal file
@ -1 +1 @@
|
||||
1.0.0
|
||||
2.0.0
|
16
components/zh_config/zh_config.c
Executable file → Normal file
16
components/zh_config/zh_config.c
Executable file → Normal file
@ -144,22 +144,6 @@ char *zh_get_chip_type_value_name(ha_chip_type_t value)
|
||||
return "";
|
||||
}
|
||||
|
||||
char *zh_get_led_type_value_name(ha_led_type_t value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
#define DF(_value, _name) \
|
||||
case _value: \
|
||||
return _name;
|
||||
HA_LED_TYPE
|
||||
#undef DF
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
char *zh_get_sensor_type_value_name(ha_sensor_type_t value)
|
||||
{
|
||||
switch (value)
|
||||
|
0
components/zh_espnow/CMakeLists.txt
Executable file → Normal file
0
components/zh_espnow/CMakeLists.txt
Executable file → Normal file
0
components/zh_espnow/LICENSE
Executable file → Normal file
0
components/zh_espnow/LICENSE
Executable file → Normal file
0
components/zh_espnow/README.md
Executable file → Normal file
0
components/zh_espnow/README.md
Executable file → Normal file
0
components/zh_espnow/component.mk
Executable file → Normal file
0
components/zh_espnow/component.mk
Executable file → Normal file
4
components/zh_espnow/include/zh_espnow.h
Executable file → Normal file
4
components/zh_espnow/include/zh_espnow.h
Executable file → Normal file
@ -31,7 +31,8 @@
|
||||
.stack_size = 2048, \
|
||||
.queue_size = 32, \
|
||||
.wifi_interface = WIFI_IF_STA, \
|
||||
.wifi_channel = 1 \
|
||||
.wifi_channel = 1, \
|
||||
.attempts = 3 \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -53,6 +54,7 @@ extern "C"
|
||||
uint8_t queue_size; ///< Queue size for task for the ESP-NOW messages processing. @note The size depends on the number of messages to be processed. It is not recommended to set the value less than 16.
|
||||
wifi_interface_t wifi_interface; ///< WiFi interface (STA or AP) used for ESP-NOW operation. @note The MAC address of the device depends on the selected WiFi interface.
|
||||
uint8_t wifi_channel; ///< Wi-Fi channel uses to send/receive ESP-NOW data. @note Values from 1 to 14.
|
||||
uint8_t attempts; ///< Maximum number of attempts to send a message. @note It is not recommended to set a value greater than 5.
|
||||
} zh_espnow_init_config_t;
|
||||
|
||||
/// \cond
|
||||
|
2
components/zh_espnow/version.txt
Executable file → Normal file
2
components/zh_espnow/version.txt
Executable file → Normal file
@ -1 +1 @@
|
||||
1.0.1
|
||||
1.0.3
|
22
components/zh_espnow/zh_espnow.c
Executable file → Normal file
22
components/zh_espnow/zh_espnow.c
Executable file → Normal file
@ -27,6 +27,7 @@ static QueueHandle_t _queue_handle = {0};
|
||||
static TaskHandle_t _processing_task_handle = {0};
|
||||
static zh_espnow_init_config_t _init_config = {0};
|
||||
static bool _is_initialized = false;
|
||||
static uint8_t _attempts = 0;
|
||||
|
||||
/// \cond
|
||||
typedef struct
|
||||
@ -61,11 +62,22 @@ esp_err_t zh_espnow_init(const zh_espnow_init_config_t *config)
|
||||
ESP_LOGE(TAG, "ESP-NOW initialization fail. WiFi channel.");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (esp_wifi_set_channel(_init_config.wifi_channel, WIFI_SECOND_CHAN_NONE) != ESP_OK)
|
||||
esp_err_t err = esp_wifi_set_channel(_init_config.wifi_channel, WIFI_SECOND_CHAN_NONE);
|
||||
if (err == ESP_ERR_WIFI_NOT_INIT || err == ESP_ERR_WIFI_NOT_STARTED)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW initialization fail. WiFi not initialized.");
|
||||
return ESP_ERR_WIFI_NOT_INIT;
|
||||
}
|
||||
else if (err == ESP_FAIL)
|
||||
{
|
||||
uint8_t prim = 0;
|
||||
wifi_second_chan_t sec = 0;
|
||||
esp_wifi_get_channel(&prim, &sec);
|
||||
if (prim != _init_config.wifi_channel)
|
||||
{
|
||||
ESP_LOGW(TAG, "ESP-NOW initialization warning. The device is connected to the router. Channel %d will be used for ESP-NOW.", prim);
|
||||
}
|
||||
}
|
||||
_event_group_handle = xEventGroupCreate();
|
||||
_queue_handle = xQueueCreate(_init_config.queue_size, sizeof(_queue_t));
|
||||
if (esp_now_init() != ESP_OK || esp_now_register_send_cb(_send_cb) != ESP_OK || esp_now_register_recv_cb(_recv_cb) != ESP_OK)
|
||||
@ -277,6 +289,8 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
memset(on_send, 0, sizeof(zh_espnow_event_on_send_t));
|
||||
memcpy(on_send->mac_addr, queue.data.mac_addr, 6);
|
||||
SEND:
|
||||
++_attempts;
|
||||
err = esp_now_send(queue.data.mac_addr, queue.data.payload, queue.data.payload_len);
|
||||
if (err == ESP_ERR_ESPNOW_NO_MEM)
|
||||
{
|
||||
@ -305,11 +319,17 @@ static void _processing(void *pvParameter)
|
||||
{
|
||||
ESP_LOGI(TAG, "Confirmation message received. ESP-NOW message to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.mac_addr));
|
||||
on_send->status = ZH_ESPNOW_SEND_SUCCESS;
|
||||
_attempts = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_attempts < _init_config.attempts)
|
||||
{
|
||||
goto SEND;
|
||||
}
|
||||
ESP_LOGE(TAG, "Confirmation message not received. ESP-NOW message to MAC %02X:%02X:%02X:%02X:%02X:%02X sent fail.", MAC2STR(queue.data.mac_addr));
|
||||
on_send->status = ZH_ESPNOW_SEND_FAIL;
|
||||
_attempts = 0;
|
||||
}
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.mac_addr));
|
||||
if (esp_event_post(ZH_ESPNOW, ZH_ESPNOW_ON_SEND_EVENT, on_send, sizeof(zh_espnow_event_on_send_t), portTICK_PERIOD_MS) != ESP_OK)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,7 @@
|
||||
#include "esp_mac.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "zh_json.h"
|
||||
#include "zh_vector.h"
|
||||
#include "zh_config.h"
|
||||
|
||||
#ifdef CONFIG_NETWORK_TYPE_DIRECT
|
||||
@ -42,17 +43,21 @@
|
||||
#define ZH_CHIP_TYPE HACHT_ESP32C6
|
||||
#endif
|
||||
|
||||
#define ZH_LAN_MODULE_TYPE(x) esp_eth_phy_new_rtl8201(x) // Change it according to the LAN module used.
|
||||
#define ZH_LAN_MODULE_POWER_PIN GPIO_NUM_12 // Change it according to the LAN module used.
|
||||
#define ZH_LAN_MODULE_TYPE(x) esp_eth_phy_new_rtl8201(x) // For LILYGO T-ETH-Lite ESP32.
|
||||
#define ZH_LAN_MODULE_POWER_PIN GPIO_NUM_12 // For LILYGO T-ETH-Lite ESP32.
|
||||
// #define ZH_LAN_MODULE_TYPE(x) esp_eth_phy_new_lan87xx(x) // For Wireless-Tag WT32-ETH01.
|
||||
// #define ZH_LAN_MODULE_POWER_PIN GPIO_NUM_16 // For Wireless-Tag WT32-ETH01.
|
||||
|
||||
#define ZH_WIFI_MAXIMUM_RETRY 5 // Maximum number of unsuccessful WiFi connection attempts.
|
||||
#define ZH_WIFI_RECONNECT_TIME 5 // Waiting time (in seconds) between attempts to reconnect to WiFi (if number of attempts of unsuccessful connections is exceeded).
|
||||
#define MAC_STR "%02X-%02X-%02X-%02X-%02X-%02X"
|
||||
|
||||
#define ZH_MESSAGE_TASK_PRIORITY 2 // Prioritize the task of sending messages to the MQTT.
|
||||
#define ZH_MESSAGE_STACK_SIZE 2048 // The stack size of the task of sending messages to the MQTT.
|
||||
#define ZH_MESSAGE_STACK_SIZE 3072 // The stack size of the task of sending messages to the MQTT.
|
||||
#define ZH_SNTP_TASK_PRIORITY 2 // Prioritize the task to get the current time.
|
||||
#define ZH_SNTP_STACK_SIZE 2048 // The stack size of the task to get the current time.
|
||||
#define ZH_CHECK_TASK_PRIORITY 2 // Prioritize the task to checking device availability.
|
||||
#define ZH_CHECK_STACK_SIZE 2048 // The stack size of the task to checking device availability.
|
||||
#define ZH_OTA_TASK_PRIORITY 3 // Prioritize the task of OTA updates.
|
||||
#define ZH_OTA_STACK_SIZE 8192 // The stack size of the task of OTA updates.
|
||||
|
||||
@ -60,6 +65,17 @@
|
||||
|
||||
typedef struct // Structure of data exchange between tasks, functions and event handlers.
|
||||
{
|
||||
struct // Storage structure of gateway configuration data.
|
||||
{
|
||||
bool is_lan_mode; // Ethernet work mode flag.
|
||||
char ssid_name[32]; // WiFi SSID name.
|
||||
char ssid_password[64]; // WiFi password.
|
||||
char mqtt_broker_url[64]; // MQTT broker url.
|
||||
char mqtt_topic_prefix[32]; // MQTT topic prefix.
|
||||
char ntp_server_url[64]; // NTP server url.
|
||||
char ntp_time_zone[10]; // NTP time zone.
|
||||
char firmware_upgrade_url[64]; // Firmware upgrade url.
|
||||
} software_config;
|
||||
uint8_t self_mac[6]; // Gateway MAC address. @note Depends at WiFi operation mode.
|
||||
bool sntp_is_enable; // SNTP client operation status flag. @note Used to control the SNTP functions when the network connection is established / lost.
|
||||
bool mqtt_is_enable; // MQTT client operation status flag. @note Used to control the MQTT functions when the network connection is established / lost.
|
||||
@ -70,30 +86,60 @@ typedef struct // Structure of data exchange between tasks, functions and event
|
||||
TaskHandle_t gateway_attributes_message_task; // Unique task handle for zh_gateway_send_mqtt_json_attributes_message_task().
|
||||
TaskHandle_t gateway_keep_alive_message_task; // Unique task handle for zh_gateway_send_mqtt_json_keep_alive_message_task().
|
||||
TaskHandle_t gateway_current_time_task; // Unique task handle for zh_send_espnow_current_time_task().
|
||||
zh_espnow_ota_data_t espnow_ota_data; // Structure for initial transfer system data to the node update task.
|
||||
TaskHandle_t device_availability_check_task; // Unique task handle for zh_device_availability_check_task().
|
||||
struct // Structure for initial transfer system data to the node update task.
|
||||
{
|
||||
zh_device_type_t device_type; // ESP-NOW device type.
|
||||
char app_name[32]; // Firmware application name.
|
||||
char app_version[32]; // Firmware application version.
|
||||
uint8_t mac_addr[6]; // ESP-NOW node MAC address.
|
||||
} espnow_ota_data;
|
||||
SemaphoreHandle_t espnow_ota_data_semaphore; // Semaphore for control the acknowledgement of successful receipt of an update package from a node.
|
||||
SemaphoreHandle_t self_ota_in_progress_mutex; // Mutex blocking the second run of the gateway update task.
|
||||
SemaphoreHandle_t espnow_ota_in_progress_mutex; // Mutex blocking the second run of the node update task.
|
||||
SemaphoreHandle_t device_check_in_progress_mutex; // Mutex blocking the second access to the vector for struct for storing data about available nodes.
|
||||
zh_vector_t available_device_vector; // Vector for struct for storing data about available nodes.
|
||||
} gateway_config_t;
|
||||
|
||||
typedef struct // Struct for storing data about available nodes.
|
||||
{
|
||||
zh_device_type_t device_type; // ESP-NOW device type.
|
||||
uint8_t mac_addr[6]; // ESP-NOW node MAC address.
|
||||
uint8_t frequency; // Keep alive message frequency.
|
||||
uint64_t time; // Last keep alive message time.
|
||||
} available_device_t;
|
||||
|
||||
extern const uint8_t server_certificate_pem_start[] asm("_binary_certificate_pem_start");
|
||||
extern const uint8_t server_certificate_pem_end[] asm("_binary_certificate_pem_end");
|
||||
|
||||
#ifdef CONFIG_CONNECTION_TYPE_LAN
|
||||
/**
|
||||
* @brief Function for loading the gateway configuration from NVS memory.
|
||||
*
|
||||
* @param[out] switch_config Pointer to structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_load_config(gateway_config_t *gateway_config);
|
||||
|
||||
/**
|
||||
* @brief Function for saving the gateway configuration to NVS memory.
|
||||
*
|
||||
* @param[in] switch_config Pointer to structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_save_config(const gateway_config_t *gateway_config);
|
||||
|
||||
/**
|
||||
* @brief Function for LAN event processing.
|
||||
*
|
||||
* @param[in,out] arg Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
#else
|
||||
|
||||
/**
|
||||
* @brief Function for WiFi event processing.
|
||||
*
|
||||
* @param[in,out] arg Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for ESP-NOW event processing
|
||||
*
|
||||
@ -131,6 +177,13 @@ void zh_espnow_ota_update_task(void *pvParameter);
|
||||
*/
|
||||
void zh_send_espnow_current_time_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief The task of checking device availability and sending a message to the MQTT broker in case of unavailability.
|
||||
*
|
||||
* @param[in,out] pvParameter Pointer to the structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
void zh_device_availability_check_task(void *pvParameter);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the correctness of the GPIO number value.
|
||||
*
|
||||
|
@ -1 +1 @@
|
||||
1.0.0
|
||||
1.0.4
|
Reference in New Issue
Block a user