question

kazetsukai avatar image
kazetsukai asked

VE.Direct Java Library (USB)

Hello all,


Using the technical details provided by Victron Energy in one of their PDFs, I was able to create a small Java library to discover VE.Direct USB devices and read data from them. I needed this for my MPPT Charge controller but it should be usable with more or less any VE.Direct device.

https://github.com/kazetsukaimiko/victron-java


This library uses Java 9+ Streams. It has a single dependency of JSSC, although there is an abstraction layer built in so that can be removed if necessary. It can also be used to read events from the command line, and has nice helper code to convert electrical units.


I wanted to put this out there and get an idea of how useful it might be to others. It is well tested with 80%-90% code coverage. I organized it to support more protocols than VE.Direct, but as I currently don't have any Victron devices that use other protocols I have omitted writing in support for them, but feel free to submit feature requests via the GitHub Issue tracker.


I intend to maintain this library and eventually get it into Maven central for easy import into Maven/Gradle projects. To test it you will need git, maven, and Java 11+. You can then checkout the code:

git clone https://github.com/kazetsukaimiko/victron-java.git && cd victron-java

And run the CLI Monitor:

mvn exec:java -Dexec.mainClass="kaze.app.ShowDevices"


MPPT ControllersVE.Direct
2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Warwick Bruce Chapman avatar image Warwick Bruce Chapman commented ·

Thank you for sharing!

0 Likes 0 ·

Very cool. nice to see this come full circle for you :)

0 Likes 0 ·
2 Answers
kazetsukai avatar image
kazetsukai answered ·

I intend to build an entire web stack to watch and manage devices, at least for any hardware I have. The hex protocol is next on my list to implement.


@Guy Stewart (Victron Community Manager) To that end I hope you guys either have available, or release information pertaining to the bluetooth protocols in use by your products. The VE.Direct protocol PDFs are pretty excellent, if you look at the VictronProduct and VEDirectColumn enums ( https://github.com/kazetsukaimiko/victron-java/blob/master/src/main/java/kaze/victron/VictronProductType.java and https://github.com/kazetsukaimiko/victron-java/blob/master/src/main/java/kaze/victron/VEDirectColumn.java ) you can see I was able to very comprehensively handle all possible fields and their values.


This kind of documentation sets you apart from other vendors, I don't see anyone else doing this. This allows me to build integrations between energy management and device control, remote monitoring solutions. I intend to support any hardware I can get my hands on.


One question- I'm thinking of recreating the entire style (blue/orange/white theme), using CSS, for an open source/non-commercial web application equivalent of VictronConnect. Will this land me in trouble?

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

mvader (Victron Energy) avatar image mvader (Victron Energy) ♦♦ commented ·

As long as its victron oriented, no problem. But if you’re making a nice Victron look alike to then manage a chinese set of battery monitors or solar charger hardware, we’d be less happy with it ofcourse; as I am sure you’ll understand.

Btw to make sure: you are familiar with Venus OS (see wiki pages on github), and also the html5 app we host within Venus OS?

https://github.com/victronenergy/venus-html5-app

0 Likes 0 ·
kazetsukai avatar image kazetsukai mvader (Victron Energy) ♦♦ commented ·

So yeah, I'm not making a Victron interface for Chinese clones... I think that'd be pretty slimy. My personal application is for my home (a converted school bus / skoolie). A practical commercial application I could see would be integrating Victron equipment into a custom interface for an RV.


So while I have looked at the Venus stuff a bit I will admit I more than likely am not aware of all its capabilities, and that there likely is a good amount of overlap between Venus and this project. Architecturally its a Thorntail / Java EE Microprofile stack with several modules:

  1. api : or the JAX-RS interfaces and entities needed to talk to the application with REST (client proxies) or Websockets.
  2. web : The WAR deployment including all service code, endpoint handlers, etc as well as all the static frontend assets.
  3. ui : I hope to learn some JavaFX to build an actual client application, this is just a placeholder for that at this point.
  4. jsonlink: This is technically another project- one aimed at solving part of the sensor input problem. Its a library to talk to an Arduino via ArduinoJSON. The library allows me to upload one sketch to the device, configure pins and read/write their states. It also lets me assign a Java UUID to a board (flashed to EEPROM) so I can reliably find and talk to the same board no matter how/what order it is connected in.


My goal is to build a user-configurable, event-driven flow that allows the implementer to map events to actions (set a pin on board x-y-z, run a command, issue a REST request, etc), and fire aggregate events. For example, if my water tanks drop below a certain threshold, I could run (Linux TTS):

echo "Water tank capacity has dropped below 20%" | festival --tts


I'm aiming for easy expansion capability (just keep plugging in more and more event sources/sinks) and some potentially smarter decisioning with this approach. Take for instance the standard battery under-voltage case: Drops below a threshold, yeah lets turn off certain devices, but is waiting for bank voltage to climb above some magic number before I "turn the lights back on" really the best solution? I think better outcomes could potentially be achieved by spawning an aggregate event of VE.Direct data collected over the last hour, watching for either a consistent climb in voltage or a consistent panel input power, that would allow me to safely turn things back on instead of simply waiting for bank voltage to climb. With hard cutoffs, of course.

0 Likes 0 ·
mvader (Victron Energy) avatar image mvader (Victron Energy) ♦♦ kazetsukai commented ·

Sounds nice. And an enourmous project (!).

Btw I’m not familiar with Java at all.

On the Venus OS side, the equivalent for user event based programming would be node-red.


All the best, Matthijs

0 Likes 0 ·
mvader (Victron Energy) avatar image
mvader (Victron Energy) answered ·

Thumbs up @kazetsukai !

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.