Sereno
demo-kit/ è quello che simula il dispositivo per la demo nella pagina di inizio. Il dispositivo stesso non ne ha bisogno.
demo-kit/ è quello che simula il dispositivo per la demo nella pagina di inizio. Il dispositivo stesso non ne ha bisogno.
An ESP32 watches one plant: how wet its soil is, how warm, humid and bright the air around it is, and how much water is left in a tank. A relay switches a small pump, when you ask for it or by itself when the soil is drier than a threshold you set. The device brings its own screen (device UIs): a plant whose leaves droop as the soil dries and lift again after watering. The Connectivitizer app shows it full screen, from anywhere, without an open port.
The sketch has run on a bare board, without its sensors, relay and pump. It compiles for the board esp32dev with PlatformIO (espressif32 6.12.0, Arduino core 2.0.17) against the library in ../../connectivitizer-esp32: 1,049,069 bytes of flash, 80 % of the default 1.3 MB app partition. No sensor, relay or pump has been connected to it, so the pins, the calibration values and the timing of the sensors below are what the data sheets say, not what a test showed. The page has only been run against the pretend device in ui/demo-data.js.
Tried on a board (November 2026). The sketch was flashed to an ESP32-S3 DevKit board (N16R8: 16 MB flash, 8 MB octal PSRAM) with nothing connected to it, built with PlatformIO (espressif32 6.12.0, Arduino core 2.0.17) against the library of this repository, and reached through a development platform in the same network with the TypeScript SDK, peer to peer and through the relay, both end-to-end encrypted. On the S3 the pins had to change: GPIO 22 to 25 do not exist there, and on modules with octal PSRAM GPIO 26 to 37 belong to the flash and the PSRAM, so a sketch that drives one of them stops the chip. With the pins as written (PIN_PUMP 26) the S3 restarted over and over before setup() printed anything; with PIN_SOIL 4, I2C on 8 and 9 and PIN_PUMP 7 it came online, and /state, /history and the page answered with the same keys as the pretend device. Without the SHT31 and the BH1750 the log shows an I2C error every two seconds, which is expected. It also compiles for the ESP32-S3 and the ESP32-C3.
| Folder | What it is |
|---|---|
ui/greenhouse.html | The device's screen: one self-contained page (about 43 KB), light or dark with the phone. |
ui/manifest.json | What the device serves as /.cz/ui.json. |
ui/demo-data.js | A pretend greenhouse, for the demo on the landing page (demo kit). |
esp32/greenhouse/ | The Arduino sketch, with the page built in (page.h). |
| Part | Notes |
|---|---|
| ESP32 development board | Any with the classic ESP32 (esp32dev). Other chips need other pins. |
| Capacitive soil moisture sensor | The analog kind, powered with 3.3 V. |
| SHT31 breakout | Temperature and humidity, I2C address 0x44. |
| BH1750 breakout | Light in lux, I2C address 0x23. |
| HC-SR04 ultrasonic sensor | In the lid of the tank, looking down at the water. Two resistors (1 kΩ, 2 kΩ) for its 5 V echo. |
| Relay module, 5 V, one channel | Switches the pump. |
| Small pump with its own power supply, tube, a water tank | For example a 5 V or 12 V submersible pump. |
The sketch reads the two I2C sensors itself with Wire, so the Connectivitizer library is the only one to install.
ESP32
┌─────────────┐
soil sensor AOUT ─┤ GPIO34 │
SHT31 + BH1750 SDA┤ GPIO21 │
SHT31 + BH1750 SCL┤ GPIO22 │
HC-SR04 TRIG ─────┤ GPIO5 │
HC-SR04 ECHO ─1kΩ─┤ GPIO18 │ relay COM / NO ── pump ── pump's own supply
2kΩ │ GPIO26 ├──── relay IN
│ │ │
GND └─────────────┘| Part | Power | Signal |
|---|---|---|
| Soil sensor | 3V3, GND | AOUT → GPIO34. It has to be an ADC1 pin (32 to 39): the ADC2 pins do not work while Wi-Fi is on. |
| SHT31, BH1750 | 3V3, GND | SDA → GPIO21, SCL → GPIO22, both on the same two wires. |
| HC-SR04 | 5V, GND | TRIG → GPIO5. ECHO is 5 V: 1 kΩ from ECHO to GPIO18, 2 kΩ from GPIO18 to GND. |
| Relay module | 5V, GND | IN → GPIO26. For a module that switches on when IN is low, set PUMP_ACTIVE_HIGH to false. |
The pump gets its power from its own supply through the relay's COM and NO contacts, never from the ESP32. Keep the electronics above and away from the water.
The pins and the calibration are constants at the top of greenhouse.ino. Measure four of them once: SOIL_RAW_DRY and SOIL_RAW_WET (what analogRead gives with the sensor in air and in a glass of water), TANK_EMPTY_CM and TANK_FULL_CM (the distance from the ultrasonic sensor to the bottom of the tank, and to the water when it is full).
You need a device key (czd_…, web app: Credentials → Create credential → Device key) and a shared key (czs_…, Credentials → Generate a shared key).
cd src/examples/greenhouse/esp32/greenhouse
copy secrets.example.h secrets.h # fill in Wi-Fi (2.4 GHz), DEVICE_KEY, SHARED_KEYArduino IDE: install the board package esp32 and the library Connectivitizer (Tools → Manage Libraries), open greenhouse.ino, choose ESP32 Dev Module, upload.
arduino-cli:
arduino-cli lib install Connectivitizer
arduino-cli compile --fqbn esp32:esp32:esp32 .
arduino-cli upload --fqbn esp32:esp32:esp32 -p COM5 .PlatformIO (how it was compiled here): a platformio.ini beside a folder src that holds the files of the sketch.
[env:esp32dev]
platform = espressif32@6.12.0
framework = arduino
board = esp32dev
lib_deps = huelakesoftwaresolutions/ConnectivitizerThe serial monitor (115200 baud) prints the address in your Wi-Fi and, once the device is online, Reachable through Connectivitizer. The device appears in the workspace as greenhouse (DEVICE_NAME).
After a change to ui/greenhouse.html or ui/manifest.json, write page.h again and flash:
node make-page.mjsIn the Connectivitizer app (Android): link the app to the workspace, give it the shared key, pick greenhouse. The app asks the device for /.cz/ui.json and shows the page it names.
In a browser in the same Wi-Fi: http://<address of the ESP32>/.cz/ui.html. The page then talks to the ESP32 directly; it is the same file.
Without hardware: the demo, with the pretend device.
cd src/connectivitizer
node scripts/build-demos.mjs --only greenhouse --out <folder> # then open <folder>/greenhouse/ui.htmlUnder the service name api, on port 80:
| Request | Answer |
|---|---|
GET /state | { "soil": 43.0, "temperature": 24.3, "humidity": 54.1, "light": 31250, "tank": 68.0, "pump": false, "pumpSecondsLeft": 0, "auto": true, "threshold": 35, "lastWateredSecondsAgo": 36240, "rssi": -58, "uptimeSeconds": 529920 }. Soil, humidity and tank in percent, temperature in °C, light in lux. A reading is null until its sensor has answered, and soil is null while the sensor reads far outside its calibration (unplugged). lastWateredSecondsAgo is null until the pump has run since the last restart: the ESP32 has no clock that survives one. |
GET /history | { "intervalSeconds": 900, "soil": [...], "temperature": [...], "humidity": [...] }: up to 96 numbers each, oldest first, one every 15 minutes, and the last one is the reading of this moment. Shorter after a restart; the history is kept in memory only. |
POST /pump | Body { "on": true }, { "on": false } or { "seconds": 8 }. Answers like /state. on without a time runs until it is switched off, and like every run at most 30 seconds (PUMP_MAX_SECONDS). 409 { "error": "The tank is empty." } below 5 % in the tank, 400 for another body. |
POST /config | Body { "auto": true, "threshold": 35 }, either member or both. threshold is kept between 5 and 90. Answers like /state. Both settings are stored in flash and survive a restart. |
GET /.cz/ui.json, GET /.cz/ui.html | The manifest and the page. |
With auto on, the pump runs for 8 seconds (AUTO_WATER_SECONDS) when the soil is below the threshold. Then it waits 30 minutes (AUTO_PAUSE_MINUTES) after any watering, so that the water can spread before the sensor is believed again. It does not start without a soil reading it can believe and a known tank level: a sensor that fell out of the pot reads "dry" for ever.
The pump stops after 30 seconds at the latest, whoever started it, and when the tank falls below 5 %, so that it does not run dry. It is switched off first thing in setup().
ui/demo-data.js answers the same five requests with the same members, with invented values, in the browser. Three things are different from a real pot, on purpose:
null.Each run of the pump takes half a percent per second from the pretend tank. With auto-watering on, the pretend pump starts by itself once the soil is below the threshold.