Franja LED
demo-kit/ es lo que simula el dispositivo para la demostración en la página de inicio. El dispositivo en sí no lo necesita.
demo-kit/ es lo que simula el dispositivo para la demostración en la página de inicio. El dispositivo en sí no lo necesita.
An ESP32 drives an addressable LED strip and brings its own control panel: a page with a live preview of the strip, a colour wheel, brightness, speed and eight effects. The Connectivitizer app shows that page full screen (device UIs) and reaches the strip from anywhere, without an open port and without an app of your own.
| Folder | What it is |
|---|---|
esp32/lights/ | The Arduino sketch: Wi-Fi, a web server with the addresses below, the effects, and the page built into the firmware. |
ui/lights.html | The device UI: one self-contained page. |
ui/manifest.json | What the device serves as /.cz/ui.json. |
ui/demo-data.js | A pretend strip, for showing the page without hardware (below). |
What has been checked. The sketch compiles for the ESP32, the ESP32-S3 and the ESP32-C3 with PlatformIO (espressif32 6.12.0, Arduino core 2.0.17). It has been 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. GET /state, POST /state, GET /effects and the page answered as the pretend strip does. No strip has been connected, so the timing of the LED signal has not been tried. The path for Arduino core 3.x in the sketch has not been compiled. The page has been tried in a browser against the pretend strip only.
| Part | |
|---|---|
| ESP32 development board | Any ESP32 with Arduino support (ESP32, -S2, -S3, -C3). |
| WS2812B LED strip, 5 V | 60 LEDs in the sketch (LED_COUNT). Other strips with the same one-wire signal work the same way; a different colour order is one line (COLOR_ORDER). |
| 5 V power supply | Count 60 mA per LED at full white: 3.6 A for 60 LEDs. The sketch dims a frame that would draw more than MAX_MILLIAMPS (2000 as written), so a 5 V / 3 A supply is enough for 60 LEDs. |
| Level shifter 3.3 V to 5 V | For the data line, for example a 74AHCT125 or 74HCT245. |
| Resistor 330 to 470 Ω | In the data line, close to the strip. |
| Capacitor 1000 µF, 6.3 V or more | Across 5 V and ground where the strip is fed. |
5 V supply +5V ───────────────┬───────────────► strip 5V
│ (1000 µF across 5V and GND at the strip)
GND ──┬────────────┴───────────────► strip GND
│
ESP32 GND ──┘
5V / VIN ◄── +5V of the supply (or power the board over USB instead, never both)
GPIO 5 ──► level shifter ──► 330 Ω ──► strip DINLED_PIN in the sketch). Any free output pin works; avoid the strapping pins of your board.cd src/examples/lights/esp32/lights
copy secrets.example.h secrets.h # fill in Wi-Fi (2.4 GHz), device key and shared keyThe keys come from your workspace in the web app: Credentials → Create credential → Device key and Credentials → Generate a shared key. secrets.h is not committed.
Arduino IDE: install the ESP32 boards and the Connectivitizer library (Tools → Manage Libraries), open lights.ino, choose your board and port, upload. No LED library is needed.
PlatformIO: a platformio.ini next to a src folder with the four files (lights.ino, page.h, secrets.h, secrets.example.h):
[env:esp32dev]
platform = espressif32@6.12.0
framework = arduino
board = esp32dev
monitor_speed = 115200
lib_deps = huelakesoftwaresolutions/Connectivitizerthen pio run -t upload -t monitor.
The serial monitor (115200 baud) shows the address of the page in your own network and Reachable through Connectivitizer. once the device is online. It appears in the workspace under the name in secrets.h (desk-lights).
The strip without a library. The sketch sends the LED signal with the RMT functions of the ESP32 Arduino core (rmtInit, rmtWriteBlocking, in esp32-hal-rmt.h): each bit is one RMT item of 0.4 µs and 0.8 µs, as the core's own neopixelWrite does it for a single LED. The core changed these functions with version 3; the sketch has both forms and picks one by ESP_ARDUINO_VERSION_MAJOR. Only the 2.x form has been compiled, and neither has driven a real strip yet.
After changing the page, write it into the firmware again and flash:
node make-page.mjs # writes page.h from ../../ui/lights.html and ../../ui/manifest.jsonOpen the Connectivitizer app (Android), link it to the workspace, give it the same shared key, and pick the device. The app finds /.cz/ui.json on the service api and shows the page; the bar above it takes the page's colours and follows the chosen colour.
In a browser in the same network the page works too, straight from the ESP32: http://<address>/.
The page asks for /state every 1.5 seconds, so a change made on a second phone shows up on the first. While a finger is on the wheel or a slider, changes go out about nine times a second, and the page then shows the state the device answers.
All on the service api (port 80 of the ESP32):
| Request | Answer |
|---|---|
GET /state | { "on": true, "brightness": 204, "color": "#7c5cff", "effect": "aurora", "speed": 55, "leds": 60 }. brightness is 0 to 255, speed 0 to 100, leds the length of the strip. |
POST /state | Takes a JSON object with any of on, brightness, color, effect, speed and answers like GET /state. A member that is unknown or does not fit (an effect that does not exist, a colour that is not #rrggbb) is left out; numbers are brought into their range. 400 with { "error": … } when the body is not a JSON object. |
GET /effects | [ { "id": "solid", "name": "Solid" }, … ]: solid, rainbow, breathe, chase, sparkle, fire, aurora, sunrise. |
GET /.cz/ui.json, GET /.cz/ui.html | The manifest and the page. |
rainbow, fire and sunrise bring their own colours; the others use color. The state is kept in memory: after a restart the strip starts as the sketch says.
Changes are not abrupt on the strip either: colour, brightness, on and off, and the change from one effect to the next fade over a fraction of a second. The effects are computed from the time that has passed, 50 times a second, and loop() never waits for them. Wi-Fi interrupts can disturb the LED signal on some boards; if single frames flicker, that is the place to look.
The landing page of the web app shows this page without a strip (demo kit). ui/demo-data.js is the pretend device there: it answers GET /state, POST /state and GET /effects with the same shapes and the same rules as the sketch, and keeps the state in memory. So that the demo is not a still picture, it changes effect and colour by itself every nine seconds, as long as the visitor has not changed anything for 20 seconds. The page learns of these changes the way it would learn of a second phone: from its regular GET /state.
The preview of the strip in the page is computed in the page, with the same formulas as the sketch. It shows what the effect does, not a measurement of the real LEDs.
cd src/connectivitizer
node scripts/build-demos.mjs --only lights --out <folder> # then open <folder>/lights/ui.html