Skip to content

Commit 47785cd

Browse files
authored
Merge pull request #2 from lsw031105guge-bit/main
Add:soil_sensor
2 parents 23375da + cf574d2 commit 47785cd

5 files changed

Lines changed: 641 additions & 0 deletions

File tree

arduino.zip

230 KB
Binary file not shown.

arduino/SeeedHADiscovery.zip

177 KB
Binary file not shown.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Temperature and Humidity Sensor Example
2+
3+
Real-time reporting of soil moisture data to Home Assistant. Supports real soil moisture sensors (such as Seeed Studio soil sensors) and simulated data.
4+
5+
## Features
6+
7+
- **Soil Moisture Sensor** (displayed in %)
8+
- **Configurable Update Interval** (adjust data reporting frequency as needed)
9+
- **Optional Real Soil Moisture Sensor Support** (Capacitive/Resistive)
10+
- **Simulated Data Mode** (for hardware-free testing scenarios)
11+
- **WiFi Provisioning**: Web-based WiFi configuration (no hard-coded credentials required)
12+
13+
## Hardware Requirements
14+
15+
- XIAO ESP32-C3/C5/C6/S3 or other ESP32 development boards
16+
- Soil Moisture Sensor (optional - simulated data can be used, Seeed Studio soil sensor recommended)
17+
18+
> **Note**: XIAO ESP32-C5 supports dual-band WiFi (2.4GHz and 5GHz)
19+
20+
### Sensor Pin Connections
21+
22+
| Function | Pin | Description |
23+
| :--- | :--- | :--- |
24+
| Excitation Signal (EX) | **D3** | Sends excitation square wave signal |
25+
| Analog Signal (SIG) | **D1** | Reads soil capacitance response voltage |
26+
| VCC | 3.3V | Power supply (Do not connect to 5V) |
27+
| GND | GND | Ground |
28+
29+
### LED Indicator Connections (Common Cathode Connection)
30+
31+
| LED Color | Pin | Status Definition |
32+
| :--- | :--- | :--- |
33+
| Green | **D8** | Moisture > 60% (Wet) |
34+
| Yellow | **D10** | Moisture 30%-60% (Moderate) |
35+
| Red | **D9** | Moisture < 30% (Dry) |
36+
37+
## Software Dependencies
38+
39+
### Required Libraries
40+
41+
Install via Arduino Library Manager:
42+
43+
| Library Name | Author | Description |
44+
| :--- | :--- | :--- |
45+
| **ArduinoJson** | Benoit Blanchon | JSON parsing |
46+
| **WebSockets** | Markus Sattler | WebSocket communication |
47+
48+
### SeeedHADiscovery Library
49+
50+
Manually install from [GitHub](https://github.com/limengdu/SeeedHADiscovery).
51+
52+
## Quick Start
53+
54+
### 1. WiFi Configuration
55+
56+
**Method A: WiFi Provisioning (Recommended)**
57+
58+
WiFi provisioning is enabled by default. Upon first startup:
59+
60+
1. Device creates AP hotspot: `Seeed_TempHum_AP`
61+
2. Connect your phone/computer to this AP
62+
3. Browser opens automatically, or manually visit `http://192.168.4.1`
63+
4. Select your WiFi network and enter password
64+
5. Device restarts and connects to your WiFi
65+
66+
**Method B: Hard-coded Credentials**
67+
68+
To use hard-coded credentials:
69+
70+
```cpp
71+
#define USE_WIFI_PROVISIONING false
72+
const char* WIFI_SSID = "YourWiFiName";
73+
const char* WIFI_PASSWORD = "YourWiFiPassword";
74+
```
75+
76+
### 2. Configure Update Interval
77+
78+
```cpp
79+
const unsigned long UPDATE_INTERVAL = 5000; // 5 seconds
80+
```
81+
82+
### 3. ESP32-C5 5GHz WiFi(Optional)
83+
84+
Force specific WiFi band on ESP32-C5:
85+
```cpp
86+
#define WIFI_BAND_MODE WIFI_BAND_MODE_5G_ONLY // 或 WIFI_BAND_MODE_2G_ONLY
87+
```
88+
89+
### 4. Upload and Connect
90+
91+
1. Select board: XIAO ESP32C6 (or your board)
92+
2. Upload program
93+
3. Open serial monitor (115200 baud)
94+
4. Add device in Home Assistant
95+
96+
## Home Assistant Setup
97+
98+
1. Go to Settings → Devices & Services → Add Integration
99+
2. Search for Seeed HA Discovery
100+
3. Enter device IP address
101+
4. one sensor will appear:
102+
- Humidity
103+
104+
## Created Entities
105+
106+
| Entity | Type | Unit | Precision |
107+
| :------------ | :----- | :--- | :-------- |
108+
| Soil Moisture | Sensor | % | Integer |
109+
110+
## Simulated Data Mode
111+
112+
When USE_SOIL_SENSOR is not defined, the device will automatically enable simulated data mode:
113+
Soil Moisture: Fluctuates between 0-100% (simulating the full range from dry to over-wet)
114+
This mode is suitable for scenarios without real sensors, facilitating code testing and Home Assistant integration debugging.
115+
116+
## Device Status Page
117+
118+
Access device status: http://<DeviceIP>/
119+
120+
## Troubleshooting
121+
122+
### Values Not Updating in HA
123+
- Check WiFi connection
124+
- Verify device is connected to HA
125+
- Check error messages in serial monitor
126+
127+
### Cannot Access Provisioning Page
128+
- Ensure you are connected to the device's AP
129+
- Try manually visiting http://192.168.4.1
130+
131+
## License
132+
133+
Part of the SeeedHADiscovery library.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# 土壤湿度传感器示例
2+
3+
实时向 Home Assistant 报告土壤湿度数据。支持真实土壤湿度传感器(如Seeed Studio土壤传感器)和模拟数据。
4+
5+
## 功能特性
6+
7+
- **土壤湿度传感器**(% 单位显示)
8+
- **可配置更新间隔**(按需调整数据上报频率)
9+
- **可选真实土壤湿度传感器支持**(电容式/电阻式)
10+
- **模拟数据模式**(用于无硬件测试场景)
11+
- **WiFi 配网**:网页配置WiFi(无需硬编码凭据)
12+
13+
## 硬件要求
14+
15+
- XIAO ESP32-C3/C5/C6/S3 或其他 ESP32 开发板
16+
- 土壤湿度传感器(可选 - 可使用模拟数据,推荐Seeed Studio土壤传感器)
17+
18+
> **注意**:XIAO ESP32-C5 支持 2.4GHz 和 5GHz 双频 WiFi
19+
20+
### 传感器引脚连接
21+
22+
| 功能 | 连接引脚 | 说明 |
23+
|----------------|----------|-----------------------|
24+
| 激励信号 (EX) | **D3** | 发送激励方波信号 |
25+
| 模拟信号 (SIG) | **D1** | 读取土壤电容响应电压 |
26+
| VCC | 3.3V | 供电(请勿接5V) |
27+
| GND | GND | 接地 |
28+
29+
### LED 指示灯连接(共阴极接法)
30+
31+
| LED颜色 | 引脚 | 状态定义 |
32+
|---------|--------|------------------------------|
33+
| 绿色 | **D8** | 湿度 > 60%(湿润) |
34+
| 黄色 | **D10**| 湿度 30%-60%(适中) |
35+
| 红色 | **D9** | 湿度 < 30%(干旱) |
36+
37+
## 软件依赖
38+
39+
### 需要安装的库
40+
41+
通过 Arduino 库管理器安装:
42+
43+
| 库名称 | 作者 | 说明 |
44+
|-------|------|------|
45+
| **ArduinoJson** | Benoit Blanchon | JSON 解析 |
46+
| **WebSockets** | Markus Sattler | WebSocket 通信 |
47+
48+
49+
### SeeedHADiscovery 库
50+
51+
[GitHub](https://github.com/limengdu/SeeedHADiscovery) 手动安装。
52+
53+
## 快速开始
54+
55+
### 1. WiFi 配置
56+
57+
**方式 A:WiFi 配网(推荐)**
58+
59+
WiFi 配网默认启用。首次启动时:
60+
1. 设备创建 AP 热点:`Seeed_TempHum_AP`
61+
2. 将手机/电脑连接到此 AP
62+
3. 浏览器自动打开,或手动访问 `http://192.168.4.1`
63+
4. 选择你的 WiFi 网络并输入密码
64+
5. 设备重启并连接到你的 WiFi
65+
66+
**方式 B:硬编码凭据**
67+
68+
如需使用硬编码凭据:
69+
```cpp
70+
#define USE_WIFI_PROVISIONING false
71+
const char* WIFI_SSID = "你的WiFi名称";
72+
const char* WIFI_PASSWORD = "你的WiFi密码";
73+
```
74+
75+
### 2. 配置更新间隔
76+
77+
```cpp
78+
const unsigned long UPDATE_INTERVAL = 5000; // 5 秒
79+
```
80+
81+
### 3. ESP32-C5 5GHz WiFi(可选)
82+
83+
在 ESP32-C5 上强制使用特定 WiFi 频段:
84+
```cpp
85+
#define WIFI_BAND_MODE WIFI_BAND_MODE_5G_ONLY // 或 WIFI_BAND_MODE_2G_ONLY
86+
```
87+
88+
### 4. 上传并连接
89+
90+
1. 选择开发板:**XIAO ESP32C6**(或你的开发板)
91+
2. 上传程序
92+
3. 打开串口监视器(115200 波特率)
93+
4. 在 Home Assistant 中添加设备
94+
95+
## Home Assistant 设置
96+
97+
1. 进入 **设置** → **设备与服务** → **添加集成**
98+
2. 搜索 **Seeed HA Discovery**
99+
3. 输入设备 IP 地址
100+
4. 将出现一个传感器:
101+
- 土壤湿度
102+
103+
## 创建的实体
104+
105+
| 实体 | 类型 | 单位 | 精度 |
106+
| :--- | :--- | :--- | :--- |
107+
| Soil Moisture | 传感器 | % | 整数 |
108+
109+
## 模拟数据模式
110+
111+
当未定义 USE_SOIL_SENSOR 时,设备将自动启用模拟数据模式:
112+
113+
土壤湿度:在 0-100% 之间波动(模拟干旱到过湿的全范围)
114+
115+
此模式适用于没有真实传感器的场景,方便代码测试与 Home Assistant 联动调试。
116+
117+
## 设备状态页面
118+
119+
访问设备状态:`http://<设备IP>/`
120+
121+
## 故障排除
122+
123+
### HA 中数值不更新
124+
- 检查 WiFi 连接
125+
- 验证设备已连接到 HA
126+
- 查看串口监视器的错误信息
127+
128+
### 无法访问配网页面
129+
- 确保已连接到设备的 AP
130+
- 尝试手动访问 `http://192.168.4.1`
131+
132+
## 许可证
133+
134+
SeeedHADiscovery 库的一部分。

0 commit comments

Comments
 (0)