Docs
Guided quickstart
This is the guided quickstart as you will see it in the web app. Sign in to create the keys there and watch each step tick itself off as your device and app connect.
How it fits together
On the device, the library runs the agent inside your software and forwards incoming requests to the local port your service listens on. On your phone, the Connectivitizer app opens the session and shows the screen your device brings. Both sides connect outwards to Connectivitizer, which introduces them. What they exchange is encrypted end to end between the two endpoints.
The device
The machine that has the service: an ESP32 in a lamp, a Raspberry Pi in the garden shed, a PC in the office.
Steps tick themselves off once the platform sees their result. You can tick off the others yourself by clicking their number; this browser remembers it.
Choose your language
NextThe library needs no other library. Install it with the Library Manager of the Arduino IDE, with lib_deps in PlatformIO, or as a component from the ESP Component Registry. It is made for every ESP32 with Wi-Fi.
In your project# Arduino IDE: Tools > Manage Libraries..., search "Connectivitizer" arduino-cli lib install Connectivitizer # PlatformIO: in platformio.ini lib_deps = huelakesoftwaresolutions/Connectivitizer # ESP-IDF idf.py add-dependency "huelake/connectivitizer"Give the device its key and name
The device logs in with a device key of this workspace and a name you choose. There is nothing to enroll: it appears here the first time it connects.
In the device software · C · ESP32#include <WiFi.h> #include <WebServer.h> #include <Connectivitizer.h> // from this workspace const char *DEVICE_KEY = "czd_..."; // how apps address this device const char *DEVICE_NAME = "living-room-lamp"; // the same key the app has; never sent to anyone const char *SHARED_KEY = "czs_...";One device key serves any number of devices; the name tells them apart and is how apps address the device. The shared key comes from part 2.
Expose a service
Say which local port of your software may be reached, under a name of your choice.
In the device software · C · ESP32WebServer server(80); // an ordinary web server // in setup(), after server.begin(): Connectivitizer.setSharedKey(SHARED_KEY); Connectivitizer.expose("api", 80);Port 80 is the sketch’s own web server; any TCP port works. The platform only ever learns the name “api”, and nothing is reachable that is not exposed here.
Start it
begin() starts the library in a task of its own. It keeps one outbound connection to the platform and waits for sessions. No inbound port is opened.
In the device software · C · ESP32// in setup(), last: Connectivitizer.setServer("<api url>"); Connectivitizer.begin(DEVICE_KEY, DEVICE_NAME); void loop() { server.handleClient(); // nothing to call for Connectivitizer }The device appears in this workspace and shows as online within a few seconds of its first connection.
Your phone
The Connectivitizer app shows the devices of this workspace and opens the screen each of them brings.
Get the Connectivitizer app
Install the app and sign in with the account you use here. Your devices appear in it on their own once they have connected.
AndroidGet it on Google PlayComing sooniOSDownload on the App StoreComing soonGive the device and the phone the same key
The device and the app encrypt their sessions with a key that only the two of them hold. Generate one, put it into the device’s code, and scan its QR code in the app under Keys. Connectivitizer never receives it.
In the device software · C · ESP32Connectivitizer.setSharedKey("czs_...");A session is refused when the keys differ. A device may hold several keys, for example one per phone.
Give the device a screen
Without a page of its own, the app can only show that the device is there. Save this page next to your device’s program and serve it with this small web server, on the address you exposed in “Expose a service”. The app shows it when you tap the device.
In the device software · C · ESP32// In the sketch: the routes go on the WebServer that is exposed as "api" (port 80). static const char UI_JSON[] PROGMEM = R"({"name":"Desk lamp","entry":"/.cz/ui.html","version":"1"})"; static const char UI_HTML[] PROGMEM = R"html(<!doctype html> <html lang="en"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- CSS: how the page looks --> <style> body { margin: 0; padding: 24px; font: 16px system-ui, sans-serif; background: #fdf6e3; color: #3b3526; } h1 { font-size: 44px; margin: 4px 0 24px; } label { display: block; margin: 28px 0 8px; } button { font: inherit; padding: 12px 24px; border-radius: 12px; border: 0; background: #b58900; color: #fff; } input, select { font: inherit; padding: 10px; border-radius: 10px; border: 1px solid #c8b98a; background: #fff; color: inherit; } input[type=range] { width: 100%; padding: 0; border: 0; background: none; accent-color: #b58900; } </style> <!-- HTML: what is on the page. Each id connects an element to the script below. --> <p>Desk lamp</p> <h1 id="state">…</h1> <button id="toggle">Switch</button> <label for="level">Brightness: <b id="level-value">…</b> %</label> <input id="level" type="range" min="0" max="100" step="5"> <p>Running for <b id="uptime">…</b> s</p> <!-- JavaScript: what happens. fetch('/…') goes to the device, through the app. --> <script> const $ = (id) => document.getElementById(id); // The device answers every request with its state, e.g. {"on":true,"level":40,"uptime":120}. // show() puts it on the page: one line per value. const show = async (response) => { const s = await response.json(); $('state').textContent = s.on ? 'On' : 'Off'; $('level-value').textContent = s.level; if (document.activeElement !== $('level')) $('level').value = s.level; $('uptime').textContent = s.uptime; }; const refresh = () => fetch('/state').then(show).catch(() => { $('state').textContent = 'No /state yet'; }); // A tap or a change sends a request; the answer is shown right away. $('toggle').onclick = () => fetch('/toggle', { method: 'POST' }).then(show); $('level').oninput = () => { $('level-value').textContent = $('level').value; }; $('level').onchange = () => fetch('/level?value=' + $('level').value, { method: 'POST' }).then(show); refresh(); setInterval(refresh, 2000); // new values every 2 seconds </script> </html>)html"; static bool on = false; static int level = 50; static void sendState() { String json = String("{\"on\":") + (on ? "true" : "false") + ",\"level\":" + level + ",\"uptime\":" + (millis() / 1000) + "}"; server.send(200, "application/json", json); } // in setup(), before server.begin(): server.on("/.cz/ui.json", HTTP_GET, [] { server.send_P(200, "application/json", UI_JSON); }); server.on("/.cz/ui.html", HTTP_GET, [] { server.send_P(200, "text/html; charset=utf-8", UI_HTML); }); server.on("/state", HTTP_GET, sendState); server.on("/toggle", HTTP_POST, [] { on = !on; // switch your pin here: digitalWrite(LED_PIN, on); sendState(); }); server.on("/level", HTTP_POST, [] { level = constrain(server.arg("value").toInt(), 0, 100); // e.g. analogWrite(LED_PIN, level * 255 / 100); sendState(); });Your own controls to copy, a preview on your computer without the device, colours, the camera and finished examples to start from: How to give your device a screen
Open your device
Tap the device in the app. The app connects and shows your device’s page.
The session reports whether it is direct or relayed and whether it is end-to-end encrypted. The same is recorded here: Connections
Instructions to paste into your agent
They follow the languages chosen above and point the agent to the guides this web app serves: what to install, what to ask you for, which rules to keep, how to check the result and what to do when a session is not direct. They contain no key.
I want to add Connectivitizer to my project. Connectivitizer lets an app reach a service on a device behind NAT without opening a port: directly (peer to peer) when the networks allow it, otherwise through a relay, end-to-end encrypted either way.
Follow the instructions for coding agents at /guides/agent.md. They say what to ask me before you write code, which rules to keep and how to check the result. Install the packages as the guides say.
## My setup
- Device (has the service): an ESP32 with the Connectivitizer library (Arduino, PlatformIO or ESP-IDF).
- Calling app: the Connectivitizer app on my phone. Nothing is built on that side; the device serves its own screen (one HTML page), which the app shows.
- Connectivitizer web app:
- API address: <api url>
- Device name: living-room-lamp (how apps address the device)
- Service name: api
- The two sides trust each other with a shared key (czs_...) that both sides hold. Connectivitizer never receives it.
## Guides
- Instructions for coding agents: /guides/agent.md
- Device (ESP32): /guides/esp32.md
- The device's own screen, with the code for each language (serve it from the device): /guides/device-screen.md
- The Connectivitizer app and the shared key on the phone: /guides/mobile-app.md
- Troubleshooting (relayed instead of direct, or no connection): /guides/troubleshooting.md
- Error codes: /guides/errors.md
- All guides: /llms.txt
Do not ask me to paste keys into this chat. Create the git-ignored files that will hold them, with placeholders, and I fill them in.
The instructions are in English, which coding agents follow best; the agent answers you in your language.