This commit is contained in:
2024-07-05 09:10:53 +03:00
parent cebee7859e
commit dd255e6a29
6 changed files with 39 additions and 12 deletions

3
.gitmodules vendored
View File

@ -22,3 +22,6 @@
[submodule "components/zh_bh1750"] [submodule "components/zh_bh1750"]
path = components/zh_bh1750 path = components/zh_bh1750
url = https://github.com/aZholtikov/zh_bh1750 url = https://github.com/aZholtikov/zh_bh1750
[submodule "components/zh_aht"]
path = components/zh_aht
url = https://github.com/aZholtikov/zh_aht

View File

@ -10,11 +10,12 @@ ESP-NOW based sensor for ESP32 ESP-IDF and ESP8266 RTOS SDK.
## Features ## Features
1. Supported 1-wire sensors: 1. Supported 1-wire sensors:
1. DS18B20 1. [DS18B20](https://github.com/aZholtikov/zh_ds18b20)
2. DHT11/DHT22/AM2302/AM2320 2. [DHT11/DHT22/AM2302/AM2320](https://github.com/aZholtikov/zh_dht)
2. Supported I2C sensors: 2. Supported I2C sensors:
1. AM2320 1. [AM2320](https://github.com/aZholtikov/zh_dht)
2. BH1750 2. [BH1750](https://github.com/aZholtikov/zh_bh1750)
3. [AHT20/AHT21](https://github.com/aZholtikov/zh_aht)
3. Optional support sensor power management (for 1-wire sensors only). 3. Optional support sensor power management (for 1-wire sensors only).
4. Automatically adds sensor configuration to Home Assistan via MQTT discovery as a sensor. 4. Automatically adds sensor configuration to Home Assistan via MQTT discovery as a sensor.
5. Update firmware from HTTPS server via ESP-NOW. 5. Update firmware from HTTPS server via ESP-NOW.
@ -33,7 +34,7 @@ ESP-NOW based sensor for ESP32 ESP-IDF and ESP8266 RTOS SDK.
MQTT configuration message should filled according to the template "X1,X2,X3,X4,X5,X6". Where: MQTT configuration message should filled according to the template "X1,X2,X3,X4,X5,X6". Where:
1. X1 - Sensor type. 1 for DS18B20, 8 for DHT, 9 for BH1750. 1. X1 - Sensor type. 1 for DS18B20, 2 for AHT, 8 for DHT, 9 for BH1750.
2. X2 - Sensor GPIO number 1 (main pin for 1-wire sensors, SDA pin for I2C sensors). 0 - 48 (according to the module used), 255 if not used. 2. X2 - Sensor GPIO number 1 (main pin for 1-wire sensors, SDA pin for I2C sensors). 0 - 48 (according to the module used), 255 if not used.
3. X3 - Sensor GPIO number 2 (SCL pin for I2C sensors). 0 - 48 (according to the module used), 255 if not used. 3. X3 - Sensor GPIO number 2 (SCL pin for I2C sensors). 0 - 48 (according to the module used), 255 if not used.
4. X4 - Power GPIO number (if using sensor power control). 0 - 48 (according to the module used), 255 if not used. 4. X4 - Power GPIO number (if using sensor power control). 0 - 48 (according to the module used), 255 if not used.

1
components/zh_aht Submodule

Submodule components/zh_aht added at 735dda94d3

View File

@ -30,19 +30,21 @@ menu "ZH ESP-NOW Sensor Configuration"
bool "DS18B20" bool "DS18B20"
config SENSOR_TYPE_DHT config SENSOR_TYPE_DHT
bool "DHT" bool "DHT"
config SENSOR_TYPE_AHT
bool "AHT"
config SENSOR_TYPE_BH1750 config SENSOR_TYPE_BH1750
bool "BH1750" bool "BH1750"
endchoice endchoice
choice CONNECTION_TYPE choice CONNECTION_TYPE
depends on SENSOR_TYPE_DS18B20 || SENSOR_TYPE_DHT || SENSOR_TYPE_BH1750 depends on SENSOR_TYPE_DS18B20 || SENSOR_TYPE_DHT || SENSOR_TYPE_BH1750 || SENSOR_TYPE_AHT
prompt "Connection type" prompt "Connection type"
default CONNECTION_TYPE_ONEWIRE default CONNECTION_TYPE_ONEWIRE
config CONNECTION_TYPE_ONEWIRE config CONNECTION_TYPE_ONEWIRE
depends on SENSOR_TYPE_DS18B20 || SENSOR_TYPE_DHT depends on SENSOR_TYPE_DS18B20 || SENSOR_TYPE_DHT
bool "ONE WIRE" bool "ONE WIRE"
config CONNECTION_TYPE_I2C config CONNECTION_TYPE_I2C
depends on SENSOR_TYPE_DHT || SENSOR_TYPE_BH1750 depends on SENSOR_TYPE_DHT || SENSOR_TYPE_BH1750 || SENSOR_TYPE_AHT
bool "I2C" bool "I2C"
endchoice endchoice
@ -63,7 +65,7 @@ menu "ZH ESP-NOW Sensor Configuration"
Sensor GPIO (SCL pin for I2C sensors). Sensor GPIO (SCL pin for I2C sensors).
config MEASUREMENT_FREQUENCY config MEASUREMENT_FREQUENCY
depends on SENSOR_TYPE_DS18B20 || SENSOR_TYPE_DHT || SENSOR_TYPE_BH1750 depends on CONNECTION_TYPE_ONEWIRE || CONNECTION_TYPE_I2C
int "Measurement frequency" int "Measurement frequency"
range 1 65536 range 1 65536
default 300 default 300

View File

@ -76,6 +76,8 @@ void zh_load_config(sensor_config_t *sensor_config)
sensor_config->hardware_config.sensor_type = HAST_DS18B20; sensor_config->hardware_config.sensor_type = HAST_DS18B20;
#elif CONFIG_SENSOR_TYPE_DHT #elif CONFIG_SENSOR_TYPE_DHT
sensor_config->hardware_config.sensor_type = HAST_DHT; sensor_config->hardware_config.sensor_type = HAST_DHT;
#elif CONFIG_SENSOR_TYPE_AHT
sensor_config->hardware_config.sensor_type = HAST_AHT;
#elif CONFIG_SENSOR_TYPE_BH1750 #elif CONFIG_SENSOR_TYPE_BH1750
sensor_config->hardware_config.sensor_type = HAST_BH1750; sensor_config->hardware_config.sensor_type = HAST_BH1750;
#else #else
@ -254,7 +256,17 @@ void zh_sensor_init(sensor_config_t *sensor_config)
break; break;
case HAST_BME680: // For future development. case HAST_BME680: // For future development.
break; break;
case HAST_AHT: // For future development. case HAST_AHT:;
zh_aht_init_config_t aht_init_config = ZH_AHT_INIT_CONFIG_DEFAULT();
#ifdef CONFIG_IDF_TARGET_ESP8266
aht_init_config.i2c_port = I2C_PORT;
#else
aht_init_config.i2c_handle = sensor_config->i2c_bus_handle;
#endif
if (zh_aht_init(&aht_init_config) != ESP_OK)
{
goto ZH_SENSOR_ERROR;
}
break; break;
case HAST_SHT: // For future development. case HAST_SHT: // For future development.
break; break;
@ -371,7 +383,7 @@ uint8_t zh_send_sensor_config_message(const sensor_config_t *sensor_config)
++messages_quantity; ++messages_quantity;
break; break;
case HAST_DHT: case HAST_DHT:
case HAST_AHT: // For future development. case HAST_AHT:
case HAST_SHT: // For future development. case HAST_SHT: // For future development.
case HAST_HTU21D: // For future development. case HAST_HTU21D: // For future development.
case HAST_HDC1080: // For future development. case HAST_HDC1080: // For future development.
@ -470,7 +482,14 @@ void zh_send_sensor_status_message_task(void *pvParameter)
break; break;
case HAST_BME680: // For future development. case HAST_BME680: // For future development.
break; break;
case HAST_AHT: // For future development. case HAST_AHT:
err = zh_aht_read(&humidity, &temperature);
if (err == ESP_OK)
{
data.payload_data.status_message.sensor_status_message.humidity = humidity;
data.payload_data.status_message.sensor_status_message.temperature = temperature;
data.payload_data.status_message.sensor_status_message.voltage = 3.3; // For future development.
}
break; break;
case HAST_SHT: // For future development. case HAST_SHT: // For future development.
break; break;

View File

@ -12,6 +12,7 @@
#include "zh_ds18b20.h" #include "zh_ds18b20.h"
#include "zh_dht.h" #include "zh_dht.h"
#include "zh_bh1750.h" #include "zh_bh1750.h"
#include "zh_aht.h"
#include "zh_config.h" #include "zh_config.h"
#ifdef CONFIG_NETWORK_TYPE_DIRECT #ifdef CONFIG_NETWORK_TYPE_DIRECT