In summer, Andorran herds climb high, the phone signal drops, and one cow
that wanders off can cost a farmer a whole morning of walking. Most livestock
trackers are designed for flat farmland with good coverage.
Mosicu is a collar plus an app. The collar reports where the animal is every
15 minutes over the mobile network. The app shows the whole herd on a map and
sends an alert when an animal leaves its pasture, stops reporting, hasn't
moved for hours, or is in heat stress. No antennas to install.
I built all of it: the electronics, the case, the firmware, the cellular link,
the backend, the iOS and Android apps and the website.
The collar, exploded: board, battery and sensors in the base; GNSS antenna and buzzer in the lid.
The hardware.
The collar is built around a LilyGO T-SIM7080G-S3: an ESP32-S3 with a SIMCom
SIM7080G modem that does both GNSS and NB-IoT. Around it:
One 18650 cell, with a target of two to three weeks per charge at a 15-minute interval.
An MSA311 accelerometer for activity (resting, grazing, moving) and wake-on-motion.
A temperature sensor touching the neck (AHT20), used for heat-stress alerts.
A vibration motor and a buzzer, so the farmer can make a collar beep to find the animal.
The modem's LTE antenna and an active GNSS patch in the lid, facing the sky.
One soldered wire from the accelerometer's interrupt to a GPIO lets the
collar sleep through the night and wake when a resting animal gets up,
without shortening the reporting interval.
The enclosure
The case is a parametric model in Python with
build123d
(an OpenCascade B-rep kernel), so it exports STEP as well as STL, and every
dimension is a named constant with asserts guarding the critical
clearances. It's on its fourth version:
v2 used screws and a tongue on a 1.5 mm cord.
v3 tried snap arms and a formed-in-place gasket. One arm broke on the first print, and the snaps couldn't squeeze the gasket evenly. Not good enough for rain, snow and mud in the Pyrenees.
v4 seals the lid on a 2 mm silicone O-ring in a proper face-seal groove, held by eight M3 screws in brass heat-set inserts. The USB-C port gets a printed TPU plug.
The base comes in a goat and a cow version (only the strap lugs differ), and
the logo and serial number are engraved into the lid.
The closed v4 enclosure, and the engraved lid (filled with a paint marker after printing).
The firmware.
PlatformIO on the ESP32-S3. The firmware is deliberately minimal: measure,
buffer, send, obey. Every wake it gets a GNSS fix, reads the sensors and
battery, sends the reading, executes any pending commands, and goes back
to deep sleep. Anything likely to change lives on the server.
Remote config. Timeouts, intervals, motion thresholds and cellular budgets are tuned from the backend. The collar stores them in flash and applies them on the next wake.
Over-the-air updates. Every collar runs the same image (its key lives in its own NVS, not in the binary). A new version is offered in the uplink response, downloaded only on WiFi with a healthy battery, checked against its size and SHA-256, and booted as "pending verify". If the first uplink from the new image fails, the bootloader rolls back.
Commands ride the uplink. The collar sleeps, so "beep" or "report every minute" waits in a queue and is delivered in the response to its next report. Minutes of latency, no extra radio time.
NB-IoT in Andorra.
Andorra Telecom's NB-IoT is the only IoT network in the country (no LTE-M),
so the collar uses WiFi when it can and NB-IoT when it can't. I measured
what one HTTPS uplink really costs on a test SIM:
Per uplink
~5.8 KB total, of which ~3.2 KB is the TLS 1.2 handshake
Radio on
29–36 s: network attach 12–18 s, TLS connect 7–11 s
Per month
~17 MB if every 15-minute reading goes out alone, on a 100 MB SIM
The modem can't resume TLS sessions or report byte counters, so the
firmware keeps its own daily and monthly data budget in flash and buffers
readings when the budget runs out. The next steps are about bytes: batch
several readings per session, resume TLS on the ESP32 itself over the
modem's raw TCP (~0.7 KB instead of 3.2 KB per handshake), and eventually
CoAP over DTLS with a compact binary payload.
A stable edge in front. Collars only know one URL, served by a Cloudflare Worker. The backend behind it can change without reflashing a single collar. The Worker also rate-limits per device and per IP, and only it can reach the ingest functions.
Logic on ingest, not on the collar. Geofence checks, "near the edge of the pasture" (report every 5 minutes within 50 m of the boundary), inactivity and heat stress all run in Postgres and Supabase functions as data arrives.
Scheduled jobs in the database. pg_cron checks for silent collars and inactive animals every few minutes and sends a weekly summary every Monday at 08:00 farm time.
Battery forecasting. Charge comes from an 18650 discharge curve, and "days left" from a regression since the last recharge, shown only when there's a clear trend.
Security reviewed. Per-collar 192-bit keys (only hashes stored, revocable in one command), row-level security tested with a script, and a written plan for flash encryption and Secure Boot on production collars.
The apps.
One Flutter codebase for iOS and Android, in Catalan, Spanish and English.
The users are farmers outdoors, with gloves, in bright sun and patchy
coverage, so: map first, big targets, high contrast, and the age of every
value ("15 min ago") always on screen.
The herd on the map with an out-of-zone alert, and an animal's profile.
Pastures drawn with a finger on a satellite map (Esri imagery), plus an offline vector map of the farm (Protomaps) for when the phone has no signal either.
Pair a collar by scanning the QR code on it.
Find mode: the collar reports every minute for a while, and can beep or vibrate.
Daily tracks with playback, distance and activity, reports exported as CSV.
Share a farm by email with family or helpers, view-only, with an optional end date.
Alerts, and pastures drawn on the satellite map. Store screenshots are generated by script.
The website.
mosicu.tech
is a static site from a tiny dependency-free generator, served by a
Cloudflare Worker. It picks the language from a cookie or the visitor's
country, and its contact form is protected by Turnstile and rate limits, with
leads stored in Cloudflare D1 and deleted after 24 months.
What I learned.
Put a URL you own in front of hardware. Collars in a field can't be reflashed by hand, so everything that might change belongs behind the edge or in remote config.
Measure the radio before designing the protocol. On NB-IoT, the TLS handshake costs more than the data. That changed the roadmap.
Mechanical design is iteration. Snap fits looked elegant on screen and failed on the first print. Screws and an O-ring are boring and work.