Lake monitor: how it is built
A battery-powered box by the lake Fiskmyran measures the water temperature and the water level and sends them over LoRa radio to a gateway indoors, which shows them on its display and a web page and passes them on to MQTT. The readings themselves are on the Fiskmyran page (in Swedish).
Overview

The lakeside unit
Battery powered, asleep almost all the time
| Microcontroller | ESP32-C3 Super Mini, deep sleep between measurements, its LED removed to save power |
| Radio | RFM95W (SX1276, 868 MHz) on SPI; DIO0 not wired, the radio is polled |
| Temperature | DS18B20 in the water, with a calibration offset stored in flash (set once in melting ice: 0.0 °C) |
| Water level | RCWL-1655 ultrasonic sensor in Trig/Echo mode at 3.3 V, about 40 cm above the zero level, looking down through the lid |
| Tamper | A tilt switch that wakes the unit at once when the box is opened or tilted |
| Battery | Li-ion, measured through a 2 × 1 MΩ divider; the sensors get power from a GPIO only while measuring |
Every wake
- Power the sensors and wait 500 ms (the RCWL-1655 misses pings for about 450 ms after power-on).
- Read the temperature, and take 9 distance pings: drop the 2 highest and 2 lowest and average the middle 5 (the sensor reads in steps of about 1.3 cm, so a plain median would jump between steps). The speed of sound is corrected for the temperature.
- Sensors off, send the data packet, then listen about half a second for the gateway's answer, which may carry new settings.
- Choose the next interval from the water temperature and go back to deep sleep.
How often it measures
| below +2 °C | every 7 days (ice season) |
| +2 to +5 °C | every 24 hours |
| +5 to +15 °C | every 6 hours |
| above +15 °C | every 2 hours |
With about 1 °C of hysteresis, so it does not flip between two intervals at a threshold. Thresholds and intervals can be changed remotely and are kept in flash. For tests it can stay awake and measure every minute; that falls back to the schedule by itself after 24 hours, so a forgotten test cannot drain the battery at the lake.
Water level
The unit computes the level itself: zero offset minus the measured distance, so the level rises when the distance falls. The ultrasonic sensor cannot measure closer than about 20 cm; with the sensor 40 cm above the zero level, levels above about +18 cm show as "at least +18 cm". The highest water seen there is about +25 cm, in spring.
The radio link
Plain point-to-point LoRa, no LoRaWAN
| Frequency | 869.525 MHz, the EU868 sub-band with a 10 % duty cycle; 14 dBm |
| Modulation | LoRa SF7, 125 kHz, coding rate 4/5, private sync word; a data packet is 22 bytes, about 50 ms on air |
| Integrity | Every packet carries a sequence number and a 4-byte HMAC-SHA256 tag; the gateway rejects wrong tags and old sequence numbers, so packets can be neither forged nor replayed |
| Downlink | The gateway answers each data packet with queued settings (or none) within about 0.1 s, while the unit still listens; the unit applies them and acknowledges. That is how intervals, thresholds and calibration are changed without opening the box. |
| Fallback | Two slower radio profiles (SF9, SF12) can be chosen remotely; if either side hears nothing for three intervals, both fall back to SF7, so a bad setting cannot cut the link. |
| Range | Measured walking around the lake: at the mounting spot −84 to −92 dBm with SNR about 8 dB and no lost packets, some 30 dB of margin, so SF7 stays. |
The gateway
Heltec WiFi LoRa 32 V2, indoors on mains power
- The radio runs in its own FreeRTOS task, so the answer to the lake is on air 60 to 125 ms after the uplink, whatever the display, web server or MQTT are doing.
- The OLED shows temperature, level, battery and the times of the last and next measurement; it is dimmed and shifts by a pixel now and then against burn-in.
- A small web page with a 14-day graph, and
/data.jsonand/history.jsonfor other pages; the latest values and the history are kept in flash, so a restart loses nothing. - MQTT to the home broker (Mosquitto, read by Home Assistant): values, link quality, alarms; commands to the lake are published to MQTT and sent with the next answer.
The gateway is never reachable from the internet: this site's server fetches its JSON through an NGINX caching proxy (30 s), so any number of visitors cause at most one request to the gateway every 30 seconds.
What comes next
A history service on the server that keeps every reading for good, together with air temperature, incoming sunshine and rain from Home Assistant, to see how the lake level follows dry and rainy spells over the summer, how much evaporates on hot days, and when the ice season starts and ends.