Udev rule for Victron VE.Direct -> USB on Pi

Looking for some suggestions here.

I’m experimenting with a remote solar setup for a LoRa gateway and using a Victron SmartSolar solar charge controller. The Victron products seem superior in every way to other competitors, including providing a VE.Direct port, which when combined with their USB cable going in to the Pi based gateway lets me monitor solar panel output, battery performance, and more.

I’m interested in using a UDEV rule to detect when the USB cable is plugged in - including potentially kicking off a script that parses the VE.Direct serial messages and piping them to an MQTT server dynamically.

I just did a test by running udevadm monitor — environment in the host container and unplugging and plugging back in the Victron → USB adapter.

Resulting in:

KERNEL[32329.783736] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1 (usb)
KERNEL[32329.794573] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0 (usb)
KERNEL[32329.794839] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/ttyUSB0 (usb-serial)
KERNEL[32329.801311] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/gpiochip2 (gpio)
KERNEL[32329.801411] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/gpio/gpiochip500 (gpio)
KERNEL[32329.801492] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
KERNEL[32329.801565] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/ttyUSB0 (usb-serial)
KERNEL[32329.801656] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0 (usb)
KERNEL[32329.801758] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1 (usb)
UDEV  [32329.803754] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1 (usb)
UDEV  [32329.810711] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0 (usb)
UDEV  [32329.822091] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/gpiochip2 (gpio)
UDEV  [32329.823936] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/gpio/gpiochip500 (gpio)
UDEV  [32329.834082] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/ttyUSB0 (usb-serial)
UDEV  [32329.868650] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
UDEV  [32329.873661] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/ttyUSB0 (usb-serial)
UDEV  [32329.880226] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0 (usb)
UDEV  [32329.886126] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1 (usb)

I’m not quite sure how to translate this output into a UDEV rule that would run on the correct events from udev. Any suggestions?

1 Like

Hey @barryjump this looks like an amazing project that I would like to learn more :slight_smile:

Just found this blogpost which can give you hints on how to do it → Hot plugging USB devices in balenaOS | by Tomás Migone | The Startup | Medium

or this Balena base images - Balena Documentation

Let me know if this works! Looking forward to test this on my BluesSolar (mine is not smart enough)!

1 Like

Thanks @mpous. I did see those docs originally, which got me up to this point.
I think my trouble is not knowing the best practice for which event to hook the rule up to. The output above wasn’t clear enough for me to know which of those events specifically I need to use.

Anyways, udev aside, the experiment is going really well.

(1) 50w Solar Panel
(1) Victron Smart Charge Controller
(1) 12vx6ah LifePo4 (providing 72 watt hours) Battery
(1) VE.Direct to USB cable
(1) Sixfab PowerHAT v2
(1) Raspi 4 (will eventually replace with a CM4 based Lora gateway)

What I realized is that the battery is too small at 12v 6ah. On sunny days it will get me through the night, but on anything less that perfect sun I only get between 14 and 18 hours of runtime.

I’ve learned a good rule of thumb is about 72 hours of runtime is best, so I’ll need to replace the primary battery with a 12v 50ah on the high end. Especially when considering that the Pi4 during testing isn’t running the LoRa concentrator or cell modem which would increase the power draw.

1 Like

@mpous Forgot to add this image… Here’s the ve.direct protocol → usb → an mqtt container that I’m pushing into a dashboard.

Not much power right now as the sun is just starting to come up.

2022-07-29 07.08.12

1 Like

This is amazing @barryjump is this open source? :slight_smile: i would love to test here!

Currently it’s just local, but I’ll pop it on github and make it public tonight.

@mpous here you go:

Awesome! Looking fwd to play with it :slight_smile:

Some time ago i created an excel sheet with a calculator for solar panel and battery sizes withsingle board computers. Happy to play again with it :smiley:

El dv., 29 de jul. 2022, 17:19, barryjump via balenaForums <notifications@balena.discoursemail.com> va escriure: