In Cuba, Venezuela and much of rural Latin America, a house stores water in two places: a cistern at ground level that fills whenever the city supply happens to arrive, and a tank on the roof that gives the taps their pressure. Between them sits a pump, usually switched by a float switch or by someone walking to the breaker. Floats stick and tanks overflow. Cisterns run dry and pumps burn. Nobody knows how much water is left without climbing to the roof.

I work on Tinajón Pro, an ESP32 controller for that pump. Most "smart" pump switches assume a stable connection and a vendor cloud. Where internet is metered, paid by the hour, or gone for half the day, that assumption is exactly backwards: if the cloud is the brain, a dropped connection leaves the pump in whatever state it was in.

These are the design decisions that came out of building for that world. Most of them apply to any device that controls something physical.

1. Local-first: the cloud is an add-on, never the brain

Every decision that keeps the water flowing happens on the device: start the pump when the level drops below a threshold, stop it when the tank is full, stop it if something looks wrong. The phone app talks to the device directly over the LAN (HTTP + WebSocket). If the home has no WiFi at all, the device creates its own access point and the app connects straight to it.

The cloud only adds the things that genuinely need it: alerts on your phone when you are away, remote control, sharing the device with family, a long-term history. Lose the internet and you lose those, not the pump.

A useful test: unplug the router's uplink and walk through every feature. Anything that breaks and isn't inherently remote is a design bug.

2. "Connected to WiFi" does not mean "connected to the internet"

Our device has two logical modes. In cloud mode it publishes events over MQTT (TLS) to a backend. It enters that mode when it is on the home WiFi and paired to the cloud. For a while our own architecture notes claimed a connectivity monitor that pinged the internet to decide the mode. It never existed.

That matters, because the most common failure in our target markets is not "no WiFi". It is WiFi up, router up, and no uplink behind it. The device happily thinks it is in cloud mode while nothing reaches the broker.

The fix was to stop treating the mode as a proxy for reachability. Anything that depends on the cloud now looks at the actual broker connection. One concrete case: the backend can tell the device "don't auto-start the pump during these hours". Only the backend can lift that block. If the device can't reach the broker for 10 minutes, it releases the block on its own. Otherwise a schedule that nobody can update anymore would keep the house without water.

Rule of thumb: any state the cloud can set but only the cloud can clear needs a local timeout.

3. Fail safe on the device, with the reason on the screen

The protections that matter most can't wait for a server round trip:

  • If the pump runs for 2 minutes (the default) and the tank level hasn't risen, stop it. That catches a dry cistern, a lost prime or a closed valve. The timer resets every time the water rises 1 cm, so a slow fill doesn't trip it.
  • Optional cistern float input: no water below, no start.
  • A minimum pause between starts, so a noisy reading can't make the pump click on and off.
  • A configurable wait after a power cut before starting again.
  • If the level sensor stops responding, stop. Don't guess.

Every stop shows why on the device's own screen. A protection that silently turns a pump off looks exactly like a broken product.

4. Don't write logs to flash

It is tempting to keep an event log on the device "for when there's no internet". On a microcontroller, flash has a limited number of write cycles, and a pump controller produces events all day, for years. So the device keeps current state and a small buffer of recent events in RAM. Persistent history lives in the backend, when there is one.

We also deliberately don't sync offline events once the connection comes back. It would have been the single most complex piece of the firmware. The honest trade-off: if you never connect to the cloud, you have no long-term history. The pump works the same either way.

5. Recovery must work with no network and no account

When someone mistypes their WiFi password or loses access to their account, the device must still be recoverable with what's in front of them. We have two physical buttons and a small OLED, so recovery is a set of hold-to-act gestures:

  • Hold MODE for 3–6 s: restart.
  • Hold MODE for 6–10 s: open a 5-minute window to update the firmware from a file.
  • Hold MODE + START/STOP for 5 s: reset only the WiFi and go back to the factory access point. Settings are kept.
  • Keep holding into a separate confirmation: factory reset.
  • Hold START/STOP for 3–6 s: show the local access PIN on screen, 15 s. This is deliberately the only way to recover it. It is never exposed over the network.

Two details turned out to matter more than the gestures themselves. First, the action happens on release, and the screen says what will happen if you let go now ("Release to restart", "Release to cancel"). Nobody has to count seconds. Second, the first 3 seconds are silent on purpose, so a clumsy long press does nothing.

The factory access point uses a predictable name and a fixed, documented password. That sounds like a security smell. In practice it is what makes recovery possible, and it only exists after a deliberate reset done by someone standing next to the device.

6. Describe capabilities, not models

We expect cheaper variants (no screen, electrodes instead of an ultrasonic sensor) and richer ones (current and voltage metering). Early on, the obvious move was a hardware_variant string and a switch in the app.

The problem: every app already installed would treat any future model as unknown. Instead, the device reports a capabilities object (which sensors, whether there is a screen, how many buttons, how it resets), and the app renders from that. The variant name is metadata only: shown to the user, used to pick the right firmware binary, never used to branch the UI. An old app talking to new hardware shows less, not something broken.

A side effect we didn't expect: electrodes change the shape of the data, not just its presence. They give discrete steps, not a 0–100% level. Capabilities forced us to model that, instead of faking a percentage.

7. Test the rollback, not just the update

Over-the-air updates come with rollback if the new firmware doesn't boot properly. We had that "working" for a while, and only found it was decorative when we flashed a deliberately broken binary and watched the device stay on it. The fix itself was small. The lesson wasn't: a safety mechanism you have never seen trigger is a hope, not a mechanism.

The same goes for backups. We restored ours into a clean database for the first time, and found a real bug in the process.

8. Commands from the cloud need an expiry date

A subtle one. With MQTT persistent sessions, a command sent while the device is offline is stored by the broker and delivered when the device comes back. The backend may not even know the device is offline yet. For "turn the pump on", that means it can run hours later, when nobody is watching. Our API now refuses commands to devices it knows are offline and sets a short message expiry (60 s) on the rest. One path in the app still publishes straight to the broker without that expiry, and moving it behind the API is on our list. A stale "on" is worse than a lost one.

What I'd tell anyone building for unreliable connectivity

  • Make the device the source of truth. The cloud reflects it, extends it, and can disappear.
  • Treat "the cloud can set this but only the cloud can clear it" as a bug until it has a local timeout.
  • Put the reason for every automatic action where the user is standing.
  • Test every safety net by making it fire.

If you are curious about the domestic side (why tanks overflow, why pumps run dry), we write guides about it in Spanish on the Tinajón Pro blog. The device itself is in testing with real hardware, with a waitlist on the site. Disclosure: I work on Tinajón Pro.