Acquario
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 looks after a fish tank: it dims the lamp through the day (moonlight, a slow dawn, the day, a slow dusk), turns a feeder at set times or when you ask for it, and reads the temperature of the water. The device brings its own screen (device UIs): the tank as a living picture, with fish, plants and bubbles in the light the lamp gives at that moment. The Connectivitizer app shows it full screen, from anywhere, without an open port.
The sketch has run on a bare board, without its sensor, lamp and servo. It compiles for the board esp32dev with PlatformIO (espressif32 6.12.0, Arduino core 2.0.17) against the library in ../../connectivitizer-esp32: 1,060,453 bytes of flash, 81 % of the default 1.3 MB app partition. No sensor, lamp or servo has been connected to it, so the pins, the timing of the DS18B20's one-wire protocol, the PWM settings and the pulse widths of the servo below are what the data sheets say, not what a test showed. The branch for version 3 of the Arduino core (ledcAttachChannel) has not been compiled. The page has only been run against the pretend device in ui/demo-data.js, in Chromium at phone sizes (360, 390 and 430 px wide), not in the app on a phone.
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. It came online by itself, and /state, /history, /.cz/ui.json and /.cz/ui.html answered with the same keys as the pretend device; POST /light refused a body without mode, as it should. 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. Here PIN_LIGHT moved from 25 to 15. It also compiles for the ESP32-S3 and the ESP32-C3.
| Folder | What it is |
|---|---|
ui/aquarium.html | The device's screen: one self-contained page (about 57 KB), always dark. |
ui/manifest.json | What the device serves as /.cz/ui.json. |
ui/demo-data.js | A pretend aquarium, for the demo on the landing page (demo kit). |
esp32/aquarium/ | 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. |
| DS18B20 temperature sensor | The waterproof kind on a cable, and a 4.7 kΩ resistor. |
| LED lamp with its own supply | Dimmed by PWM: through a logic-level N-channel MOSFET (with 100 Ω and 10 kΩ), or through the PWM input of the lamp's driver. |
| Servo (SG90 or similar) with its own 5 V supply | Turns the drum of a feeder over and back. |
| A drum feeder for the servo | A small container with an opening on top, on the servo's arm above the water. |
The sketch talks to the DS18B20 itself and uses the ESP32's own PWM for the lamp and the servo, so the Connectivitizer library is the only one to install.
ESP32
┌─────────────┐
3V3 ─4.7kΩ─┬──┤ GPIO4 │
DS18B20 DQ ──────┘ │ GPIO25 ├─100Ω─ MOSFET gate (10kΩ to GND) ── lamp minus
│ GPIO18 ├────── servo signal
└─────────────┘| Part | Power | Signal |
|---|---|---|
| DS18B20 | 3V3, GND | DQ → GPIO4, and 4.7 kΩ from DQ to 3V3. |
| Lamp | Its own supply | GPIO25 → 100 Ω → the MOSFET's gate, 10 kΩ from the gate to GND; the MOSFET switches the lamp's minus wire. Or GPIO25 → the PWM input of the lamp's driver. For a lamp that is brightest with the pin low, set LIGHT_ACTIVE_HIGH to false. |
| Servo | Its own 5 V supply | Signal → GPIO18. The minus of that supply goes to GND of the ESP32 as well. |
The lamp and the servo get their power from their own supplies, never from the ESP32. Keep the electronics above and away from the water.
The pins and the timing are constants at the top of aquarium.ino. Two of them depend on your feeder: FEEDER_REST_MICROS and FEEDER_DUMP_MICROS, the pulse widths at which the drum's opening is up and down. TIME_ZONE is the time zone the schedule is meant in; it is set to Central European Time.
Three constants make the sketch invent a part instead of using its pin, so that it runs on a board with nothing connected: SIMULATE_TEMPERATURE (a temperature that drifts around 25 °C), SIMULATE_LIGHT (the brightness is computed and not put on the pin) and SIMULATE_FEEDER (a feeding takes its time and moves nothing). All three are false as the sketch comes. While one is true, /state says "simulated": true and the page shows Simulated hardware at the bottom.
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/aquarium/esp32/aquarium
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 aquarium.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 aquarium (DEVICE_NAME).
After a change to ui/aquarium.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 aquarium. 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 aquarium --out <folder> # then open <folder>/aquarium/ui.htmlThe upper part is the tank. Its look follows /state: the brightness of the lamp decides how light the water is, how strong the rays from above are and how lively the fish swim, and during a dawn or a dusk the water turns rose or orange. In moonlight the fish stay low and the stripes of the small ones glow. When a feeding starts, by the button, by a feeding time or from another phone, food falls and the fish gather for it. A tap on the water calls the fish to that place.
Below it: the next feeding and the Feed button, the day of the lamp with one handle for sunrise and one for sunset and a slider for the brightness by day, a switch to a fixed brightness (Manual), and the temperature of the last 24 hours with the hours the lamp was on behind the curve. The feeding times are shown as dots on the day; the page does not edit them, POST /schedule does.
With prefers-reduced-motion the tank is a still picture that is drawn again when the state changes.
Under the service name api, on port 80. Times of day are minutes since midnight in the device's time zone, brightness is in percent.
| Request | Answer |
|---|---|
GET /state | { "temperature": 25.44, "light": 85.0, "phase": "day", "mode": "auto", "minuteOfDay": 1086, "schedule": { "sunrise": 480, "sunset": 1200, "ramp": 45, "dayLevel": 85, "moonLevel": 4 }, "feeding": false, "feedTimes": [450, 1110], "nextFeedMinutes": 24, "lastFedSecondsAgo": 38160, "simulated": false, "rssi": -61, "uptimeSeconds": 976500 }. temperature in °C, null until the sensor has answered and again after ten seconds without an answer. light is what the lamp shows right now. phase is "moon", "dawn", "day" or "dusk", the part of the scheduled day, also while mode is "manual". phase, minuteOfDay and nextFeedMinutes are null until the ESP32 has the time from the internet; nextFeedMinutes also when there are no feeding times. lastFedSecondsAgo is null until a feeding since the last restart. |
GET /history | { "intervalSeconds": 900, "temperature": [...], "light": [...] }: up to 96 numbers each, oldest first, one every 15 minutes, and the last one is the reading of this moment. A temperature can be null. Shorter after a restart; the history is kept in memory only. |
POST /light | Body { "mode": "auto" }, { "mode": "manual" } or { "mode": "manual", "level": 60 }; { "level": 60 } alone means manual too. Manual without a level keeps the brightness of that moment. Answers like /state. 400 for another body. Manual is not kept over a restart. |
POST /feed | Any body. Turns the feeder once. Answers like /state, with "feeding": true for the 2.4 seconds the turn takes. 409 { "error": "The feeder is still turning." } during a turn. |
POST /schedule | Body with any of sunrise, sunset, ramp, dayLevel, moonLevel, feedTimes, for example { "sunrise": 450, "sunset": 1230 } or { "feedTimes": [450, 1110] }. Answers like /state, with the values as the device keeps them. 400 when none of them is there. Stored in flash, survives a restart. |
GET /.cz/ui.json, GET /.cz/ui.html | The manifest and the page. |
From sunrise the brightness rises from moonLevel to dayLevel within ramp minutes, stays there until sunset, and falls back to moonLevel within ramp minutes. The device keeps the day in order: ramp between 5 and 120 minutes, at least an hour of full day between the two ramps, the dusk over by 23:45, dayLevel between 10 and 100, moonLevel between 0 and 10. A value outside is moved to the nearest one that fits, and the answer shows it.
The lamp never jumps: it moves to a new brightness by 20 percent per second at most (LIGHT_PERCENT_PER_SECOND), and the duty cycle follows a gamma curve so that the steps look even. Without the time of day the schedule cannot be followed; until the ESP32 has it, the lamp stays at moonLevel.
Up to four feeding times. At each, and for each POST /feed, the servo turns the drum over, holds it for 1.2 seconds and turns it back; then the pulses stop, so that the servo does not hum above the water. A restart during a minute that is a feeding time does not feed a second time. The device does not limit how often POST /feed is called.
ui/demo-data.js answers the same requests with the same members, with invented values, in the browser. These things are different from a real tank, on purpose:
minuteOfDay, nextFeedMinutes, lastFedSecondsAgo and the history follow that clock; uptimeSeconds does not.null.