Energy Measurement System Using LoRaWAN and BalenaCloud

Description

This project implements an energy monitoring system leveraging LoRaWAN technology. The system uses a Modbus RTU device to collect measurements from an energy meter, including current, voltage, frequency, and power metrics. The collected data is transmitted via LoRaWAN to The Things Stack server, where it is received and decoded.

Using Node-RED, the data is further processed and stored in an InfluxDB database. Visualization of this data is achieved through a Grafana dashboard. Additionally, a Cloudflare tunnel is set up to enable secure remote access to the system from the internet.

UC-300 Modbus RTU / Lorawan.

Implementation

The system is deployed on Balena OS for efficient device management and containerization. The implementation is based on the guide from the Balena blog: Run your private The Things Stack network server on a Raspberry Pi with balena, with modifications to the Docker Compose configuration to adapt it to the project’s specific requirements.

Service

Dashboard

Hardware


@rojasyal This is brilliant, thanks for sharing here!

Update 2026: from Grafana to an AI-powered FastAPI dashboard

It’s been almost two years since I shared this project, and it has grown quite a bit. What started as a single energy meter is now the base of a platform we run in production, deployed and updated OTA with balenaCloud. The Things Stack setup based on xoseperez’s `the-things-stack-basicstation-balena` has been rock solid for more than 3 years.

New architecture

The biggest change was splitting the system across two devices. Pi #1 keeps the data layer (The Things Stack, Node-RED, InfluxDB and a Cloudflare Tunnel), and Pi #2 runs only the web application. A bad dashboard release can never interrupt data collection.

Services on balenaCloud

Pi #2 runs a single FastAPI service, so dashboard updates are just a balena push without touching the data layer on Pi #1.

Grafana → custom FastAPI dashboard

Session-based login and KPIs designed for the end user rather than for engineers: power factor, phantom loads and an estimate of the utility bill (CFE tariffs in Mexico).

AI assistant on top of InfluxDB

A chat that uses LLM function calling to query the time-series data by date range. Users can ask things like “why did consumption spike last Tuesday night?” and get answers based on the real measurements.

Automated PDF reports

Monthly reports generated with WeasyPrint, including an AI-written diagnosis section. Before exposing the dashboard to clients, we also did a full security review of the app.

Balena tips we learned along the way

  • On balenaCloud, use docker-compose file version 2.1 syntax.
  • If the app is served over plain HTTP on the LAN, secure-only session cookies will silently break login. Enable them only behind HTTPS (the Cloudflare Tunnel in our case).
  • A static IP can be set by editing the ethernet-static file in the resin-boot partition before the first boot.

The same pattern (LoRaWAN → TTS → Node-RED → InfluxDB → FastAPI + LLM) now also covers water meters and motor vibration monitoring (ISO 10816).

Thanks again to the balena team. This platform made it possible for a small team to manage a fleet this size.

great project @rojasyal
thanks for sharing the progress!