Version 1.0.1
Updated some components. Changed main code to support the new major version of zh_config. Reducing the amount of memory used.
This commit is contained in:
parent
db2a33d47f
commit
6ecd5a59bd
@ -6,7 +6,7 @@ In an existing project, run the following command to install the component:
|
||||
|
||||
```text
|
||||
cd ../your_project/components
|
||||
git clone http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
||||
git clone https://github.com/aZholtikov/zh_config.git
|
||||
```
|
||||
|
||||
In the application, add the component:
|
||||
|
@ -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;
|
@ -1 +1 @@
|
||||
1.11.0
|
||||
2.0.0
|
@ -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)
|
||||
|
@ -13,7 +13,7 @@ In an existing project, run the following command to install the component:
|
||||
|
||||
```text
|
||||
cd ../your_project/components
|
||||
git clone http://git.zh.com.ru/alexey.zholtikov/zh_dht.git
|
||||
git clone https://github.com/aZholtikov/zh_dht.git
|
||||
```
|
||||
|
||||
In the application, add the component:
|
||||
@ -29,7 +29,7 @@ Reading the sensor:
|
||||
```c
|
||||
#include "zh_dht.h"
|
||||
|
||||
void app_main()
|
||||
void app_main(void)
|
||||
{
|
||||
zh_dht_handle_t dht_handle = zh_dht_init(ZH_DHT22, GPIO_NUM_5);
|
||||
float humidity;
|
||||
|
@ -24,9 +24,9 @@ extern "C"
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ZH_DHT11, ///< Sensor type DHT11
|
||||
ZH_DHT22 ///< Sensor type DHT22 or AM2302
|
||||
} __attribute__((packed)) zh_dht_sensor_type_t;
|
||||
ZH_DHT11, ///< Sensor type DHT11.
|
||||
ZH_DHT22 ///< Sensor type DHT22 or AM2302.
|
||||
} zh_dht_sensor_type_t;
|
||||
|
||||
/**
|
||||
* @brief Unique handle of the sensor.
|
||||
@ -34,18 +34,17 @@ extern "C"
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sensor_pin; ///< Sensor GPIO connection
|
||||
zh_dht_sensor_type_t sensor_type; ///< Sensor type
|
||||
} __attribute__((packed)) zh_dht_handle_t;
|
||||
uint8_t sensor_pin; ///< Sensor GPIO connection. @note
|
||||
zh_dht_sensor_type_t sensor_type; ///< Sensor type. @note
|
||||
} zh_dht_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize DHT sensor.
|
||||
*
|
||||
* @param[in] sensor_type Sensor type (ZH_DHT11 or ZH_DHT22).
|
||||
* @param[in] sensor_type Sensor type.
|
||||
* @param[in] sensor_pin Sensor connection gpio.
|
||||
*
|
||||
* @return
|
||||
* - Handle of the sensor.
|
||||
* @return Handle of the sensor
|
||||
*/
|
||||
zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin);
|
||||
|
||||
|
@ -1 +1 @@
|
||||
1.2.6
|
||||
1.0.0
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file
|
||||
* The main code of the zh_dht component.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zh_dht.h"
|
||||
@ -27,10 +28,10 @@ static esp_err_t _read_bit(const zh_dht_handle_t *dht_handle, bool *bit);
|
||||
zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin)
|
||||
{
|
||||
ESP_LOGI(TAG, "DHT initialization begin.");
|
||||
zh_dht_handle_t zh_dht_handle;
|
||||
zh_dht_handle.sensor_type = sensor_type;
|
||||
zh_dht_handle.sensor_pin = sensor_pin;
|
||||
gpio_config_t config;
|
||||
zh_dht_handle_t zh_dht_handle = {
|
||||
.sensor_type = sensor_type,
|
||||
.sensor_pin = sensor_pin};
|
||||
gpio_config_t config = {0};
|
||||
config.intr_type = GPIO_INTR_DISABLE;
|
||||
config.mode = GPIO_MODE_INPUT;
|
||||
config.pin_bit_mask = (1ULL << sensor_pin);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
## Dependencies
|
||||
|
||||
1. [zh_onewire](http://git.zh.com.ru/alexey.zholtikov/zh_onewire.git)
|
||||
1. [zh_onewire](https://github.com/aZholtikov/zh_onewire.git)
|
||||
|
||||
## [Function description](http://zh-ds18b20.zh.com.ru)
|
||||
|
||||
@ -17,8 +17,8 @@ In an existing project, run the following command to install the components:
|
||||
|
||||
```text
|
||||
cd ../your_project/components
|
||||
git clone http://git.zh.com.ru/alexey.zholtikov/zh_onewire.git
|
||||
git clone http://git.zh.com.ru/alexey.zholtikov/zh_ds18b20.git
|
||||
git clone https://github.com/aZholtikov/zh_onewire.git
|
||||
git clone https://github.com/aZholtikov/zh_ds18b20.git
|
||||
```
|
||||
|
||||
In the application, add the component:
|
||||
@ -36,8 +36,10 @@ One or more 1-Wire DS18B20 sensors on bus:
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
uint8_t *rom;
|
||||
float temperature;
|
||||
esp_log_level_set("zh_onewire", ESP_LOG_NONE);
|
||||
esp_log_level_set("zh_ds18b20", ESP_LOG_NONE);
|
||||
uint8_t *rom = NULL;
|
||||
float temperature = 0.0;
|
||||
zh_onewire_init(GPIO_NUM_5);
|
||||
if (zh_onewire_reset() != ESP_OK)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ extern "C"
|
||||
* @return
|
||||
* - ESP_OK if read was successful
|
||||
* - ESP_FAIL if any error
|
||||
* - ESP_ERR_INVALID_CRC if case an read error
|
||||
* - ESP_ERR_INVALID_CRC if check CRC is fail
|
||||
*/
|
||||
esp_err_t zh_ds18b20_read(const uint8_t *device, float *temperature);
|
||||
|
||||
|
@ -1 +1 @@
|
||||
1.3.2
|
||||
1.0.0
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file
|
||||
* The main code of the zh_ds18b20 component.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zh_ds18b20.h"
|
||||
|
@ -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
|
||||
@ -44,9 +45,7 @@ extern "C"
|
||||
*
|
||||
* @note Before initialize ESP-NOW interface recommend initialize zh_espnow_init_config_t structure with default values.
|
||||
*
|
||||
* @code
|
||||
* zh_espnow_init_config_t config = ZH_ESPNOW_INIT_CONFIG_DEFAULT()
|
||||
* @endcode
|
||||
* @code zh_espnow_init_config_t config = ZH_ESPNOW_INIT_CONFIG_DEFAULT() @endcode
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@ -55,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
|
||||
@ -85,7 +85,6 @@ extern "C"
|
||||
* @brief Structure for sending data to the event handler when an ESP-NOW message was sent.
|
||||
*
|
||||
* @note Should be used with ZH_ESPNOW event base and ZH_ESPNOW_ON_SEND_EVENT event.
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@ -110,9 +109,7 @@ extern "C"
|
||||
*
|
||||
* @note Before initialize ESP-NOW interface recommend initialize zh_espnow_init_config_t structure with default values.
|
||||
*
|
||||
* @code
|
||||
* zh_espnow_init_config_t config = ZH_ESPNOW_INIT_CONFIG_DEFAULT()
|
||||
* @endcode
|
||||
* @code zh_espnow_init_config_t config = ZH_ESPNOW_INIT_CONFIG_DEFAULT() @endcode
|
||||
*
|
||||
* @param[in] config Pointer to ESP-NOW initialized configuration structure. Can point to a temporary variable.
|
||||
*
|
||||
|
@ -1 +1 @@
|
||||
1.2.6
|
||||
1.0.3
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file
|
||||
* The main code of the zh_espnow component.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zh_espnow.h"
|
||||
@ -12,7 +13,7 @@
|
||||
/// \endcond
|
||||
|
||||
static void _send_cb(const uint8_t *mac_addr, esp_now_send_status_t status);
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
#if defined CONFIG_IDF_TARGET_ESP8266 || ESP_IDF_VERSION_MAJOR == 4
|
||||
static void _recv_cb(const uint8_t *mac_addr, const uint8_t *data, int data_len);
|
||||
#else
|
||||
static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len);
|
||||
@ -26,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
|
||||
@ -60,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)
|
||||
@ -163,7 +176,7 @@ esp_err_t zh_espnow_send(const uint8_t *target, const uint8_t *data, const uint8
|
||||
}
|
||||
if (xQueueSend(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error at line %d.", __LINE__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
@ -181,13 +194,13 @@ static void _send_cb(const uint8_t *mac_addr, esp_now_send_status_t status)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
#if defined CONFIG_IDF_TARGET_ESP8266 || ESP_IDF_VERSION_MAJOR == 4
|
||||
static void _recv_cb(const uint8_t *mac_addr, const uint8_t *data, int data_len)
|
||||
#else
|
||||
static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len)
|
||||
#endif
|
||||
{
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
#if defined CONFIG_IDF_TARGET_ESP8266 || ESP_IDF_VERSION_MAJOR == 4
|
||||
ESP_LOGI(TAG, "Adding incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to queue begin.", MAC2STR(mac_addr));
|
||||
#else
|
||||
ESP_LOGI(TAG, "Adding incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to queue begin.", MAC2STR(esp_now_info->src_addr));
|
||||
@ -199,7 +212,7 @@ static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *dat
|
||||
}
|
||||
_queue_t queue = {0};
|
||||
queue.id = ON_RECV;
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
#if defined CONFIG_IDF_TARGET_ESP8266 || ESP_IDF_VERSION_MAJOR == 4
|
||||
memcpy(queue.data.mac_addr, mac_addr, 6);
|
||||
#else
|
||||
memcpy(queue.data.mac_addr, esp_now_info->src_addr, 6);
|
||||
@ -220,14 +233,14 @@ static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *dat
|
||||
memset(queue.data.payload, 0, data_len);
|
||||
memcpy(queue.data.payload, data, data_len);
|
||||
queue.data.payload_len = data_len;
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
#if defined CONFIG_IDF_TARGET_ESP8266 || ESP_IDF_VERSION_MAJOR == 4
|
||||
ESP_LOGI(TAG, "Adding incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to queue success.", MAC2STR(mac_addr));
|
||||
#else
|
||||
ESP_LOGI(TAG, "Adding incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to queue success.", MAC2STR(esp_now_info->src_addr));
|
||||
#endif
|
||||
if (xQueueSend(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error at line %d.", __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,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)
|
||||
{
|
||||
@ -304,16 +319,22 @@ 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)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error at line %d.", __LINE__);
|
||||
}
|
||||
heap_caps_free(queue.data.payload);
|
||||
esp_now_del_peer(peer->peer_addr);
|
||||
@ -326,7 +347,7 @@ static void _processing(void *pvParameter)
|
||||
ESP_LOGI(TAG, "Incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.mac_addr));
|
||||
if (esp_event_post(ZH_ESPNOW, ZH_ESPNOW_ON_RECV_EVENT, recv_data, recv_data->data_len + 7, portTICK_PERIOD_MS) != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error at line %d.", __LINE__);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -21,9 +21,8 @@
|
||||
## Attention
|
||||
|
||||
1. The definition of ZH_NETWORK_MAX_MESSAGE_SIZE in the zh_network.h can be changed between 1 and 218. Smaller size - higher transmission speed. All devices on the network must have the same ZH_NETWORK_MAX_MESSAGE_SIZE.
|
||||
2. For correct operation in ESP-NOW + STA mode, your WiFi router must be set to the same channel as ESP-NOW.
|
||||
3. All devices on the network must have the same WiFi channel.
|
||||
4. The ZHNetwork and the zh_network are incompatible.
|
||||
2. For correct work at ESP-NOW + STA mode your WiFi router must be set on channel 1.
|
||||
3. The ZHNetwork and the zh_network are incompatible.
|
||||
|
||||
## Testing
|
||||
|
||||
@ -85,7 +84,7 @@ typedef struct
|
||||
void app_main(void)
|
||||
{
|
||||
esp_log_level_set("zh_vector", ESP_LOG_NONE);
|
||||
// esp_log_level_set("zh_network", ESP_LOG_NONE);
|
||||
esp_log_level_set("zh_network", ESP_LOG_NONE);
|
||||
nvs_flash_init();
|
||||
esp_netif_init();
|
||||
esp_event_loop_create_default();
|
||||
|
@ -35,7 +35,6 @@
|
||||
* @note Value range from 1 to 218. Smaller size - higher transmission speed.
|
||||
*
|
||||
* @attention All devices on the network must have the same ZH_NETWORK_MAX_MESSAGE_SIZE.
|
||||
*
|
||||
*/
|
||||
#define ZH_NETWORK_MAX_MESSAGE_SIZE 218
|
||||
|
||||
@ -52,8 +51,7 @@
|
||||
.max_waiting_time = 1000, \
|
||||
.id_vector_size = 100, \
|
||||
.route_vector_size = 100, \
|
||||
.wifi_interface = WIFI_IF_STA, \
|
||||
.wifi_channel = 1 \
|
||||
.wifi_interface = WIFI_IF_STA \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -66,9 +64,7 @@ extern "C"
|
||||
*
|
||||
* @note Before initialize ESP-NOW interface recommend initialize zh_network_init_config_t structure with default values.
|
||||
*
|
||||
* @code
|
||||
* zh_network_init_config_t config = ZH_NETWORK_INIT_CONFIG_DEFAULT()
|
||||
* @endcode
|
||||
* @code zh_network_init_config_t config = ZH_NETWORK_INIT_CONFIG_DEFAULT() @endcode
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@ -80,8 +76,7 @@ extern "C"
|
||||
uint16_t id_vector_size; ///< Maximum size of unique ID of received messages. @note If the size is exceeded, the first value will be deleted. Minimum recommended value: number of planned nodes in the network + 10%.
|
||||
uint16_t route_vector_size; ///< The maximum size of the routing table. @note If the size is exceeded, the first route will be deleted. Minimum recommended value: number of planned nodes in the network + 10%.
|
||||
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 ESPNOW data. @note Values from 1 to 14.
|
||||
} __attribute__((packed)) zh_network_init_config_t;
|
||||
} zh_network_init_config_t;
|
||||
|
||||
/// \cond
|
||||
ESP_EVENT_DECLARE_BASE(ESP_EVENT_BASE);
|
||||
@ -95,7 +90,7 @@ extern "C"
|
||||
{
|
||||
ZH_NETWORK_ON_RECV_EVENT, ///< The event when the ESP-NOW message was received.
|
||||
ZH_NETWORK_ON_SEND_EVENT ///< The event when the ESP-NOW message was sent.
|
||||
} __attribute__((packed)) zh_network_event_type_t;
|
||||
} zh_network_event_type_t;
|
||||
|
||||
/**
|
||||
* @brief Enumeration of possible status of sent ESP-NOW message.
|
||||
@ -105,19 +100,18 @@ extern "C"
|
||||
{
|
||||
ZH_NETWORK_SEND_SUCCESS, ///< If ESP-NOW message was sent success.
|
||||
ZH_NETWORK_SEND_FAIL ///< If ESP-NOW message was sent fail.
|
||||
} __attribute__((packed)) zh_network_on_send_event_type_t;
|
||||
} zh_network_on_send_event_type_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for sending data to the event handler when an ESP-NOW message was sent.
|
||||
*
|
||||
* @note Should be used with ZH_NETWORK event base and ZH_NETWORK_ON_SEND_EVENT event.
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t mac_addr[6]; ///< MAC address of the device to which the ESP-NOW message was sent. @note
|
||||
zh_network_on_send_event_type_t status; ///< Status of sent ESP-NOW message. @note
|
||||
} __attribute__((packed)) zh_network_event_on_send_t;
|
||||
} zh_network_event_on_send_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for sending data to the event handler when an ESP-NOW message was received.
|
||||
@ -129,16 +123,14 @@ extern "C"
|
||||
uint8_t mac_addr[6]; ///< MAC address of the sender ESP-NOW message. @note
|
||||
uint8_t *data; ///< Pointer to the data of the received ESP-NOW message. @note
|
||||
uint8_t data_len; ///< Size of the received ESP-NOW message. @note
|
||||
} __attribute__((packed)) zh_network_event_on_recv_t;
|
||||
} zh_network_event_on_recv_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize ESP-NOW interface.
|
||||
*
|
||||
* @note Before initialize ESP-NOW interface recommend initialize zh_network_init_config_t structure with default values.
|
||||
*
|
||||
* @code
|
||||
* zh_network_init_config_t config = ZH_NETWORK_INIT_CONFIG_DEFAULT()
|
||||
* @endcode
|
||||
* @code zh_network_init_config_t config = ZH_NETWORK_INIT_CONFIG_DEFAULT() @endcode
|
||||
*
|
||||
* @param[in] config Pointer to ESP-NOW initialized configuration structure. Can point to a temporary variable.
|
||||
*
|
||||
@ -148,7 +140,7 @@ extern "C"
|
||||
* - ESP_ERR_WIFI_NOT_INIT if WiFi is not initialized
|
||||
* - ESP_FAIL if any internal error
|
||||
*/
|
||||
esp_err_t zh_network_init(const zh_network_init_config_t *config);
|
||||
esp_err_t zh_network_init(zh_network_init_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ESP-NOW interface.
|
||||
@ -172,7 +164,7 @@ extern "C"
|
||||
* - ESP_OK if sent was success
|
||||
* - ESP_ERR_INVALID_ARG if parameter error
|
||||
* - ESP_ERR_INVALID_STATE if queue for outgoing data is almost full
|
||||
* - ESP_FAIL if ESP-NOW is not initialized or any internal error
|
||||
* - ESP_FAIL if ESP-NOW is not initialized
|
||||
*/
|
||||
esp_err_t zh_network_send(const uint8_t *target, const uint8_t *data, const uint8_t data_len);
|
||||
|
||||
|
@ -1 +1 @@
|
||||
1.4.4
|
||||
1.0.0
|
@ -21,7 +21,7 @@ static void _processing(void *pvParameter);
|
||||
|
||||
static const char *TAG = "zh_network";
|
||||
|
||||
static EventGroupHandle_t _event_group_handle = {0};
|
||||
static EventGroupHandle_t _send_cb_status_event_group_handle = {0};
|
||||
static QueueHandle_t _queue_handle = {0};
|
||||
static TaskHandle_t _processing_task_handle = {0};
|
||||
static SemaphoreHandle_t _id_vector_mutex = {0};
|
||||
@ -34,47 +34,53 @@ static const uint8_t _broadcast_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
static bool _is_initialized = false;
|
||||
|
||||
/// \cond
|
||||
typedef struct
|
||||
typedef enum
|
||||
{
|
||||
uint8_t original_target_mac[6];
|
||||
uint8_t intermediate_target_mac[6];
|
||||
} __attribute__((packed)) _routing_table_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t time;
|
||||
enum
|
||||
{
|
||||
TO_SEND,
|
||||
ON_RECV,
|
||||
WAIT_ROUTE,
|
||||
WAIT_RESPONSE,
|
||||
} id;
|
||||
struct
|
||||
{
|
||||
enum
|
||||
{
|
||||
BROADCAST,
|
||||
UNICAST,
|
||||
DELIVERY_CONFIRM,
|
||||
SEARCH_REQUEST,
|
||||
SEARCH_RESPONSE
|
||||
} message_type;
|
||||
} message_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
message_type_t message_type;
|
||||
uint32_t network_id;
|
||||
uint32_t message_id;
|
||||
uint32_t confirm_id;
|
||||
uint8_t original_target_mac[6];
|
||||
uint8_t original_sender_mac[6];
|
||||
uint8_t sender_mac[6];
|
||||
uint8_t payload[ZH_NETWORK_MAX_MESSAGE_SIZE];
|
||||
uint8_t payload_len;
|
||||
} data;
|
||||
} __attribute__((packed)) _queue_t;
|
||||
uint8_t data[ZH_NETWORK_MAX_MESSAGE_SIZE];
|
||||
uint8_t data_len;
|
||||
} data_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t original_target_mac[6];
|
||||
uint8_t intermediate_target_mac[6];
|
||||
} routing_table_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TO_SEND,
|
||||
ON_RECV,
|
||||
WAIT_ROUTE,
|
||||
WAIT_RESPONSE,
|
||||
} queue_id_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
queue_id_t id;
|
||||
uint64_t time;
|
||||
data_t data;
|
||||
} queue_t;
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(ZH_NETWORK);
|
||||
/// \endcond
|
||||
|
||||
esp_err_t zh_network_init(const zh_network_init_config_t *config)
|
||||
esp_err_t zh_network_init(zh_network_init_config_t *config)
|
||||
{
|
||||
ESP_LOGI(TAG, "ESP-NOW initialization begin.");
|
||||
if (config == NULL)
|
||||
@ -82,18 +88,12 @@ esp_err_t zh_network_init(const zh_network_init_config_t *config)
|
||||
ESP_LOGE(TAG, "ESP-NOW initialization fail. Invalid argument.");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
_init_config = *config;
|
||||
if (_init_config.wifi_channel < 1 || _init_config.wifi_channel > 14)
|
||||
{
|
||||
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_ERR_WIFI_NOT_INIT)
|
||||
if (esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE) == ESP_ERR_WIFI_NOT_INIT)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW initialization fail. WiFi not initialized.");
|
||||
return ESP_ERR_WIFI_NOT_INIT;
|
||||
}
|
||||
if ((sizeof(_queue_t) - 12) > ESP_NOW_MAX_DATA_LEN)
|
||||
if (sizeof(data_t) > ESP_NOW_MAX_DATA_LEN)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW initialization fail. The maximum value of the transmitted data size is incorrect.");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -106,10 +106,11 @@ esp_err_t zh_network_init(const zh_network_init_config_t *config)
|
||||
{
|
||||
esp_read_mac(_self_mac, ESP_MAC_WIFI_SOFTAP);
|
||||
}
|
||||
_event_group_handle = xEventGroupCreate();
|
||||
_queue_handle = xQueueCreate(_init_config.queue_size, sizeof(_queue_t));
|
||||
_init_config = *config;
|
||||
_send_cb_status_event_group_handle = xEventGroupCreate();
|
||||
_queue_handle = xQueueCreate(_init_config.queue_size, sizeof(queue_t));
|
||||
zh_vector_init(&_id_vector, sizeof(uint32_t), false);
|
||||
zh_vector_init(&_route_vector, sizeof(_routing_table_t), false);
|
||||
zh_vector_init(&_route_vector, sizeof(routing_table_t), false);
|
||||
zh_vector_init(&_response_vector, sizeof(uint32_t), false);
|
||||
_id_vector_mutex = xSemaphoreCreateMutex();
|
||||
if (esp_now_init() != ESP_OK || esp_now_register_send_cb(_send_cb) != ESP_OK || esp_now_register_recv_cb(_recv_cb) != ESP_OK)
|
||||
@ -135,7 +136,7 @@ esp_err_t zh_network_deinit(void)
|
||||
ESP_LOGE(TAG, "ESP-NOW deinitialization fail. ESP-NOW not initialized.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
vEventGroupDelete(_event_group_handle);
|
||||
vEventGroupDelete(_send_cb_status_event_group_handle);
|
||||
vQueueDelete(_queue_handle);
|
||||
esp_now_unregister_send_cb();
|
||||
esp_now_unregister_recv_cb();
|
||||
@ -174,31 +175,32 @@ esp_err_t zh_network_send(const uint8_t *target, const uint8_t *data, const uint
|
||||
ESP_LOGW(TAG, "Adding outgoing ESP-NOW data to queue fail. Queue is almost full.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
_queue_t queue = {0};
|
||||
queue_t queue = {0};
|
||||
queue.id = TO_SEND;
|
||||
queue.data.network_id = _init_config.network_id;
|
||||
queue.data.message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
memcpy(queue.data.original_sender_mac, _self_mac, 6);
|
||||
data_t *send_data = &queue.data;
|
||||
send_data->network_id = _init_config.network_id;
|
||||
send_data->message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
memcpy(send_data->original_sender_mac, &_self_mac, 6);
|
||||
if (target == NULL)
|
||||
{
|
||||
queue.data.message_type = BROADCAST;
|
||||
memcpy(queue.data.original_target_mac, _broadcast_mac, 6);
|
||||
send_data->message_type = BROADCAST;
|
||||
memcpy(send_data->original_target_mac, &_broadcast_mac, 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (memcmp(target, _broadcast_mac, 6) != 0)
|
||||
if (memcmp(target, &_broadcast_mac, 6) != 0)
|
||||
{
|
||||
queue.data.message_type = UNICAST;
|
||||
memcpy(queue.data.original_target_mac, target, 6);
|
||||
send_data->message_type = UNICAST;
|
||||
memcpy(send_data->original_target_mac, target, 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
queue.data.message_type = BROADCAST;
|
||||
memcpy(queue.data.original_target_mac, _broadcast_mac, 6);
|
||||
send_data->message_type = BROADCAST;
|
||||
memcpy(send_data->original_target_mac, &_broadcast_mac, 6);
|
||||
}
|
||||
}
|
||||
memcpy(queue.data.payload, data, data_len);
|
||||
queue.data.payload_len = data_len;
|
||||
memcpy(&send_data->data, data, data_len);
|
||||
send_data->data_len = data_len;
|
||||
if (target == NULL)
|
||||
{
|
||||
ESP_LOGI(TAG, "Adding outgoing ESP-NOW data to MAC FF:FF:FF:FF:FF:FF to queue success.");
|
||||
@ -210,7 +212,6 @@ esp_err_t zh_network_send(const uint8_t *target, const uint8_t *data, const uint
|
||||
if (xQueueSend(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -219,11 +220,11 @@ static void _send_cb(const uint8_t *mac_addr, esp_now_send_status_t status)
|
||||
{
|
||||
if (status == ESP_NOW_SEND_SUCCESS)
|
||||
{
|
||||
xEventGroupSetBits(_event_group_handle, DATA_SEND_SUCCESS);
|
||||
xEventGroupSetBits(_send_cb_status_event_group_handle, DATA_SEND_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
xEventGroupSetBits(_event_group_handle, DATA_SEND_FAIL);
|
||||
xEventGroupSetBits(_send_cb_status_event_group_handle, DATA_SEND_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,12 +244,10 @@ static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *dat
|
||||
ESP_LOGW(TAG, "Adding incoming ESP-NOW data to queue fail. Queue is almost full.");
|
||||
return;
|
||||
}
|
||||
if (data_len == sizeof(_queue_t) - 12)
|
||||
if (data_len == sizeof(data_t))
|
||||
{
|
||||
_queue_t queue = {0};
|
||||
queue.id = ON_RECV;
|
||||
memcpy(&queue.data, data, data_len);
|
||||
if (memcmp(&queue.data.network_id, &_init_config.network_id, sizeof(queue.data.network_id)) != 0)
|
||||
data_t *recv_data = (data_t *)data;
|
||||
if (memcmp(&recv_data->network_id, &_init_config.network_id, sizeof(recv_data->network_id)) != 0)
|
||||
{
|
||||
ESP_LOGW(TAG, "Adding incoming ESP-NOW data to queue fail. Incorrect mesh network ID.");
|
||||
return;
|
||||
@ -256,7 +255,7 @@ static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *dat
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_id_vector); ++i)
|
||||
{
|
||||
uint32_t *message_id = zh_vector_get_item(&_id_vector, i);
|
||||
if (memcmp(&queue.data.message_id, message_id, sizeof(queue.data.message_id)) == 0)
|
||||
if (memcmp(&recv_data->message_id, message_id, sizeof(recv_data->message_id)) == 0)
|
||||
{
|
||||
ESP_LOGW(TAG, "Adding incoming ESP-NOW data to queue fail. Repeat message received.");
|
||||
return;
|
||||
@ -264,17 +263,21 @@ static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *dat
|
||||
}
|
||||
if (xSemaphoreTake(_id_vector_mutex, portTICK_PERIOD_MS) == pdTRUE)
|
||||
{
|
||||
zh_vector_push_back(&_id_vector, &queue.data.message_id);
|
||||
zh_vector_push_back(&_id_vector, &recv_data->message_id);
|
||||
if (zh_vector_get_size(&_id_vector) > _init_config.id_vector_size)
|
||||
{
|
||||
zh_vector_delete_item(&_id_vector, 0);
|
||||
}
|
||||
xSemaphoreGive(_id_vector_mutex);
|
||||
}
|
||||
queue_t queue = {0};
|
||||
queue.id = ON_RECV;
|
||||
recv_data = &queue.data;
|
||||
memcpy(recv_data, data, data_len);
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
memcpy(queue.data.sender_mac, mac_addr, 6);
|
||||
memcpy(recv_data->sender_mac, mac_addr, 6);
|
||||
#else
|
||||
memcpy(queue.data.sender_mac, esp_now_info->src_addr, 6);
|
||||
memcpy(recv_data->sender_mac, esp_now_info->src_addr, 6);
|
||||
#endif
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
ESP_LOGI(TAG, "Adding incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to queue success.", MAC2STR(mac_addr));
|
||||
@ -294,10 +297,11 @@ static void _recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *dat
|
||||
|
||||
static void _processing(void *pvParameter)
|
||||
{
|
||||
_queue_t queue = {0};
|
||||
queue_t queue = {0};
|
||||
while (xQueueReceive(_queue_handle, &queue, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
bool flag = false;
|
||||
data_t *data = &queue.data;
|
||||
switch (queue.id)
|
||||
{
|
||||
case TO_SEND:
|
||||
@ -311,14 +315,14 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
memset(peer, 0, sizeof(esp_now_peer_info_t));
|
||||
peer->ifidx = _init_config.wifi_interface;
|
||||
if (queue.data.message_type == BROADCAST || queue.data.message_type == SEARCH_REQUEST || queue.data.message_type == SEARCH_RESPONSE)
|
||||
if (data->message_type == BROADCAST || data->message_type == SEARCH_REQUEST || data->message_type == SEARCH_RESPONSE)
|
||||
{
|
||||
memcpy(peer->peer_addr, _broadcast_mac, 6);
|
||||
if (memcmp(queue.data.original_sender_mac, _self_mac, 6) == 0)
|
||||
memcpy(peer->peer_addr, &_broadcast_mac, 6);
|
||||
if (memcmp(data->original_sender_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
if (xSemaphoreTake(_id_vector_mutex, portTICK_PERIOD_MS) == pdTRUE)
|
||||
{
|
||||
zh_vector_push_back(&_id_vector, &queue.data.message_id);
|
||||
zh_vector_push_back(&_id_vector, &data->message_id);
|
||||
if (zh_vector_get_size(&_id_vector) > _init_config.id_vector_size)
|
||||
{
|
||||
zh_vector_delete_item(&_id_vector, 0);
|
||||
@ -332,8 +336,8 @@ static void _processing(void *pvParameter)
|
||||
ESP_LOGI(TAG, "Checking routing table to MAC %02X:%02X:%02X:%02X:%02X:%02X.", MAC2STR(queue.data.original_target_mac));
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_route_vector); ++i)
|
||||
{
|
||||
_routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(queue.data.original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(data->original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
{
|
||||
memcpy(peer->peer_addr, routing_table->intermediate_target_mac, 6);
|
||||
flag = true;
|
||||
@ -344,7 +348,7 @@ static void _processing(void *pvParameter)
|
||||
if (flag == false)
|
||||
{
|
||||
ESP_LOGI(TAG, "Routing to MAC %02X:%02X:%02X:%02X:%02X:%02X not found.", MAC2STR(queue.data.original_target_mac));
|
||||
if (queue.data.message_type == UNICAST)
|
||||
if (data->message_type == UNICAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X transferred to routing waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
@ -360,11 +364,11 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
ESP_LOGI(TAG, "System message for routing request from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X added to queue.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
queue.id = TO_SEND;
|
||||
queue.data.message_type = SEARCH_REQUEST;
|
||||
memcpy(queue.data.original_sender_mac, _self_mac, 6);
|
||||
queue.data.payload_len = 0;
|
||||
memset(queue.data.payload, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
queue.data.message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
data->message_type = SEARCH_REQUEST;
|
||||
memcpy(data->original_sender_mac, &_self_mac, 6);
|
||||
data->data_len = 0;
|
||||
memset(data->data, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
data->message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (xQueueSendToFront(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
@ -389,20 +393,20 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
}
|
||||
memset(on_send, 0, sizeof(zh_network_event_on_send_t));
|
||||
memcpy(on_send->mac_addr, queue.data.original_target_mac, 6);
|
||||
if (esp_now_send((uint8_t *)peer->peer_addr, (uint8_t *)&queue.data, sizeof(_queue_t) - 12) != ESP_OK)
|
||||
memcpy(on_send->mac_addr, data->original_target_mac, 6);
|
||||
if (esp_now_send((uint8_t *)peer->peer_addr, (uint8_t *)data, sizeof(data_t)) != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
heap_caps_free(peer);
|
||||
heap_caps_free(on_send);
|
||||
break;
|
||||
}
|
||||
EventBits_t bit = xEventGroupWaitBits(_event_group_handle, DATA_SEND_SUCCESS | DATA_SEND_FAIL, pdTRUE, pdFALSE, 50 / portTICK_PERIOD_MS);
|
||||
EventBits_t bit = xEventGroupWaitBits(_send_cb_status_event_group_handle, DATA_SEND_SUCCESS | DATA_SEND_FAIL, pdTRUE, pdFALSE, 50 / portTICK_PERIOD_MS);
|
||||
if ((bit & DATA_SEND_SUCCESS) != 0)
|
||||
{
|
||||
if (memcmp(queue.data.original_sender_mac, _self_mac, 6) == 0)
|
||||
if (memcmp(data->original_sender_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
if (queue.data.message_type == BROADCAST)
|
||||
if (data->message_type == BROADCAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Broadcast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
on_send->status = ZH_NETWORK_SEND_SUCCESS;
|
||||
@ -412,22 +416,22 @@ static void _processing(void *pvParameter)
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
}
|
||||
}
|
||||
if (queue.data.message_type == SEARCH_REQUEST)
|
||||
if (data->message_type == SEARCH_REQUEST)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for routing request from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == SEARCH_RESPONSE)
|
||||
if (data->message_type == SEARCH_RESPONSE)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for routing response from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == DELIVERY_CONFIRM)
|
||||
if (data->message_type == DELIVERY_CONFIRM)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for message receiving confirmation from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == UNICAST)
|
||||
if (data->message_type == UNICAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X transferred to confirmation message waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -442,27 +446,27 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (queue.data.message_type == BROADCAST)
|
||||
if (data->message_type == BROADCAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Broadcast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == SEARCH_REQUEST)
|
||||
if (data->message_type == SEARCH_REQUEST)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for routing request from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == SEARCH_RESPONSE)
|
||||
if (data->message_type == SEARCH_RESPONSE)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for routing response from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == DELIVERY_CONFIRM)
|
||||
if (data->message_type == DELIVERY_CONFIRM)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for message receiving confirmation from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == UNICAST)
|
||||
if (data->message_type == UNICAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -471,22 +475,22 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (memcmp(queue.data.original_target_mac, _broadcast_mac, 6) != 0)
|
||||
if (memcmp(data->original_target_mac, &_broadcast_mac, 6) != 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Routing to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X is incorrect.", MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_route_vector); ++i)
|
||||
{
|
||||
_routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(queue.data.original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(data->original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
{
|
||||
zh_vector_delete_item(&_route_vector, i);
|
||||
}
|
||||
}
|
||||
if (queue.data.message_type == UNICAST)
|
||||
if (data->message_type == UNICAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X transferred to routing waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == DELIVERY_CONFIRM)
|
||||
if (data->message_type == DELIVERY_CONFIRM)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for message receiving confirmation from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X transferred to routing waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
@ -498,11 +502,11 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
ESP_LOGI(TAG, "System message for routing request to MAC %02X:%02X:%02X:%02X:%02X:%02X added to queue.", MAC2STR(queue.data.original_target_mac));
|
||||
queue.id = TO_SEND;
|
||||
queue.data.message_type = SEARCH_REQUEST;
|
||||
memcpy(queue.data.original_sender_mac, _self_mac, 6);
|
||||
queue.data.payload_len = 0;
|
||||
memset(queue.data.payload, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
queue.data.message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
data->message_type = SEARCH_REQUEST;
|
||||
memcpy(data->original_sender_mac, &_self_mac, 6);
|
||||
data->data_len = 0;
|
||||
memset(data->data, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
data->message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (xQueueSendToFront(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
@ -516,7 +520,7 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
case ON_RECV:
|
||||
ESP_LOGI(TAG, "Incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processing begin.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
switch (queue.data.message_type)
|
||||
switch (data->message_type)
|
||||
{
|
||||
case BROADCAST:
|
||||
ESP_LOGI(TAG, "Broadcast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X is received.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -528,9 +532,9 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
}
|
||||
memset(on_recv, 0, sizeof(zh_network_event_on_recv_t));
|
||||
memcpy(on_recv->mac_addr, queue.data.original_sender_mac, 6);
|
||||
on_recv->data_len = queue.data.payload_len;
|
||||
on_recv->data = heap_caps_malloc(queue.data.payload_len, MALLOC_CAP_8BIT);
|
||||
memcpy(on_recv->mac_addr, data->original_sender_mac, 6);
|
||||
on_recv->data_len = data->data_len;
|
||||
on_recv->data = heap_caps_malloc(data->data_len, MALLOC_CAP_8BIT);
|
||||
if (on_recv->data == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
@ -538,8 +542,8 @@ static void _processing(void *pvParameter)
|
||||
heap_caps_free(on_recv->data);
|
||||
break;
|
||||
}
|
||||
memset(on_recv->data, 0, queue.data.payload_len);
|
||||
memcpy(on_recv->data, queue.data.payload, queue.data.payload_len);
|
||||
memset(on_recv->data, 0, data->data_len);
|
||||
memcpy(on_recv->data, data->data, data->data_len);
|
||||
ESP_LOGI(TAG, "Broadcast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X added to queue for resend to all nodes.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (esp_event_post(ZH_NETWORK, ZH_NETWORK_ON_RECV_EVENT, on_recv, sizeof(zh_network_event_on_recv_t) + on_recv->data_len + sizeof(on_recv->data_len), portTICK_PERIOD_MS) != ESP_OK)
|
||||
@ -555,7 +559,7 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
case UNICAST:
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X is received.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (memcmp(queue.data.original_target_mac, _self_mac, 6) == 0)
|
||||
if (memcmp(data->original_target_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
zh_network_event_on_recv_t *on_recv = heap_caps_malloc(sizeof(zh_network_event_on_recv_t), MALLOC_CAP_8BIT);
|
||||
if (on_recv == NULL)
|
||||
@ -565,9 +569,9 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
}
|
||||
memset(on_recv, 0, sizeof(zh_network_event_on_recv_t));
|
||||
memcpy(on_recv->mac_addr, queue.data.original_sender_mac, 6);
|
||||
on_recv->data_len = queue.data.payload_len;
|
||||
on_recv->data = heap_caps_malloc(queue.data.payload_len, MALLOC_CAP_8BIT);
|
||||
memcpy(on_recv->mac_addr, data->original_sender_mac, 6);
|
||||
on_recv->data_len = data->data_len;
|
||||
on_recv->data = heap_caps_malloc(data->data_len, MALLOC_CAP_8BIT);
|
||||
if (on_recv->data == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
@ -575,8 +579,8 @@ static void _processing(void *pvParameter)
|
||||
heap_caps_free(on_recv->data);
|
||||
break;
|
||||
}
|
||||
memset(on_recv->data, 0, queue.data.payload_len);
|
||||
memcpy(on_recv->data, queue.data.payload, queue.data.payload_len);
|
||||
memset(on_recv->data, 0, data->data_len);
|
||||
memcpy(on_recv->data, data->data, data->data_len);
|
||||
ESP_LOGI(TAG, "Incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (esp_event_post(ZH_NETWORK, ZH_NETWORK_ON_RECV_EVENT, on_recv, sizeof(zh_network_event_on_recv_t) + on_recv->data_len + sizeof(on_recv->data_len), portTICK_PERIOD_MS) != ESP_OK)
|
||||
{
|
||||
@ -584,13 +588,13 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
heap_caps_free(on_recv);
|
||||
queue.id = TO_SEND;
|
||||
queue.data.message_type = DELIVERY_CONFIRM;
|
||||
memcpy(queue.data.original_target_mac, queue.data.original_sender_mac, 6);
|
||||
memcpy(queue.data.original_sender_mac, _self_mac, 6);
|
||||
queue.data.payload_len = 0;
|
||||
memset(queue.data.payload, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
queue.data.confirm_id = queue.data.message_id;
|
||||
queue.data.message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
data->message_type = DELIVERY_CONFIRM;
|
||||
memcpy(data->original_target_mac, data->original_sender_mac, 6);
|
||||
memcpy(data->original_sender_mac, &_self_mac, 6);
|
||||
data->data_len = 0;
|
||||
memset(data->data, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
data->confirm_id = data->message_id;
|
||||
data->message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
if (xQueueSendToFront(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error.");
|
||||
@ -607,9 +611,9 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
case DELIVERY_CONFIRM:
|
||||
ESP_LOGI(TAG, "System message for message receiving confirmation from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X is received.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (memcmp(queue.data.original_target_mac, _self_mac, 6) == 0)
|
||||
if (memcmp(data->original_target_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
zh_vector_push_back(&_response_vector, &queue.data.confirm_id);
|
||||
zh_vector_push_back(&_response_vector, &data->confirm_id);
|
||||
if (zh_vector_get_size(&_response_vector) > _init_config.queue_size)
|
||||
{
|
||||
zh_vector_delete_item(&_response_vector, 0);
|
||||
@ -629,32 +633,32 @@ static void _processing(void *pvParameter)
|
||||
ESP_LOGI(TAG, "System message for routing request from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X is received.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_route_vector); ++i)
|
||||
{
|
||||
_routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(queue.data.original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(data->original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
{
|
||||
zh_vector_delete_item(&_route_vector, i);
|
||||
}
|
||||
}
|
||||
{ // Just to avoid the compiler warning.
|
||||
_routing_table_t routing_table = {0};
|
||||
memcpy(routing_table.original_target_mac, queue.data.original_sender_mac, 6);
|
||||
memcpy(routing_table.intermediate_target_mac, queue.data.sender_mac, 6);
|
||||
routing_table_t routing_table = {0};
|
||||
memcpy(&routing_table.original_target_mac, data->original_sender_mac, 6);
|
||||
memcpy(&routing_table.intermediate_target_mac, data->sender_mac, 6);
|
||||
zh_vector_push_back(&_route_vector, &routing_table);
|
||||
}
|
||||
if (zh_vector_get_size(&_route_vector) > _init_config.route_vector_size)
|
||||
{
|
||||
zh_vector_delete_item(&_route_vector, 0);
|
||||
}
|
||||
if (memcmp(queue.data.original_target_mac, _self_mac, 6) == 0)
|
||||
if (memcmp(data->original_target_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for routing response from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X added to the queue.", MAC2STR(queue.data.original_target_mac), MAC2STR(queue.data.original_sender_mac));
|
||||
queue.id = TO_SEND;
|
||||
queue.data.message_type = SEARCH_RESPONSE;
|
||||
memcpy(queue.data.original_target_mac, queue.data.original_sender_mac, 6);
|
||||
memcpy(queue.data.original_sender_mac, _self_mac, 6);
|
||||
queue.data.payload_len = 0;
|
||||
memset(queue.data.payload, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
queue.data.message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
data->message_type = SEARCH_RESPONSE;
|
||||
memcpy(data->original_target_mac, data->original_sender_mac, 6);
|
||||
memcpy(data->original_sender_mac, &_self_mac, 6);
|
||||
data->data_len = 0;
|
||||
memset(data->data, 0, ZH_NETWORK_MAX_MESSAGE_SIZE);
|
||||
data->message_id = abs(esp_random()); // It is not clear why esp_random() sometimes gives negative values.
|
||||
ESP_LOGI(TAG, "Incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
if (xQueueSendToFront(_queue_handle, &queue, portTICK_PERIOD_MS) != pdTRUE)
|
||||
{
|
||||
@ -674,23 +678,23 @@ static void _processing(void *pvParameter)
|
||||
ESP_LOGI(TAG, "System message for routing response from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X is received.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_route_vector); ++i)
|
||||
{
|
||||
_routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(queue.data.original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(data->original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
{
|
||||
zh_vector_delete_item(&_route_vector, i);
|
||||
}
|
||||
}
|
||||
{ // Just to avoid the compiler warning.
|
||||
_routing_table_t routing_table = {0};
|
||||
memcpy(routing_table.original_target_mac, queue.data.original_sender_mac, 6);
|
||||
memcpy(routing_table.intermediate_target_mac, queue.data.sender_mac, 6);
|
||||
routing_table_t routing_table = {0};
|
||||
memcpy(&routing_table.original_target_mac, data->original_sender_mac, 6);
|
||||
memcpy(&routing_table.intermediate_target_mac, data->sender_mac, 6);
|
||||
zh_vector_push_back(&_route_vector, &routing_table);
|
||||
}
|
||||
if (zh_vector_get_size(&_route_vector) > _init_config.route_vector_size)
|
||||
{
|
||||
zh_vector_delete_item(&_route_vector, 0);
|
||||
}
|
||||
if (memcmp(queue.data.original_target_mac, _self_mac, 6) != 0)
|
||||
if (memcmp(data->original_target_mac, &_self_mac, 6) != 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for routing response from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X added to queue for resend to all nodes.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Incoming ESP-NOW data from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -711,7 +715,7 @@ static void _processing(void *pvParameter)
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_response_vector); ++i)
|
||||
{
|
||||
uint32_t *message_id = zh_vector_get_item(&_response_vector, i);
|
||||
if (memcmp(&queue.data.message_id, message_id, sizeof(queue.data.message_id)) == 0)
|
||||
if (memcmp(&data->message_id, message_id, sizeof(data->message_id)) == 0)
|
||||
{
|
||||
zh_vector_delete_item(&_response_vector, i);
|
||||
zh_network_event_on_send_t *on_send = heap_caps_malloc(sizeof(zh_network_event_on_send_t), MALLOC_CAP_8BIT);
|
||||
@ -722,7 +726,7 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
}
|
||||
memset(on_send, 0, sizeof(zh_network_event_on_send_t));
|
||||
memcpy(on_send->mac_addr, queue.data.original_target_mac, 6);
|
||||
memcpy(on_send->mac_addr, data->original_target_mac, 6);
|
||||
on_send->status = ZH_NETWORK_SEND_SUCCESS;
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from confirmation message waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -740,7 +744,7 @@ static void _processing(void *pvParameter)
|
||||
if ((esp_timer_get_time() / 1000 - queue.time) > _init_config.max_waiting_time)
|
||||
{
|
||||
ESP_LOGW(TAG, "Time for waiting confirmation message from MAC %02X:%02X:%02X:%02X:%02X:%02X is expired.", MAC2STR(queue.data.original_target_mac));
|
||||
if (memcmp(queue.data.original_sender_mac, _self_mac, 6) == 0)
|
||||
if (memcmp(data->original_sender_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
zh_network_event_on_send_t *on_send = heap_caps_malloc(sizeof(zh_network_event_on_send_t), MALLOC_CAP_8BIT);
|
||||
if (on_send == NULL)
|
||||
@ -750,7 +754,7 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
}
|
||||
memset(on_send, 0, sizeof(zh_network_event_on_send_t));
|
||||
memcpy(on_send->mac_addr, queue.data.original_target_mac, 6);
|
||||
memcpy(on_send->mac_addr, data->original_target_mac, 6);
|
||||
on_send->status = ZH_NETWORK_SEND_FAIL;
|
||||
ESP_LOGE(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent fail.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from confirmation message waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -771,15 +775,15 @@ static void _processing(void *pvParameter)
|
||||
case WAIT_ROUTE:
|
||||
for (uint16_t i = 0; i < zh_vector_get_size(&_route_vector); ++i)
|
||||
{
|
||||
_routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(queue.data.original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
routing_table_t *routing_table = zh_vector_get_item(&_route_vector, i);
|
||||
if (memcmp(data->original_target_mac, routing_table->original_target_mac, 6) == 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Routing to MAC %02X:%02X:%02X:%02X:%02X:%02X is received.", MAC2STR(queue.data.original_target_mac));
|
||||
if (queue.data.message_type == UNICAST)
|
||||
if (data->message_type == UNICAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from routing waiting list and added to queue.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == DELIVERY_CONFIRM)
|
||||
if (data->message_type == DELIVERY_CONFIRM)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for message receiving confirmation from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from routing waiting list and added to queue.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
@ -797,7 +801,7 @@ static void _processing(void *pvParameter)
|
||||
if ((esp_timer_get_time() / 1000 - queue.time) > _init_config.max_waiting_time)
|
||||
{
|
||||
ESP_LOGW(TAG, "Time for waiting routing to MAC %02X:%02X:%02X:%02X:%02X:%02X is expired.", MAC2STR(queue.data.original_target_mac));
|
||||
if (memcmp(queue.data.original_sender_mac, _self_mac, 6) == 0)
|
||||
if (memcmp(data->original_sender_mac, &_self_mac, 6) == 0)
|
||||
{
|
||||
zh_network_event_on_send_t *on_send = heap_caps_malloc(sizeof(zh_network_event_on_send_t), MALLOC_CAP_8BIT);
|
||||
if (on_send == NULL)
|
||||
@ -807,7 +811,7 @@ static void _processing(void *pvParameter)
|
||||
break;
|
||||
}
|
||||
memset(on_send, 0, sizeof(zh_network_event_on_send_t));
|
||||
memcpy(on_send->mac_addr, queue.data.original_target_mac, 6);
|
||||
memcpy(on_send->mac_addr, data->original_target_mac, 6);
|
||||
on_send->status = ZH_NETWORK_SEND_FAIL;
|
||||
ESP_LOGE(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X sent fail.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from routing waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
@ -819,11 +823,11 @@ static void _processing(void *pvParameter)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (queue.data.message_type == UNICAST)
|
||||
if (data->message_type == UNICAST)
|
||||
{
|
||||
ESP_LOGI(TAG, "Unicast message from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from routing waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
if (queue.data.message_type == DELIVERY_CONFIRM)
|
||||
if (data->message_type == DELIVERY_CONFIRM)
|
||||
{
|
||||
ESP_LOGI(TAG, "System message for message receiving confirmation from MAC %02X:%02X:%02X:%02X:%02X:%02X to MAC %02X:%02X:%02X:%02X:%02X:%02X removed from routing waiting list.", MAC2STR(queue.data.original_sender_mac), MAC2STR(queue.data.original_target_mac));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ In an existing project, run the following command to install the component:
|
||||
|
||||
```text
|
||||
cd ../your_project/components
|
||||
git clone http://git.zh.com.ru/alexey.zholtikov/zh_onewire.git
|
||||
git clone https://github.com/aZholtikov/zh_onewire.git
|
||||
```
|
||||
|
||||
In the application, add the component:
|
||||
|
@ -35,6 +35,7 @@ extern "C"
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if reset was successful
|
||||
* - ESP_ERR_INVALID_STATE if 1-Wire bus not initialized
|
||||
* - ESP_ERR_INVALID_RESPONSE if the bus is busy
|
||||
* - ESP_ERR_TIMEOUT if there are no 1-Wire devices available on the bus or the devices are not responding
|
||||
*/
|
||||
@ -44,23 +45,22 @@ extern "C"
|
||||
* @brief Send one byte to 1-Wire device.
|
||||
*
|
||||
* @param[in] byte Byte value.
|
||||
*
|
||||
*/
|
||||
void zh_onewire_send_byte(uint8_t byte);
|
||||
|
||||
/**
|
||||
* @brief Read one byte from 1-Wire device.
|
||||
*
|
||||
* @return
|
||||
* - Byte value
|
||||
* @return Byte value
|
||||
*/
|
||||
uint8_t zh_onewire_read_byte(void);
|
||||
|
||||
/**
|
||||
* @brief Initializes the bus master to address all 1-Wire devices on the bus.
|
||||
* @brief Initialize the bus master to address all 1-Wire devices on the bus.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if initialization was successful
|
||||
* - ESP_ERR_INVALID_STATE if 1-Wire bus not initialized
|
||||
* - ESP_FAIL if there are no 1-Wire devices available on the bus or the devices are not responding
|
||||
*/
|
||||
esp_err_t zh_onewire_skip_rom(void);
|
||||
@ -72,6 +72,7 @@ extern "C"
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if read was successful
|
||||
* - ESP_ERR_INVALID_STATE if 1-Wire bus not initialized
|
||||
* - ESP_FAIL if there are no 1-Wire devices available on the bus or the devices are not responding
|
||||
* - ESP_ERR_INVALID_CRC if more than one 1-Wire device is present on the bus
|
||||
*/
|
||||
@ -84,6 +85,7 @@ extern "C"
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if initialization was successful
|
||||
* - ESP_ERR_INVALID_STATE if 1-Wire bus not initialized
|
||||
* - ESP_FAIL if there are no 1-Wire devices available on the bus or the devices are not responding
|
||||
*/
|
||||
esp_err_t zh_onewire_match_rom(const uint8_t *data);
|
||||
@ -93,6 +95,7 @@ extern "C"
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if initialization was successful
|
||||
* - ESP_ERR_INVALID_STATE if 1-Wire bus not initialized
|
||||
*/
|
||||
esp_err_t zh_onewire_search_rom_init(void);
|
||||
|
||||
@ -103,7 +106,7 @@ extern "C"
|
||||
*
|
||||
* @return
|
||||
* - Pointer to a buffer containing an eight-byte rom value
|
||||
* - NULL if the search is terminated or if there are no 1-Wire devices available on the bus or the devices are not responding
|
||||
* - NULL if the search is terminated or if there are no 1-Wire devices available on the bus or the devices are not responding or if 1-Wire bus not initialized
|
||||
*/
|
||||
uint8_t *zh_onewire_search_rom_next(void);
|
||||
|
||||
|
@ -1 +1 @@
|
||||
1.1.4
|
||||
1.0.0
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file
|
||||
* The main code of the zh_onewire component.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zh_onewire.h"
|
||||
@ -38,6 +39,7 @@ static const char *TAG = "zh_onewire";
|
||||
static uint8_t _pin;
|
||||
static uint8_t _rom[8];
|
||||
static uint8_t _rom_fork_bit = 0xFF;
|
||||
static bool _is_initialized = false;
|
||||
|
||||
static const uint8_t _rom_crc_table[] = {
|
||||
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
|
||||
@ -72,6 +74,7 @@ esp_err_t zh_onewire_init(const uint8_t pin)
|
||||
ESP_LOGE(TAG, "Onewire initialization fail. Incorrect GPIO number.");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
_is_initialized = true;
|
||||
ESP_LOGI(TAG, "Onewire initialization success.");
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -79,6 +82,11 @@ esp_err_t zh_onewire_init(const uint8_t pin)
|
||||
esp_err_t zh_onewire_reset(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Onewire reset begin.");
|
||||
if (_is_initialized == false)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire reset fail. Onewire not initialized.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (gpio_get_level(_pin) != 1)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire reset fail. Bus is busy.");
|
||||
@ -129,6 +137,11 @@ void zh_onewire_send_byte(uint8_t byte)
|
||||
esp_err_t zh_onewire_skip_rom(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Onewire skip ROM begin.");
|
||||
if (_is_initialized == false)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire skip ROM fail. Onewire not initialized.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (zh_onewire_reset() != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire skip ROM fail.");
|
||||
@ -142,6 +155,11 @@ esp_err_t zh_onewire_skip_rom(void)
|
||||
esp_err_t zh_onewire_read_rom(uint8_t *buf)
|
||||
{
|
||||
ESP_LOGI(TAG, "Onewire read ROM begin.");
|
||||
if (_is_initialized == false)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire read ROM fail. Onewire not initialized.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (zh_onewire_reset() != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire read ROM fail.");
|
||||
@ -167,6 +185,11 @@ esp_err_t zh_onewire_read_rom(uint8_t *buf)
|
||||
esp_err_t zh_onewire_match_rom(const uint8_t *data)
|
||||
{
|
||||
ESP_LOGI(TAG, "Onewire match ROM begin.");
|
||||
if (_is_initialized == false)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire match ROM fail. Onewire not initialized.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (zh_onewire_reset() != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire match ROM fail.");
|
||||
@ -183,6 +206,10 @@ esp_err_t zh_onewire_match_rom(const uint8_t *data)
|
||||
|
||||
esp_err_t zh_onewire_search_rom_init(void)
|
||||
{
|
||||
if (_is_initialized == false)
|
||||
{
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
for (uint8_t i = 0; i < 8; ++i)
|
||||
{
|
||||
_rom[i] = 0;
|
||||
@ -194,6 +221,11 @@ esp_err_t zh_onewire_search_rom_init(void)
|
||||
uint8_t *zh_onewire_search_rom_next(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Onewire search ROM begin.");
|
||||
if (_is_initialized == false)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire search ROM fail. Onewire not initialized.");
|
||||
return NULL;
|
||||
}
|
||||
if (_rom_fork_bit == 0xFF)
|
||||
{
|
||||
ESP_LOGE(TAG, "Onewire search ROM not initialized.");
|
||||
|
@ -46,7 +46,7 @@ char example[10] = {0};
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// esp_log_level_set("zh_vector", ESP_LOG_NONE);
|
||||
esp_log_level_set("zh_vector", ESP_LOG_NONE);
|
||||
zh_vector_init(&vector, sizeof(example), false);
|
||||
printf("Initial vector size is: %d\n", zh_vector_get_size(&vector));
|
||||
strcpy(example, "Item 1");
|
||||
|
@ -1 +1 @@
|
||||
1.4.6
|
||||
1.0.0
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file
|
||||
* The main code of the zh_vector component.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zh_vector.h"
|
||||
|
@ -236,12 +236,15 @@ void zh_sensor_deep_sleep(sensor_config_t *sensor_config)
|
||||
|
||||
void zh_send_sensor_hardware_config_message(const sensor_config_t *sensor_config)
|
||||
{
|
||||
zh_config_message_t config_message = {0};
|
||||
config_message = (zh_config_message_t)sensor_config->hardware_config;
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_HARDWARE;
|
||||
data.payload_data = (zh_payload_data_t)config_message;
|
||||
data.payload_data.config_message.sensor_hardware_config_message.sensor_type = sensor_config->hardware_config.sensor_type;
|
||||
data.payload_data.config_message.sensor_hardware_config_message.sensor_pin_1 = sensor_config->hardware_config.sensor_pin_1;
|
||||
data.payload_data.config_message.sensor_hardware_config_message.sensor_pin_2 = sensor_config->hardware_config.sensor_pin_2;
|
||||
data.payload_data.config_message.sensor_hardware_config_message.power_pin = sensor_config->hardware_config.power_pin;
|
||||
data.payload_data.config_message.sensor_hardware_config_message.measurement_frequency = sensor_config->hardware_config.measurement_frequency;
|
||||
data.payload_data.config_message.sensor_hardware_config_message.battery_power = sensor_config->hardware_config.battery_power;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
}
|
||||
|
||||
@ -249,23 +252,21 @@ void zh_send_sensor_attributes_message_task(void *pvParameter)
|
||||
{
|
||||
sensor_config_t *sensor_config = pvParameter;
|
||||
const esp_app_desc_t *app_info = get_app_description();
|
||||
zh_attributes_message_t attributes_message = {0};
|
||||
attributes_message.chip_type = ZH_CHIP_TYPE;
|
||||
attributes_message.sensor_type = sensor_config->hardware_config.sensor_type;
|
||||
strcpy(attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
|
||||
attributes_message.cpu_frequency = ZH_CPU_FREQUENCY;
|
||||
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);
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_ATTRIBUTES;
|
||||
data.payload_data.attributes_message.chip_type = ZH_CHIP_TYPE;
|
||||
data.payload_data.attributes_message.sensor_type = sensor_config->hardware_config.sensor_type;
|
||||
strcpy(data.payload_data.attributes_message.flash_size, CONFIG_ESPTOOLPY_FLASHSIZE);
|
||||
data.payload_data.attributes_message.cpu_frequency = ZH_CPU_FREQUENCY;
|
||||
data.payload_data.attributes_message.reset_reason = (uint8_t)esp_reset_reason();
|
||||
strcpy(data.payload_data.attributes_message.app_name, app_info->project_name);
|
||||
strcpy(data.payload_data.attributes_message.app_version, app_info->version);
|
||||
for (;;)
|
||||
{
|
||||
attributes_message.heap_size = esp_get_free_heap_size();
|
||||
attributes_message.min_heap_size = esp_get_minimum_free_heap_size();
|
||||
attributes_message.uptime = esp_timer_get_time() / 1000000;
|
||||
data.payload_data = (zh_payload_data_t)attributes_message;
|
||||
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(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
if (sensor_config->hardware_config.battery_power == true)
|
||||
{
|
||||
@ -282,43 +283,35 @@ uint8_t zh_send_sensor_config_message(const sensor_config_t *sensor_config)
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_CONFIG;
|
||||
zh_config_message_t config_message = {0};
|
||||
zh_sensor_config_message_t sensor_config_message = {0};
|
||||
sensor_config_message.suggested_display_precision = 1;
|
||||
sensor_config_message.expire_after = sensor_config->hardware_config.measurement_frequency * 3;
|
||||
sensor_config_message.enabled_by_default = true;
|
||||
sensor_config_message.force_update = true;
|
||||
sensor_config_message.qos = 2;
|
||||
sensor_config_message.retain = true;
|
||||
data.payload_data.config_message.sensor_config_message.suggested_display_precision = 1;
|
||||
data.payload_data.config_message.sensor_config_message.expire_after = sensor_config->hardware_config.measurement_frequency * 3;
|
||||
data.payload_data.config_message.sensor_config_message.enabled_by_default = true;
|
||||
data.payload_data.config_message.sensor_config_message.force_update = true;
|
||||
data.payload_data.config_message.sensor_config_message.qos = 2;
|
||||
data.payload_data.config_message.sensor_config_message.retain = true;
|
||||
char *unit_of_measurement = NULL;
|
||||
switch (sensor_config->hardware_config.sensor_type)
|
||||
{
|
||||
case HAST_DS18B20:
|
||||
sensor_config_message.unique_id = 1;
|
||||
sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
|
||||
data.payload_data.config_message.sensor_config_message.unique_id = 1;
|
||||
data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
|
||||
unit_of_measurement = "°C";
|
||||
strcpy(sensor_config_message.unit_of_measurement, unit_of_measurement);
|
||||
config_message = (zh_config_message_t)sensor_config_message;
|
||||
data.payload_data = (zh_payload_data_t)config_message;
|
||||
strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
++messages_quantity;
|
||||
break;
|
||||
case HAST_DHT11:
|
||||
case HAST_DHT22:
|
||||
sensor_config_message.unique_id = 1;
|
||||
sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
|
||||
data.payload_data.config_message.sensor_config_message.unique_id = 1;
|
||||
data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
|
||||
unit_of_measurement = "°C";
|
||||
strcpy(sensor_config_message.unit_of_measurement, unit_of_measurement);
|
||||
config_message = (zh_config_message_t)sensor_config_message;
|
||||
data.payload_data = (zh_payload_data_t)config_message;
|
||||
strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
++messages_quantity;
|
||||
sensor_config_message.unique_id = 2;
|
||||
sensor_config_message.sensor_device_class = HASDC_HUMIDITY;
|
||||
data.payload_data.config_message.sensor_config_message.unique_id = 2;
|
||||
data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_HUMIDITY;
|
||||
unit_of_measurement = "%";
|
||||
strcpy(sensor_config_message.unit_of_measurement, unit_of_measurement);
|
||||
config_message = (zh_config_message_t)sensor_config_message;
|
||||
data.payload_data = (zh_payload_data_t)config_message;
|
||||
strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
++messages_quantity;
|
||||
break;
|
||||
@ -333,12 +326,10 @@ void zh_send_sensor_status_message_task(void *pvParameter)
|
||||
sensor_config_t *sensor_config = pvParameter;
|
||||
float humidity = 0.0;
|
||||
float temperature = 0.0;
|
||||
zh_sensor_status_message_t sensor_status_message = {0};
|
||||
sensor_status_message.sensor_type = sensor_config->hardware_config.sensor_type;
|
||||
zh_status_message_t status_message = {0};
|
||||
zh_espnow_data_t data = {0};
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_STATE;
|
||||
data.payload_data.status_message.sensor_status_message.sensor_type = sensor_config->hardware_config.sensor_type;
|
||||
for (;;)
|
||||
{
|
||||
if (sensor_config->hardware_config.power_pin != ZH_NOT_USED && sensor_config->hardware_config.sensor_pin_1 != ZH_NOT_USED)
|
||||
@ -353,7 +344,7 @@ void zh_send_sensor_status_message_task(void *pvParameter)
|
||||
switch (zh_ds18b20_read(NULL, &temperature))
|
||||
{
|
||||
case ESP_OK:
|
||||
sensor_status_message.temperature = temperature;
|
||||
data.payload_data.status_message.sensor_status_message.temperature = temperature;
|
||||
break;
|
||||
case ESP_FAIL:
|
||||
if (sensor_config->hardware_config.battery_power == false)
|
||||
@ -379,8 +370,8 @@ void zh_send_sensor_status_message_task(void *pvParameter)
|
||||
switch (zh_dht_read(&sensor_config->dht_handle, &humidity, &temperature))
|
||||
{
|
||||
case ESP_OK:
|
||||
sensor_status_message.humidity = humidity;
|
||||
sensor_status_message.temperature = temperature;
|
||||
data.payload_data.status_message.sensor_status_message.humidity = humidity;
|
||||
data.payload_data.status_message.sensor_status_message.temperature = temperature;
|
||||
break;
|
||||
case ESP_ERR_INVALID_RESPONSE:
|
||||
if (sensor_config->hardware_config.battery_power == false)
|
||||
@ -410,8 +401,6 @@ void zh_send_sensor_status_message_task(void *pvParameter)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
status_message = (zh_status_message_t)sensor_status_message;
|
||||
data.payload_data = (zh_payload_data_t)status_message;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
if (sensor_config->hardware_config.power_pin != ZH_NOT_USED && sensor_config->hardware_config.sensor_pin_1 != ZH_NOT_USED)
|
||||
{
|
||||
@ -429,7 +418,6 @@ void zh_send_sensor_status_message_task(void *pvParameter)
|
||||
void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
sensor_config_t *sensor_config = arg;
|
||||
zh_espnow_data_t data = {0};
|
||||
switch (event_id)
|
||||
{
|
||||
#ifdef CONFIG_NETWORK_TYPE_DIRECT
|
||||
@ -447,14 +435,14 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
goto ZH_NETWORK_EVENT_HANDLER_EXIT;
|
||||
}
|
||||
#endif
|
||||
memcpy(&data, recv_data->data, recv_data->data_len);
|
||||
switch (data.device_type)
|
||||
zh_espnow_data_t *data = (zh_espnow_data_t *)recv_data->data;
|
||||
switch (data->device_type)
|
||||
{
|
||||
case ZHDT_GATEWAY:
|
||||
switch (data.payload_type)
|
||||
switch (data->payload_type)
|
||||
{
|
||||
case ZHPT_KEEP_ALIVE:
|
||||
if (data.payload_data.keep_alive_message.online_status == ZH_ONLINE)
|
||||
if (data->payload_data.keep_alive_message.online_status == ZH_ONLINE)
|
||||
{
|
||||
if (sensor_config->gateway_is_available == false)
|
||||
{
|
||||
@ -483,29 +471,31 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
}
|
||||
break;
|
||||
case ZHPT_HARDWARE:
|
||||
sensor_config->hardware_config = data.payload_data.config_message.sensor_hardware_config_message;
|
||||
sensor_config->hardware_config.sensor_type = data->payload_data.config_message.sensor_hardware_config_message.sensor_type;
|
||||
sensor_config->hardware_config.sensor_pin_1 = data->payload_data.config_message.sensor_hardware_config_message.sensor_pin_1;
|
||||
sensor_config->hardware_config.sensor_pin_2 = data->payload_data.config_message.sensor_hardware_config_message.sensor_pin_2;
|
||||
sensor_config->hardware_config.power_pin = data->payload_data.config_message.sensor_hardware_config_message.power_pin;
|
||||
sensor_config->hardware_config.measurement_frequency = data->payload_data.config_message.sensor_hardware_config_message.measurement_frequency;
|
||||
sensor_config->hardware_config.battery_power = data->payload_data.config_message.sensor_hardware_config_message.battery_power;
|
||||
zh_save_config(sensor_config);
|
||||
esp_restart();
|
||||
break;
|
||||
case ZHPT_UPDATE:;
|
||||
const esp_app_desc_t *app_info = get_app_description();
|
||||
sensor_config->update_partition = esp_ota_get_next_update_partition(NULL);
|
||||
zh_espnow_ota_message_t espnow_ota_message = {0};
|
||||
espnow_ota_message.chip_type = ZH_CHIP_TYPE;
|
||||
strcpy(espnow_ota_message.app_version, app_info->version);
|
||||
strcpy(data->payload_data.ota_message.espnow_ota_data.app_version, app_info->version);
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
char *app_name = (char *)heap_caps_malloc(strlen(app_info->project_name) + 6, MALLOC_CAP_8BIT);
|
||||
memset(app_name, 0, strlen(app_info->project_name) + 6);
|
||||
sprintf(app_name, "%s.app%d", app_info->project_name, sensor_config->update_partition->subtype - ESP_PARTITION_SUBTYPE_APP_OTA_0 + 1);
|
||||
strcpy(espnow_ota_message.app_name, app_name);
|
||||
strcpy(data->payload_data.ota_message.espnow_ota_data.app_name, app_name);
|
||||
heap_caps_free(app_name);
|
||||
#else
|
||||
strcpy(espnow_ota_message.app_name, app_info->project_name);
|
||||
strcpy(data->payload_data.ota_message.espnow_ota_data.app_name, app_info->project_name);
|
||||
#endif
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_UPDATE;
|
||||
data.payload_data = (zh_payload_data_t)espnow_ota_message;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
data->device_type = ZHDT_SENSOR;
|
||||
data->payload_type = ZHPT_UPDATE;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
case ZHPT_UPDATE_BEGIN:
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
@ -514,19 +504,19 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
esp_ota_begin(sensor_config->update_partition, OTA_SIZE_UNKNOWN, (esp_ota_handle_t *)&sensor_config->update_handle);
|
||||
#endif
|
||||
sensor_config->ota_message_part_number = 1;
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_UPDATE_PROGRESS;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
data->device_type = ZHDT_SENSOR;
|
||||
data->payload_type = ZHPT_UPDATE_PROGRESS;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
case ZHPT_UPDATE_PROGRESS:
|
||||
if (sensor_config->ota_message_part_number == data.payload_data.espnow_ota_message.part)
|
||||
if (sensor_config->ota_message_part_number == data->payload_data.ota_message.espnow_ota_message.part)
|
||||
{
|
||||
++sensor_config->ota_message_part_number;
|
||||
esp_ota_write(sensor_config->update_handle, (const void *)data.payload_data.espnow_ota_message.data, data.payload_data.espnow_ota_message.data_len);
|
||||
esp_ota_write(sensor_config->update_handle, (const void *)data->payload_data.ota_message.espnow_ota_message.data, data->payload_data.ota_message.espnow_ota_message.data_len);
|
||||
}
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_UPDATE_PROGRESS;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
data->device_type = ZHDT_SENSOR;
|
||||
data->payload_type = ZHPT_UPDATE_PROGRESS;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
case ZHPT_UPDATE_ERROR:
|
||||
esp_ota_end(sensor_config->update_handle);
|
||||
@ -534,15 +524,15 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
case ZHPT_UPDATE_END:
|
||||
if (esp_ota_end(sensor_config->update_handle) != ESP_OK)
|
||||
{
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_UPDATE_FAIL;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
data->device_type = ZHDT_SENSOR;
|
||||
data->payload_type = ZHPT_UPDATE_FAIL;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
break;
|
||||
}
|
||||
esp_ota_set_boot_partition(sensor_config->update_partition);
|
||||
data.device_type = ZHDT_SENSOR;
|
||||
data.payload_type = ZHPT_UPDATE_SUCCESS;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
|
||||
data->device_type = ZHDT_SENSOR;
|
||||
data->payload_type = ZHPT_UPDATE_SUCCESS;
|
||||
zh_send_message(sensor_config->gateway_mac, (uint8_t *)data, sizeof(zh_espnow_data_t));
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
break;
|
||||
|
@ -47,31 +47,26 @@
|
||||
#define get_app_description() esp_app_get_description()
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Frequency of transmission of keep alive messages to the gateway (in seconds).
|
||||
*/
|
||||
#define ZH_SENSOR_ATTRIBUTES_MESSAGE_FREQUENCY 60
|
||||
#define ZH_SENSOR_ATTRIBUTES_MESSAGE_FREQUENCY 60 // Frequency of transmission of keep alive messages to the gateway (in seconds).
|
||||
|
||||
/**
|
||||
* @brief Prioritize the task of sending messages to the gateway.
|
||||
*/
|
||||
#define ZH_MESSAGE_TASK_PRIORITY 2
|
||||
#define ZH_MESSAGE_TASK_PRIORITY 2 // 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.
|
||||
|
||||
/**
|
||||
* @brief The stack size of the task of sending messages to the gateway.
|
||||
*/
|
||||
#define ZH_MESSAGE_STACK_SIZE 2048
|
||||
|
||||
/**
|
||||
* @brief Structure of data exchange between tasks, functions and event handlers.
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct // Structure of data exchange between tasks, functions and event handlers.
|
||||
{
|
||||
zh_sensor_hardware_config_message_t hardware_config; // Storage structure of sensor hardware configuration data. @note
|
||||
struct // Storage structure of sensor hardware configuration data.
|
||||
{
|
||||
ha_sensor_type_t sensor_type; // Sensor types.
|
||||
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).
|
||||
} hardware_config;
|
||||
volatile bool gateway_is_available; // Gateway availability status flag. @note Used to control the tasks when the gateway connection is established / lost. Used only when external powered.
|
||||
uint8_t gateway_mac[6]; // Gateway MAC address. @note Used only when external powered.
|
||||
uint8_t sent_message_quantity; // System counter for the number of sended messages. @note Used only when powered by battery.
|
||||
zh_dht_handle_t dht_handle; // Unique DTH11/22 sensor handle. @note
|
||||
zh_dht_handle_t dht_handle; // Unique DTH11/22 sensor handle.
|
||||
TaskHandle_t attributes_message_task; // Unique task handle for zh_send_sensor_attributes_message_task(). @note Used only when external powered.
|
||||
TaskHandle_t status_message_task; // Unique task handle for zh_send_sensor_status_message_task(). @note Used only when external powered.
|
||||
const esp_partition_t *update_partition; // Unique handle for next OTA update partition. @note Used only when external powered.
|
||||
|
@ -1 +1 @@
|
||||
1.0.0
|
||||
1.0.1
|
Loading…
x
Reference in New Issue
Block a user