npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ve-direct-hex

v0.0.3

Published

extremely basic implementation of the VE.Direct and VE.Direct HEX protocols for Victron devices

Downloads

6

Readme

ve-direct-hex

extremely basic implementation of the VE.Direct and VE.Direct HEX protocols for Victron devices

This is a pretty barebones library for interfacting with the Victron VE.Direct and VE.Direct HEX protocols used by their various devices. I'm intentionally not providing any support for actual serial communication, but example.mjs shows how you can get this running by rawdogging a linux tty.

basic rundown

a quick rundown of example.mjs

basic setup

import fs from 'fs/promises'
import {debugText} from './debug_tools.mjs'
import * as VEDirect from './main.mjs'
import child  from 'child_process'

//hoist convenience functions for building HEX messages
let {formatBytesToHex, addCheck, wordToLEBytes} = VEDirect

this is a quick and dirty way of getting a working terminal on linux, it may also work on other *nix-like operating systems but i haven't tried

const terminal = '/dev/ttyUSB0'
//call stty to set up terminal
child.execSync(`stty -F ${terminal} 19200 raw cs8 -cstopb -parenb`)

//open terminal
let tty = await fs.open('/dev/ttyUSB0', 'a+')
let stream = tty.createReadStream()

VEDirect.promise is a wrapper for the HEX protocol that takes a TTY and an optional Stream (it'll make one if you don't have it handy) initially and then the resultant function takes a buffer and returns a promise that resolves to whatever the answer was from the victron

VEDirect.nextUpdate wraps the text protocol, and it's resultant function returns a promise that reolves to the next full text update from the victron

let getStatus = VEDirect.nextUpdate(stream)
let query = VEDirect.promise(tty, stream)

print the next status updated over the text protocol w/ debug info

console.log('status: ', debugText(await getStatus()))

which will resolve to something like this

status:  {
  PID: {
    desc: 'Product ID',
    value: 41048,
    ex_value: 'SmartSolar MPPT 150|35'
  },
  FW: { desc: 'Firmware version (16 bit)', value: 159 },
  'SER#': { desc: 'Serial number', value: 'XXXXXXXXXXX' },
  V: {
    desc: 'Main or channel 1 (battery) voltage',
    value: 26360,
    unit: 'mV'
  },
  I: { desc: 'Main or channel 1 battery current', value: 0, unit: 'mA' },
  VPV: { desc: 'Panel voltage', value: 20, unit: 'mV' },
  PPV: { desc: 'Panel power', value: 0, unit: 'W' },
  CS: { desc: 'State of operation', value: 0, ex_value: 'Off' },
  MPPT: { desc: 'Tracker operation mode', value: 0, ex_value: 'Off' },
  OR: { desc: 'Off reason', value: 1, ex_value: 'No input power' },
  ERR: { desc: 'Error code', value: 0, ex_value: 'No error' },
  LOAD: { desc: 'Load output state (ON/OFF)', value: 'ON' },
  H19: {
    desc: 'Yield total (user resettable counter)',
    value: 272964,
    unit: '0.01 kWh'
  },
  H20: { desc: 'Yield today', value: 276, unit: '0.01 kWh' },
  H21: { desc: 'Maximum power today', value: 997, unit: 'W' },
  H22: { desc: 'Yield yesterday', value: 339, unit: '0.01 kWh' },
  H23: { desc: 'Maximum power yesterday', value: 571, unit: 'W' },
  HSDS: { desc: 'Day sequence number (0..364)', value: 40 }
}

add checksum and encode the message as ":[UPPERCASEHEX]\n"

let checkVersion = Buffer.from(formatBytesToHex(addCheck([3])))
console.log("query version: ",await query(checkVersion))

which will resolve to something like this

query version:  { type: 1, bytes: [ 89, 65 ], checkSum: 186, msg: ':15941BA' }

extra examples

//set charge current to 35A
let setAmps = Buffer.from(formatBytesToHex(addCheck(
  [8,...wordToLEBytes(0xEDF0),0,...wordToLEBytes(350)]
)))
console.log("set charging amps: ",await query(setAmps))

//log all VE.Direct data blocks w/ additional debug info
stream.on('data', VE_Direct(block => console.log(debugText(block))))

//log all async VE.Direct HEX messages
stream.on('data', VEDirect.hex(msg => {
  if (msg.type === 0xA) console.log(msg)
}))

caveats

  • i've only tested on debian on a beaglebone with node 17+
  • victron uses little endian encoding within their HEX format, node uses whatever endianness is default for the underlying system, i assume your system is LE, if it isn't you're going to have a bad time

References: