A low-power LoRaWAN sensor node
Firmware I wrote end to end for a battery-powered environmental sensor on Zephyr. It sleeps most of the time, wakes on a timer or on motion, and stays manageable over the radio.
Goal
The node reports temperature, humidity, pressure, tilt and vibration in Vietnam's AS923-2 band and has to last for years on a battery. Once deployed it must still be reachable: someone has to be able to change its reporting interval, probe it, open its receiver for a while and replace its firmware, all over the radio.
What I built
Sleep and wake
Deep sleep with wake-up on the real-time clock or on the motion sensor's interrupt. The LoRaWAN session is kept in flash, so a wake never costs a re-join, and the sensor rail is switched off while the node sleeps.
Remote management
Downlink commands change the interval, data rate or device class. A Class C mode for longer listening always expires on its own, so no command can leave a node draining its battery. Firmware updates arrive over the air through LoRaWAN's multicast and fragmentation packages.
Gateway and tools
A Raspberry Pi gateway runs a self-hosted ChirpStack network server, with Python tools for sending commands and analysing power captures.
Robustness
A store-and-forward buffer for missed uplinks, a watchdog with a hardware fallback, a guard against crash loops, and unit tests that run on the host.
Result
A power profiler showed every wake drawing a 418 mA spike, well above the supply budget for small cells. It came from the sensor board's capacitors charging through a switch that turned on all at once. Driving the switch with a train of short, widening pulses spread that charge out and brought the peak down to 165 mA, inside the budget, without changing the board. Moving one sensor to its own bus also cut the sleep current by about 30%.
In a 21-hour bench test on two boards, more than 99.7% of uplinks arrived and every remote command was acted on.
What I learned
- Low-power firmware: deep-sleep design, wake sources and keeping state across resets.
- Measuring power properly: profiling at high sample rates and tracing a current spike back to a component.
- LoRaWAN end to end: regional channel plans, device classes, downlinks and firmware updates over the air, with a self-hosted network server.
- Zephyr in depth: device trees, an out-of-tree sensor driver and unit tests that run on the host.