DC Power Monitoring
By Maui Systems Ltd
Monitoring Remote Sites
We help run and maintain a community broadband network, which has equipment in remote locations, powered 100% by renewables - solar and wind. It’s Scotland, solar is generally a fleeting commodity, even in summer.
In 2022, Victron added Instant Readout to some of their products. Visible on the Victron app, the devices that support it broadcast a BLE packet every couple of seconds. The broadcast packet includes telemetry from the device (so voltage, current, power etc). Victron have even published the format of the packets and how to decode them - the only downside is that this is Low Energy Bluetooth, so the receiver has to be close (metres not kilometers). Ok when you are standing at the mast with your phone; less so when you are in an office miles away.
Power is a resource we need to protect at our off-grid masts; so adding in a PC or even a RaspberryPi adds to the load. If the monitor is WiFi based, we also need to add in a WiFi AP - we don’t generally have WiFi at the mast itself; the things ’local’ to them are generally sheep, cows and hillside wildlife. If the monitor is ethernet based, then that’s another network port used, or a bigger switch required - which will again have a power implication.
Ideally we wanted a very low power BLE receiver that could magically connect to our mast router without using a network port or requiring us to add WiFi.
Our core power device at our sites is the ‘Battery Protect’ - a small inline device that will cut the power if the voltage drops below a particular value; essential for protecting batteries at remote sites - just as the name suggests. This is a BLE Instant Readout only device - no VE.Direct or CAN-Bus ports. It’s BLE packets would make for wonderful battery telemetry - but even with a CerboGX, you can’t get it unless you have their app and are physically in range of the mast.
Ultra Low Power BLE capture
A little while ago, we came across the ESP32 platform - small microcontroller with embedded WiFi and BLE. The more recent versions come with multiple-core processors and reasonable amounts of memory - both RAM and FLASH.
BLE example programs are available, so getting it to receive the Victron ‘Instant Readout’ packets was fairly easy. Decoding them requires knowing the per-device encryption key - so a decision on architecture needed to be made. Do we upload the encryption keys to the ESP32 for local decoding, or ship the entire message back to our telemetry server and decode centrally. In the end we opted for the latter - it kept local processing to a miniumum - but also meant we didn’t have to manage keys on each local device.
Network Without WiFi or Ethernet
The second part of the problem is how to connect the ESP32 to our network, so the telemetry data can be sent back to our monitoring server. Although it has WiFi, we don’t normally have WiFi APs at mast sites. The ESP32 doesn’t have onboard ethernet, and adding something increases costs and power, plus uses up an ethernet port on a switch that would otherwise be used for customer connections.
Our mast devices do have a USB port though; they also have the ability to run a PPP server on that port, historically this was so you could add a 4G/LTE USB modem as a backup / out of band connection. The router has drivers for virtual serial over USB.
The Expressif ESP32 environment has ‘PPP over serial client’ functionality, and the ESP32-S3 uses a virtual serial port over it’s USB port to let you flash firmware to it.
With a bit of investigation, you can move the ‘console’ port (where the ESP32 sends it’s diagnostic messages) to the onboard serial port, letting you reconfigure the Serial-over-USB functionality for use by the PPP client.
What we’ve ended up with is a single USB-A to USB-C cable that connects the ESP32 to the router; the cable provides the ESP32 with power and data. This means we didn’t need to do anything to drop the battery 12V or 24V supply down to 5V for the ESP32 (the router does this), nor do we have to use an ethernet adapter and port, as the PPP over serial implementation does this in software.
Software Tips
We may end up publishing the software, but in the meantime, here are a couple of things we learned during this project, that weren’t obvious from the examples we found, nor from ESP documentation:
Console Output
In the ESP32 environment, the ‘console’ output is redirected under the Component Config -> ESP-STDIO option; either move it to UART0, or None if you don’t need it. You can also disable the secondary console output here if it’s set.
USB CDC
Virtual serial ports over the USB connection are termed ‘Communications Device Class’ - or CDC. There’s various examples in the ESP documentation, based on the ‘TinyUSB’ package.
When the ESP32 boots, the bootloader (the very first thing that runs on the device) has a minimal ‘TinyUSB’ stack, so some output appears on the builtin virtual serial port. Once it loads the app, the ‘console’ output setting above kicks in, and the app diagnostic messages get redirected.
There are two things here - one is that the PPP server will get to see the initial bootloader messages - don’t worry, it should just ignore them as ’noise’, but it does mean it takes a bit longer for the PPP server to find the actual PPP packets and process them.
Second is that when your app configures the virtual serial port, the builtin one from the bootloader is dropped. This causes a USB bus enumeration event; effectively the old device goes away and a new one appears.
If you leave the Tiny USB descriptors for ‘Vendor’ and ‘Product ID’ set to defaults for the USB stack, the application virtual serial port will look identical to the bootloader one; but the host may not then spot the fact they have changed. We found that we had less than 10% chance things would work when we created a new CDC device when using the defaults.
The USB bus expects devices to appear and disappear - what seemed to be important on the hardware we were using, was that the new CDC device needed to have a different identity to the bootloader one. Just changing the ProductID seemed to make all the difference, and we’ve seen 95%+ success this way.
The ProductID is set under Component Config -> TinyUSB Stack -> Descriptor configuration. Untick the ‘Use a default PID assigned to TinyUSB’ and specify your own. EspressIF even let you apply for your own ProductID under their VendorID, so there is a way to get an ID allocated using official channels.
Debugging
Debugging an embedded device where you only have one comms port and need to use it for another purpose is the definition of ‘a challenge’. We developed most of our code using an Xiao ESP32-S3 plus, combined with a discrete TTL-UART to USB adapter. We redirected the console output to UART0, which we connected to the UART-USB adapter. We then used the UART-USB adapter to give us a second serial path to the ESP32. Console/debug messages came through the second channel, PPP established over the primary (eventually).
Once we had something that worked, disable the UART0 console and flash the image to the Atom S3 lite. Cross some fingers or make an appropriate sacrificial offering.
Extending To Batteries
Some of the newer batteries we have been looking at have CAN-Bus ports on them, and do indeed work with the Victron CerboGX - reporting state of charge, current, voltage and even temperature.
Summary
Although it hasn’t yet been fully deployed on the hills, various prototypes have been successfully in operation for a number of months. We even created a second version that did use WiFi for use at a number of events we’ve been involved with, where WiFi AP’s were present anyway.
What started as a ‘how do we get better telemetry’ question, went via a number of expensive and power hungry bits of kit, to a simple device that costs less than £10 and barely draws any power.
Victron have to be commended for creating their ‘Instant Readout’ protocol and publishing the details, as do EspressIF for the ESP32 and all the firmware environment they’ve created.