---
title: "DIY Battery BMS: ESP32 firmware case study — Nexion"
description: "How Nexion wrote DIY Battery BMS, ESP32 firmware that reads a Victron SmartShunt and talks to solar inverters over CAN in the Pylontech protocol."
url: https://nexion.uk/work/diy-battery-bms/
---

[OUR WORK](https://nexion.uk/work/) · CASE STUDY

# DIY Battery BMS: ESP32 firmware for solar inverters

DIY Battery BMS is firmware we wrote for ESP32 boards. It lets a self-built LiFePO4 battery bank work with an off-the-shelf solar inverter, and it is free for personal, non-commercial use, with the source on GitHub.

Nexion firmware · Source on [GitHub](https://github.com/sijones/DiyBatteryBMS)

## The problem

Many hybrid inverters expect the battery to report its state and charge limits over CAN, using the Pylontech protocol. A DIY bank monitored by a Victron SmartShunt has the data but no way to send it in that form.

## What the firmware does

- Reads the SmartShunt over VE.Direct serial or Bluetooth, or takes readings from MQTT, with an optional fallback source.
- Sends battery data and the charge voltage and current the owner sets to the inverter over CAN, using the Pylontech protocol.
- Controls charging: voltage-limited charging, temperature protection, fan control and force charge for off-peak rates.
- Publishes to MQTT with Home Assistant discovery, and accepts commands such as enabling or disabling charge.
- Includes a web UI for setup, a CAN sniffer for diagnosis and syslog forwarding.

## Hardware and build

It runs on ESP32 and ESP32-S3 boards, either with an MCP2515 CAN adapter or with the chip’s built-in CAN controller, including boards such as the LilyGo T-CAN485 and the Seeed XIAO ESP32-S3. The firmware is C++, built with PlatformIO on the Arduino core for ESP-IDF.

## Getting it onto a board

Owners flash it from a [web flasher](https://diy.power-pilot.uk/) in the browser, which reads the chip’s flash size and turns off options that would not work on it. After that they join it to Wi-Fi, set it up in its web UI and install updates over the air.

## In use

It is tested with Solis inverters, and members of the DIY Solar Forum community report others working. It also connects to [PowerPilot](https://nexion.uk/work/powerpilot/), our home energy manager, over WebSockets.

## Where this applies to your project

If you need firmware for an ESP32 board that reads one device and talks to another over CAN, serial, Bluetooth or MQTT, this is the kind of work we do. See our [edge and hardware integration](https://nexion.uk/services/#edge) service.

## Need firmware for your board?

Tell us about the hardware and what it has to talk to. We reply within two working days.

[Start a project](https://nexion.uk/contact/)
