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 box opened, with the ultrasonic sensor's hole in the lid, and the Heltec gateway with its OLED in front
The lakeside box opened (the ultrasonic sensor looks down through the hole in the lid; LoRa module with its spring antenna in the corner) and the gateway in front, its OLED showing the latest values.

The lakeside unit

Battery powered, asleep almost all the time

MicrocontrollerESP32-C3 Super Mini, deep sleep between measurements, its LED removed to save power
RadioRFM95W (SX1276, 868 MHz) on SPI; DIO0 not wired, the radio is polled
TemperatureDS18B20 in the water, with a calibration offset stored in flash (set once in melting ice: 0.0 °C)
Water levelRCWL-1655 ultrasonic sensor in Trig/Echo mode at 3.3 V, about 40 cm above the zero level, looking down through the lid
TamperA tilt switch that wakes the unit at once when the box is opened or tilted
BatteryLi-ion, measured through a 2 × 1 MΩ divider; the sensors get power from a GPIO only while measuring

Every wake

  1. Power the sensors and wait 500 ms (the RCWL-1655 misses pings for about 450 ms after power-on).
  2. 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.
  3. Sensors off, send the data packet, then listen about half a second for the gateway's answer, which may carry new settings.
  4. Choose the next interval from the water temperature and go back to deep sleep.

How often it measures

below +2 °Cevery 7 days (ice season)
+2 to +5 °Cevery 24 hours
+5 to +15 °Cevery 6 hours
above +15 °Cevery 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

Frequency869.525 MHz, the EU868 sub-band with a 10 % duty cycle; 14 dBm
ModulationLoRa SF7, 125 kHz, coding rate 4/5, private sync word; a data packet is 22 bytes, about 50 ms on air
IntegrityEvery 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
DownlinkThe 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.
FallbackTwo 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.
RangeMeasured 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 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.