ESP-IDF firmware for Seeed Studio XIAO ESP32-C6 plus a Home Assistant MQTT companion integration: six soil ADC channels publishing raw readings over MQTT, discovery metadata, host-driven per-channel masking, and per-channel raw dry thresholds with binary_sensor alarms (all stored in Home Assistant, not direct database writes).
| Path | Purpose |
|---|---|
firmware/ |
ESP-IDF 5.x / 6.x, target esp32c6; Wi-Fi, NTP, HTTP JSON config, MQTT + Home Assistant discovery. |
custom_components/plant_monitor/ |
Six raw-ADC number thresholds + six binary_sensor dry alarms linked to MQTT telemetry. |
docs/hardware_xiao_esp32c6.md |
MCU ↔ pin mapping for the six analog inputs. |
docs/homeassistant.md |
MQTT topic contract, www/ JSON example, integration steps. |
-
Install ESP-IDF (5.x or 6.x) with
esp32c6support. -
cd firmware -
If
set-targetever failed orbuildis not a clean CMake tree: delete the folder manually, then continue (PowerShell:Remove-Item -Recurse -Force .\buildfromfirmware/). -
Set the MCU first — this writes
sdkconfigfor esp32c6. If you skip this, CMake may default to esp32 and the toolchain will be wrong:idf.py set-target esp32c6
-
ESP-IDF 6+ managed components: MQTT and cJSON are no longer bundled as
components/mqttandcomponents/json. This repo listsespressif/mqttandespressif/cjsoninfirmware/main/idf_component.yml; the first configure/build downloads them (network required).
If CMake reportsunknown component 'mqtt'orunknown component 'json'(or missing cJSON), add the managed deps once fromfirmware/:idf.py add-dependency "espressif/mqtt" idf.py add-dependency "espressif/cjson"
-
idf.py menuconfig— optional but recommended to set Wi‑Fi, broker URL, device registry URL, and Power / sleep behaviour (see below).
menuconfigruns CMake likebuild; it does not replaceset-target.- Plant Monitor (ESP32-C6) → Power / sleep behaviour:
- Deep sleep between measurements (default): uses Deep sleep duration (seconds), then sleeps — best on battery.
- Continuous (debug, no deep sleep): loop + delay between measurements — best for USB serial debugging (no prompt during
flash; you choose here).
- Plant Monitor (ESP32-C6) → Power / sleep behaviour:
-
idf.py build— optional explicit compile (or go straight toidf.py flash monitor, which builds if needed):idf.py build idf.py -p PORT flash monitor
The serial log prints the compact Wi-Fi MAC used when adding the Home Assistant integration.
Firmware retries MQTT and (in continuous debug mode) keeps a single session open to reduce connect/TLS churn. If the broker still closes the TCP connection during handshake (serial log e.g. mqtt_message_receive() returned 0), treat that as an infrastructure issue as well:
- Inspect Mosquitto / Home Assistant MQTT broker logs at the same time as the device (disconnect reason, auth, limits).
- Check client limits, listener caps, and ACLs if the broker rejects half-open or rapid sessions.
- For
mqtts://, verify TLS/time on the device (SNTP) and broker certificate expectations. - Review Wi‑Fi signal and stability (weak links often show up as sporadic TLS or TCP failures).
fullclean/set-targetrefuses (“doesn't seem to be a CMake build directory”): deletefirmware/buildmanually, then runidf.py set-target esp32c6again.- Wrong chip in the log (
esp32vsesp32c6, wrong compiler triplet likextensa-esp32-elfinstead of riscv32 for C6): yoursdkconfigstill targets the wrong SoC — deletefirmware/buildand (if unsure)firmware/sdkconfig, then runidf.py set-target esp32c6and build again.
- In Home Assistant, open HACS → Integrations (the left tab for integrations, not "Frontend").
- Open the menu (three dots, top right) → Custom repositories.
- Repository: paste your Git URL, e.g.
https://github.com/boexler/ESP32-PlantMonitor(use SSH if you prefer:git@github.com:boexler/ESP32-PlantMonitor.git). - Category: select Integration.
- Click Add. HACS reads the root
hacs.jsonand lists the integration. - Open the new Plant Monitor (ESP32 MQTT) card → Download (pick a version or the default branch).
- Restart Home Assistant (Settings → System → Restart).
- Settings → Devices & services → Add integration → Plant monitor, then enter MQTT topic prefix and device MAC (see
docs/homeassistant.md).
Requires the built-in MQTT integration to be connected to your broker before adding this integration.
Copy custom_components/plant_monitor into your HA config folder, restart, then add the Plant monitor integration as above. Details: docs/homeassistant.md.